Skip to content

Commit

Permalink
Merge pull request #86 from ydah/fix-trivial-formatting
Browse files Browse the repository at this point in the history
Fix trivial formatting
  • Loading branch information
yui-knk authored Aug 22, 2023
2 parents 47b3912 + e731d26 commit f029dd6
Show file tree
Hide file tree
Showing 14 changed files with 11 additions and 52 deletions.
1 change: 0 additions & 1 deletion exe/lrama
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env ruby


$LOAD_PATH << File.join(__dir__, "../lib")
require "lrama"

Expand Down
2 changes: 0 additions & 2 deletions lib/lrama/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,15 +401,13 @@ def debug_sorted_actions
end
print sprintf("]\n\n")


print sprintf("width [\n")
vectors_count.times do |i|
print sprintf("%d, ", ary[i] ? ary[i][3] : 0)
print "\n" if i % 10 == 9
end
print sprintf("]\n\n")


print sprintf("tally [\n")
vectors_count.times do |i|
print sprintf("%d, ", ary[i] ? ary[i][2] : 0)
Expand Down
4 changes: 1 addition & 3 deletions lib/lrama/counterexamples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def find_shift_conflict_shortest_state_items(reduce_path, conflict_state, confli
end

def build_paths_from_state_items(state_items)
paths = state_items.zip([nil] + state_items).map do |si, prev_si|
state_items.zip([nil] + state_items).map do |si, prev_si|
case
when prev_si.nil?
StartPath.new(si)
Expand All @@ -215,8 +215,6 @@ def build_paths_from_state_items(state_items)
TransitionPath.new(prev_si, si)
end
end

paths
end

def shortest_path(conflict_state, conflict_reduce_item, conflict_term)
Expand Down
3 changes: 1 addition & 2 deletions lib/lrama/grammar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ def find_nterm_by_id!(id)
end || (raise "Nterm not found: #{id}")
end


def append_special_symbols
# YYEMPTY (token_id: -2, number: -2) is added when a template is evaluated
# term = add_term(id: Token.new(Token::Ident, "YYEMPTY"), token_id: -2)
Expand Down Expand Up @@ -512,7 +511,7 @@ def fill_symbol_number
sym.token_id = 11
when "\""
sym.token_id = 34
when "\'"
when "'"
sym.token_id = 39
when "\\\\"
sym.token_id = 92
Expand Down
1 change: 0 additions & 1 deletion lib/lrama/grammar/code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def translated_printer_code(tag)
end
alias :translated_error_token_code :translated_printer_code


private

# * ($1) yyvsp[i]
Expand Down
3 changes: 0 additions & 3 deletions lib/lrama/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def initialize(text)
@grammar_rules = []
@epilogue = []

#
@bison_declarations_tokens = []
@grammar_rules_tokens = []

Expand Down Expand Up @@ -314,8 +313,6 @@ def lex_line_comment(ss, line, str)
str << ss.getch
next
end

str << ss[0]
end

line # Reach to end of input
Expand Down
1 change: 0 additions & 1 deletion lib/lrama/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def set_items_to_state(items, next_state)
@items_to_state[items] = next_state
end

#
def set_look_ahead(rule, look_ahead)
reduce = reduces.find do |r|
r.rule == rule
Expand Down
4 changes: 2 additions & 2 deletions lib/lrama/states.rb
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,9 @@ def compute_default_reduction

state.default_reduction_rule = state.reduces.map do |r|
[r.rule, r.rule.id, (r.look_ahead || []).count]
end.sort_by do |rule, rule_id, count|
end.min_by do |rule, rule_id, count|
[-count, rule_id]
end.first.first
end.first
end
end

Expand Down
20 changes: 4 additions & 16 deletions lib/lrama/states_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)
end
io << "\n"


# Report shifts
tmp = state.term_transitions.select do |shift, _|
!shift.not_selected
Expand All @@ -123,7 +122,6 @@ def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)
end
io << "\n" if !tmp.empty?


# Report error caused by %nonassoc
nl = false
tmp = state.resolved_conflicts.select do |resolved|
Expand All @@ -138,7 +136,6 @@ def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)
end
io << "\n" if !tmp.empty?


