Skip to content

Commit

Permalink
Remove , from Rule print format
Browse files Browse the repository at this point in the history
  • Loading branch information
yui-knk committed Apr 17, 2024
1 parent 1d9f17b commit d769505
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
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
16 changes: 8 additions & 8 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 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

0 comments on commit d769505

Please sign in to comment.