Sha256: e0b14aa36b6007f75a65b7edf8fa1b9a779e59240d6c48454b0fb4447b31e847

Contents?: true

Size: 583 Bytes

Versions: 3

Compression:

Stored size: 583 Bytes

Contents

# frozen_string_literal: true

require 'sequitur' # Load the Sequitur library

#
# Purpose: show how to apply Sequitur on a stream of Symbol values
#
input_sequence = %i[
  aa bb aa bb cc
  aa bb cc dd aa
  bb cc dd ee
]

# Generate the grammar from the sequence
grammar = Sequitur.build_from(input_sequence)

# Use a formatter to display the grammar rules on the console output
formatter = Sequitur::Formatter::BaseText.new($stdout)

# Now render the rules
formatter.render(grammar.visitor)

# Rendered output is:
# start : P1 P2 P3 P3 ee.
# P1 : aa bb.
# P2 : P1 cc.
# P3 : P2 dd.

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sequitur-0.1.25 examples/symbol_sample.rb
sequitur-0.1.24 examples/symbol_sample.rb
sequitur-0.1.23 examples/symbol_sample.rb