Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove , from Rule print format #397

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/lrama/grammar/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def ==(other)
# TODO: Change this to display_name
def to_s
l = lhs.id.s_value
r = empty_rule? ? "ε" : rhs.map {|r| r.id.s_value }.join(", ")
r = empty_rule? ? "ε" : rhs.map {|r| r.id.s_value }.join(" ")

"#{l} -> #{r}"
end
Expand Down
32 changes: 16 additions & 16 deletions spec/lrama/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@
command = Lrama::Command.new
expect { command.run(o_option + [fixture_path("command/basic.y"), "--trace=rules"]) }.to output(<<~OUTPUT).to_stdout
Grammar rules:
$accept -> list, YYEOF
$accept -> list YYEOF
list -> ε
list -> list, LF
list -> list, expr, LF
list -> list LF
list -> list expr LF
expr -> NUM
expr -> expr, '+', expr
expr -> expr, '-', expr
expr -> expr, '*', expr
expr -> expr, '/', expr
expr -> '(', expr, ')'
expr -> expr '+' expr
expr -> expr '-' expr
expr -> expr '*' expr
expr -> expr '/' expr
expr -> '(' expr ')'
OUTPUT
end
end
Expand All @@ -55,16 +55,16 @@
command = Lrama::Command.new
expect { command.run(o_option + [fixture_path("command/basic.y"), "--trace=actions"]) }.to output(<<~'OUTPUT').to_stdout
Grammar rules with actions:
$accept -> list, YYEOF {}
$accept -> list YYEOF {}
list -> ε {}
list -> list, LF {}
list -> list, expr, LF { printf("=> %d\n", $2); }
list -> list LF {}
list -> list expr LF { printf("=> %d\n", $2); }
expr -> NUM {}
expr -> expr, '+', expr { $$ = $1 + $3; }
expr -> expr, '-', expr { $$ = $1 - $3; }
expr -> expr, '*', expr { $$ = $1 * $3; }
expr -> expr, '/', expr { $$ = $1 / $3; }
expr -> '(', expr, ')' { $$ = $2; }
expr -> expr '+' expr { $$ = $1 + $3; }
expr -> expr '-' expr { $$ = $1 - $3; }
expr -> expr '*' expr { $$ = $1 * $3; }
expr -> expr '/' expr { $$ = $1 / $3; }
expr -> '(' expr ')' { $$ = $2; }
OUTPUT
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/lrama/grammar/code_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,15 @@
expect { code.translated_code }.to raise_error("Tag is not specified for '$$' in '@2 -> ε'")

code = grammar.rules.find {|r| r.lhs.id.s_value == "rule7" }
expect { code.translated_code }.to raise_error("Tag is not specified for '$2' in 'rule7 -> expr, @2, '+', expr'")
expect { code.translated_code }.to raise_error("Tag is not specified for '$2' in 'rule7 -> expr @2 '+' expr'")

# midrule action in rule8
# rule8 has no tag
code = grammar.rules.find {|r| r.lhs.id.s_value == "@3" }
expect { code.translated_code }.to raise_error("Tag is not specified for '$$' in '@3 -> ε'")

code = grammar.rules.find {|r| r.lhs.id.s_value == "rule8" }
expect { code.translated_code }.to raise_error("Tag is not specified for '$2' in 'rule8 -> expr, @3, '+', expr'")
expect { code.translated_code }.to raise_error("Tag is not specified for '$2' in 'rule8 -> expr @3 '+' expr'")
end
end

Expand Down
12 changes: 6 additions & 6 deletions spec/lrama/states_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,8 @@ class go to state 5
[Includes Relation]

[Lookback Relation]
(Rule: A -> B, C, D, A) -> (State 0, A)
(Rule: A -> B, C, D, A) -> (State 7, A)
(Rule: A -> B C D A) -> (State 0, A)
(Rule: A -> B C D A) -> (State 7, A)

[Follow sets]

Expand Down Expand Up @@ -790,8 +790,8 @@ class go to state 5
[Includes Relation]

[Lookback Relation]
(Rule: A -> b, B) -> (State 0, A)
(Rule: A -> b, B) -> (State 8, A)
(Rule: A -> b B) -> (State 0, A)
(Rule: A -> b B) -> (State 8, A)

[Follow sets]

Expand Down Expand Up @@ -861,7 +861,7 @@ class go to state 5
[Includes Relation]

[Lookback Relation]
(Rule: B -> c, C) -> (State 2, B)
(Rule: B -> c C) -> (State 2, B)

[Follow sets]

Expand All @@ -884,7 +884,7 @@ class go to state 5
[Includes Relation]

[Lookback Relation]
(Rule: C -> d, A) -> (State 5, C)
(Rule: C -> d A) -> (State 5, C)

[Follow sets]

Expand Down