# Report reduces
nl = false
max_len = state.non_default_reduces.flat_map(&:look_ahead).compact.map(&:display_name).map(&:length).max || 0
Expand Down Expand Up @@ -171,7 +168,6 @@ def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)
end
io << "\n" if nl


# Report nonterminal transitions
tmp = []
max_len = 0
Expand All @@ -189,7 +185,6 @@ def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)
end
io << "\n" if !tmp.empty?


if solved
# Report conflict resolutions
state.resolved_conflicts.each do |resolved|
Expand All @@ -202,13 +197,13 @@ def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)
# Report counterexamples
examples = cex.compute(state)
examples.each do |example|
label0 = example.type == :shift_reduce ? "shift/reduce" : "reduce/reduce"
label0 = example.type == :shift_reduce ? "shift/reduce" : "reduce/reduce"
label1 = example.type == :shift_reduce ? "Shift derivation" : "First Reduce derivation"
label2 = example.type == :shift_reduce ? "Reduce derivation" : "Second Reduce derivation"

io << " #{label0} conflict on token #{example.conflict_symbol.id.s_value}:\n"
io << " #{example.path1_item.to_s}\n"
io << " #{example.path2_item.to_s}\n"
io << " #{example.path1_item}\n"
io << " #{example.path2_item}\n"
io << " #{label1}\n"
example.derivations1.render_strings_for_report.each do |str|
io << " #{str}\n"
Expand All @@ -234,7 +229,6 @@ def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)
end
io << "\n"


# Report reads_relation
io << " [Reads Relation]\n"
@states.nterms.each do |nterm|
Expand All @@ -248,7 +242,6 @@ def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)
end
io << "\n"


# Report read_sets
io << " [Read sets]\n"
read_sets = @states.read_sets
Expand All @@ -263,7 +256,6 @@ def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)
end
io << "\n"


# Report includes_relation
io << " [Includes Relation]\n"
@states.nterms.each do |nterm|
Expand All @@ -277,7 +269,6 @@ def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)
end
io << "\n"


# Report lookback_relation
io << " [Lookback Relation]\n"
@states.rules.each do |rule|
Expand All @@ -286,12 +277,11 @@ def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)

a.each do |state_id2, nterm_id2|
n = @states.nterms.find {|n| n.token_id == nterm_id2 }
io << " (Rule: #{rule.to_s}) -> (State #{state_id2}, #{n.id.s_value})\n"
io << " (Rule: #{rule}) -> (State #{state_id2}, #{n.id.s_value})\n"
end
end
io << "\n"


# Report follow_sets
io << " [Follow sets]\n"
follow_sets = @states.follow_sets
Expand All @@ -306,7 +296,6 @@ def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)
end
io << "\n"


# Report LA
io << " [Look-Ahead Sets]\n"
tmp = []
Expand All @@ -326,7 +315,6 @@ def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)
io << "\n" if !tmp.empty?
end


# End of Report State
io << "\n"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lrama/command_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RSpec.describe Lrama::Command do
describe "#run" do
describe "a grammar file is specified " do
describe "a grammar file is specified" do
it "ends successfully" do
command = Lrama::Command.new([fixture_path("command/basic.y")])
expect(command.run).to be_nil
Expand Down
2 changes: 0 additions & 2 deletions spec/lrama/counterexamples_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
7: • digit
STR


# State 16
#
# 6 expr: expr • '+' expr
Expand Down Expand Up @@ -163,7 +162,6 @@
6: expr '+' expr •
STR


# State 17
#
# 1 stmt: keyword_if expr keyword_then stmt • keyword_else stmt
Expand Down
6 changes: 0 additions & 6 deletions spec/lrama/lexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ class : keyword_class tSTRING keyword_end %prec tPLUS
T.new(type: T::Ident, s_value: "strings_2"),
T.new(type: T::Semicolon, s_value: ";"),


T.new(type: T::Ident_Colon, s_value: "class"),
T.new(type: T::Ident, s_value: "keyword_class"),
T.new(type: T::Ident, s_value: "tSTRING"),
Expand Down Expand Up @@ -242,31 +241,26 @@ class : keyword_class tSTRING keyword_end %prec tPLUS
T.new(type: T::Char, s_value: "'>'"),
T.new(type: T::Semicolon, s_value: ";"),


T.new(type: T::Ident_Colon, s_value: "strings_1"),
T.new(type: T::Ident, s_value: "string_1"),
T.new(type: T::Semicolon, s_value: ";"),


