Sha256: 501f2d61731946aaf0280eab1de7ddf2762acd3c1e651f9b5eb63b3c317b37db

Contents?: true

Size: 803 Bytes

Versions: 8

Compression:

Stored size: 803 Bytes

Contents

require 'sequitur'  # Load the Sequitur library

#
# Purpose: show how to apply Sequitur on a stream of text words
#

# Raw input is one String containing repeated sentences...
raw_input = <<-SNIPPET
Error: unknown character '?' at position 6
Error: illegal character '%' at position 20
Error: unknown character '/' at position 9
SNIPPET

# Convert into a sequence of words
input_sequence = raw_input.scan(/\w+/)
# 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 : P2 6 Error illegal P1 20 P2 9.
# P1 : character at position.
# P2 : Error unknown P1.

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sequitur-0.1.18 examples/word_sample.rb
sequitur-0.1.17 examples/word_sample.rb
sequitur-0.1.16 examples/word_sample.rb
sequitur-0.1.15 examples/word_sample.rb
sequitur-0.1.14 examples/word_sample.rb
sequitur-0.1.13 examples/word_sample.rb
sequitur-0.1.12 examples/word_sample.rb
sequitur-0.1.11 examples/word_sample.rb