From b682c72b1744d789c2093920e48740f0a3e0d7c8 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 23 Jul 2022 22:09:19 -0400 Subject: [PATCH] Add semicolon to end of all grammar statements --- lib/propane/grammar.rb | 10 +++++----- spec/propane/lexer/dfa_spec.rb | 28 ++++++++++++++-------------- spec/propane_spec.rb | 28 ++++++++++++++-------------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/propane/grammar.rb b/lib/propane/grammar.rb index cfdb673..9015cc6 100644 --- a/lib/propane/grammar.rb +++ b/lib/propane/grammar.rb @@ -25,12 +25,12 @@ class Propane # Skip white space. elsif sliced = input.slice!(/\A#.*\n/) # Skip comment lines. - elsif sliced = input.slice!(/\Amodule\s+(\S+)\n/) + elsif sliced = input.slice!(/\Amodule\s+(\S+)\s*;/) @modulename = $1 - elsif sliced = input.slice!(/\Aclass\s+(\S+)\n/) + elsif sliced = input.slice!(/\Aclass\s+(\S+)\s*;/) @classname = $1 - elsif sliced = input.slice!(/\Atoken\s+(\S+)(?:\s+(\S+))?\n/) - name, pattern = $1, $2 + elsif sliced = input.slice!(/\Atoken\s+(\S+?)(?:\s+(.+?))?\s*(?:;|<<\n(.*?)^>>\n)/m) + name, pattern, code = $1, $2, $3 if pattern.nil? pattern = name end @@ -38,7 +38,7 @@ class Propane raise Error.new("Invalid token name #{name.inspect}") end @tokens << Token.new(name: name, pattern: pattern, id: @tokens.size, line_number: line_number) - elsif sliced = input.slice!(/\Adrop\s+(\S+)\n/) + elsif sliced = input.slice!(/\Adrop\s+(\S+)\s*;/) pattern = $1 @drop_tokens << Token.new(pattern: pattern, line_number: line_number) elsif sliced = input.slice!(/\A(\S+)\s*->\s*(.*?)(?:;|<<\n(.*?)^>>\n)/m) diff --git a/spec/propane/lexer/dfa_spec.rb b/spec/propane/lexer/dfa_spec.rb index f7698ac..afa7903 100644 --- a/spec/propane/lexer/dfa_spec.rb +++ b/spec/propane/lexer/dfa_spec.rb @@ -59,7 +59,7 @@ end describe Propane::Lexer::DFA do it "lexes a simple token" do expect(run(< Foo; Foo -> int << >> @@ -44,10 +44,10 @@ EOF it "generates a parser" do write_grammar < E; E -> E times B; E -> E plus B; @@ -60,7 +60,7 @@ EOF it "generates an SLR parser" do write_grammar < E; E -> one E; E -> one; @@ -70,8 +70,8 @@ EOF it "distinguishes between multiple identical rules with lookahead symbol" do write_grammar < R1 a; Start -> R2 b; R1 -> a b; @@ -84,9 +84,9 @@ EOF it "handles reducing a rule that could be arrived at from multiple states" do write_grammar < a R1; Start -> b R1; R1 -> b;