Clean up rule format in grammar files
This commit is contained in:
parent
ba74d0a20a
commit
df8088c3c6
@ -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)
|
||||
|
@ -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 <<EOF
|
||||
token a
|
||||
token b
|
||||
Start: [R1 a] <<
|
||||
>>
|
||||
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 <<EOF
|
||||
token a
|
||||
token b
|
||||
Start: [a R1] <<
|
||||
>>
|
||||
Start: [b R1] <<
|
||||
>>
|
||||
R1: [b] <<
|
||||
>>
|
||||
Start -> a R1;
|
||||
Start -> b R1;
|
||||
R1 -> b;
|
||||
EOF
|
||||
build_parser
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user