diff --git a/lib/propane/grammar.rb b/lib/propane/grammar.rb index 105f5df..113f7c8 100644 --- a/lib/propane/grammar.rb +++ b/lib/propane/grammar.rb @@ -41,7 +41,7 @@ class Propane elsif sliced = input.slice!(/\Adrop\s+(\S+)\n/) pattern = $1 @drop_tokens << Token.new(pattern: pattern, line_number: line_number) - elsif sliced = input.slice!(/\A(\S+)\s*:\s*\[(.*?)\] <<\n(.*?)^>>\n/m) + elsif sliced = input.slice!(/\A(\S+)\s*->\s*(.*?)(?:;|<<\n(.*?)^>>\n)/m) rule_name, components, code = $1, $2, $3 components = components.strip.split(/\s+/) @rules << Rule.new(rule_name, components, code, line_number) diff --git a/spec/propane_spec.rb b/spec/propane_spec.rb index 011ae8f..832da56 100644 --- a/spec/propane_spec.rb +++ b/spec/propane_spec.rb @@ -31,11 +31,10 @@ token int \\d+ token plus \\+ token times \\* drop \\s+ -Start: [Foo] << +Start -> Foo; +Foo -> int << >> -Foo: [int] << ->> -Foo: [plus] << +Foo -> plus << >> EOF build_parser @@ -49,18 +48,12 @@ token plus \\+ token times \\* token zero 0 token one 1 -Start: [E] << ->> -E: [E times B] << ->> -E: [E plus B] << ->> -E: [B] << ->> -B: [zero] << ->> -B: [one] << ->> +Start -> E; +E -> E times B; +E -> E plus B; +E -> B; +B -> zero; +B -> one; EOF build_parser end @@ -69,14 +62,10 @@ EOF write_grammar <> -Start: [R2 b] << ->> -R1: [a b] << ->> -R2: [a b] << ->> +Start -> R1 a; +Start -> R2 b; +R1 -> a b; +R2 -> a b; EOF build_parser end @@ -85,12 +74,9 @@ EOF write_grammar <> -Start: [b R1] << ->> -R1: [b] << ->> +Start -> a R1; +Start -> b R1; +R1 -> b; EOF build_parser end