T.new(type: T::Ident_Colon, s_value: "strings_2"),
T.new(type: T::Ident, s_value: "string_1"),
T.new(type: T::Bar, s_value: "|"),

T.new(type: T::Ident, s_value: "string_2"),
T.new(type: T::Semicolon, s_value: ";"),


T.new(type: T::Ident_Colon, s_value: "string_1"),
T.new(type: T::Ident, s_value: "string"),
T.new(type: T::Semicolon, s_value: ";"),


T.new(type: T::Ident_Colon, s_value: "string_2"),
T.new(type: T::Ident, s_value: "string"),
T.new(type: T::Char, s_value: "'+'"),
T.new(type: T::Semicolon, s_value: ";"),


T.new(type: T::Ident_Colon, s_value: "string"),
T.new(type: T::Ident, s_value: "tSTRING"),
T.new(type: T::Semicolon, s_value: ";"),
Expand Down
10 changes: 0 additions & 10 deletions spec/lrama/output_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@
allow(grammar).to receive(:parse_param).and_return("{ struct parser_params *p }")
expect(output.parse_param).to eq("struct parser_params *p")


allow(grammar).to receive(:parse_param).and_return("{int i}")
expect(output.parse_param).to eq("int i")

allow(grammar).to receive(:parse_param).and_return("{ int i }")
expect(output.parse_param).to eq("int i")


allow(grammar).to receive(:parse_param).and_return("{int parse_param}")
expect(output.parse_param).to eq("int parse_param")

Expand All @@ -51,14 +49,12 @@
allow(grammar).to receive(:parse_param).and_return("{ struct parser_params *p }")
expect(output.user_formals).to eq(", struct parser_params *p")


allow(grammar).to receive(:parse_param).and_return("{int i}")
expect(output.user_formals).to eq(", int i")

allow(grammar).to receive(:parse_param).and_return("{ int i }")
expect(output.user_formals).to eq(", int i")


allow(grammar).to receive(:parse_param).and_return("{int parse_param}")
expect(output.user_formals).to eq(", int parse_param")

Expand All @@ -84,14 +80,12 @@
allow(grammar).to receive(:parse_param).and_return("{ struct parser_params *p }")
expect(output.user_args).to eq(", p")


allow(grammar).to receive(:parse_param).and_return("{int i}")
expect(output.user_args).to eq(", i")

allow(grammar).to receive(:parse_param).and_return("{ int i }")
expect(output.user_args).to eq(", i")


allow(grammar).to receive(:parse_param).and_return("{int parse_param}")
expect(output.user_args).to eq(", parse_param")

Expand All @@ -116,14 +110,12 @@
allow(grammar).to receive(:parse_param).and_return("{ struct parser_params *p }")
expect(output.parse_param_name).to eq("p")


allow(grammar).to receive(:parse_param).and_return("{int i}")
expect(output.parse_param_name).to eq("i")

allow(grammar).to receive(:parse_param).and_return("{ int i }")
expect(output.parse_param_name).to eq("i")


allow(grammar).to receive(:parse_param).and_return("{int parse_param}")
expect(output.parse_param_name).to eq("parse_param")

Expand All @@ -140,14 +132,12 @@
allow(grammar).to receive(:lex_param).and_return("{ struct parser_params *p }")
expect(output.lex_param_name).to eq("p")


allow(grammar).to receive(:lex_param).and_return("{int i}")
expect(output.lex_param_name).to eq("i")

allow(grammar).to receive(:lex_param).and_return("{ int i }")
expect(output.lex_param_name).to eq("i")


allow(grammar).to receive(:lex_param).and_return("{int lex_param}")
expect(output.lex_param_name).to eq("lex_param")

Expand Down
4 changes: 2 additions & 2 deletions spec/lrama/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ class : keyword_class tSTRING keyword_end { code 1 }
])
end

it "action in the middle of RHS " do
it "action in the middle of RHS" do
y = header + <<~INPUT
%%
Expand Down Expand Up @@ -823,7 +823,7 @@ class : keyword_class
end
end

describe " ' in user code" do
describe "' in user code" do
it do
y = header + <<~INPUT
%%
Expand Down

0 comments on commit f029dd6

Please sign in to comment.