Skip to content

Commit

Permalink
Merge branch 'master' into parameterizing-rules-meets-conditonal
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Aug 21, 2024
2 parents 77218fe + e61bb6f commit 395f5c3
Show file tree
Hide file tree
Showing 28 changed files with 1,018 additions and 1,175 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source 'https://rubygems.org'
gemspec

gem "pry"
gem "racc", "1.8.0"
gem "racc", "1.8.1"
gem "rake"
gem "rspec"
gem "simplecov", require: false
Expand All @@ -15,6 +15,6 @@ gem "memory_profiler"
# Recent steep requires Ruby >= 3.0.0.
# Then skip install on some CI jobs.
if !ENV['GITHUB_ACTION'] || ENV['INSTALL_STEEP'] == 'true'
gem "rbs", "3.5.1", require: false
gem "rbs", "3.5.2", require: false
gem "steep", "1.7.1", require: false
end
2 changes: 2 additions & 0 deletions Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ target :lib do
check "lib/lrama/grammar"
check "lib/lrama/lexer"
check "lib/lrama/report"
check "lib/lrama/state"
check "lib/lrama/states"
check "lib/lrama/bitmap.rb"
check "lib/lrama/digraph.rb"
check "lib/lrama/grammar.rb"
Expand Down
10 changes: 5 additions & 5 deletions lib/lrama/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def compute_yydefact

# If no default_reduction_rule, default behavior is an
# error then replace ErrorActionNumber with zero.
if !state.default_reduction_rule
unless state.default_reduction_rule
actions.map! do |e|
if e == ErrorActionNumber
0
Expand Down Expand Up @@ -303,17 +303,17 @@ def compute_yydefgoto
end

@states.nterms.each do |nterm|
if !(states = nterm_to_next_states[nterm])
default_goto = 0
not_default_gotos = []
else
if (states = nterm_to_next_states[nterm])
default_state = states.map(&:last).group_by {|s| s }.max_by {|_, v| v.count }.first
default_goto = default_state.id
not_default_gotos = []
states.each do |from_state, to_state|
next if to_state.id == default_goto
not_default_gotos << [from_state.id, to_state.id]
end
else
default_goto = 0
not_default_gotos = []
end

k = nterm_number_to_sequence_number(nterm.number)
Expand Down
14 changes: 7 additions & 7 deletions lib/lrama/counterexamples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,13 @@ def find_shift_conflict_shortest_state_items(reduce_path, conflict_state, confli
break
end

if !si.item.beginning_of_rule?
if si.item.beginning_of_rule?
key = [si.state, si.item.lhs]
@reverse_productions[key].each do |item|
state_item = StateItem.new(si.state, item)
queue << (sis + [state_item])
end
else
key = [si, si.item.previous_sym]
@reverse_transitions[key].each do |prev_target_state_item|
next if prev_target_state_item.state != prev_state_item.state
Expand All @@ -185,12 +191,6 @@ def find_shift_conflict_shortest_state_items(reduce_path, conflict_state, confli
queue.clear
break
end
else
key = [si.state, si.item.lhs]
@reverse_productions[key].each do |item|
state_item = StateItem.new(si.state, item)
queue << (sis + [state_item])
end
end
end
else
Expand Down
2 changes: 1 addition & 1 deletion lib/lrama/grammar/parameterizing_rule/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def find_rule(token)
end

def find_inline(token)
@rules.select { |rule| rule.name == token.s_value && rule.is_inline }.last
@rules.reverse.find { |rule| rule.name == token.s_value && rule.is_inline }
end

def created_lhs(lhs_s_value)
Expand Down
10 changes: 3 additions & 7 deletions lib/lrama/grammar/rule_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,15 @@ def initialize(rule_counter, midrule_action_counter, parameterizing_rule_resolve
end

def add_rhs(rhs)
if !@line
@line = rhs.line
end
@line ||= rhs.line

flush_user_code

@rhs << rhs
end

def user_code=(user_code)
if !@line
@line = user_code&.line
end
@line ||= user_code&.line

flush_user_code

Expand Down Expand Up @@ -73,7 +69,7 @@ def has_inline_rules?
def resolve_inline_rules
resolved_builders = []
rhs.each_with_index do |token, i|
if inline_rule = @parameterizing_rule_resolver.find_inline(token)
if (inline_rule = @parameterizing_rule_resolver.find_inline(token))
inline_rule.rhs_list.each do |inline_rhs|
rule_builder = RuleBuilder.new(@rule_counter, @midrule_action_counter, @parameterizing_rule_resolver, lhs_tag: lhs_tag)
if token.is_a?(Lexer::Token::InstantiateRule)
Expand Down
10 changes: 5 additions & 5 deletions lib/lrama/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Lexer
attr_reader :head_line, :head_column, :line
attr_accessor :status, :end_symbol

SYMBOLS = ['%{', '%}', '%%', '{', '}', '\[', '\]', '\(', '\)', '\,', ':', '\|', ';']
SYMBOLS = ['%{', '%}', '%%', '{', '}', '\[', '\]', '\(', '\)', '\,', ':', '\|', ';'].freeze
PERCENT_TOKENS = %w(
%union
%token
Expand Down Expand Up @@ -44,7 +44,7 @@ class Lexer
%if
%true
%false
)
).freeze

def initialize(grammar_file)
@grammar_file = grammar_file
Expand Down Expand Up @@ -77,7 +77,7 @@ def location
end

def lex_token
while !@scanner.eos? do
until @scanner.eos? do
case
when @scanner.scan(/\n/)
newline
Expand Down Expand Up @@ -132,7 +132,7 @@ def lex_c_code
code = ''
reset_first_position

while !@scanner.eos? do
until @scanner.eos? do
case
when @scanner.scan(/{/)
code += @scanner.matched
Expand Down Expand Up @@ -169,7 +169,7 @@ def lex_c_code
private

def lex_comment
while !@scanner.eos? do
until @scanner.eos? do
case
when @scanner.scan(/\n/)
newline
Expand Down
2 changes: 1 addition & 1 deletion lib/lrama/lexer/token/user_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _references
scanner = StringScanner.new(s_value)
references = []

while !scanner.eos? do
until scanner.eos? do
case
when reference = scan_reference(scanner)
references << reference
Expand Down
12 changes: 6 additions & 6 deletions lib/lrama/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def parse(argv)
@options.report_opts = validate_report(@report)
@options.grammar_file = argv.shift

if !@options.grammar_file
unless @options.grammar_file
abort "File should be specified\n"
end

Expand Down Expand Up @@ -90,7 +90,7 @@ def parse_by_option_parser(argv)
o.on_tail ' time display generation time'
o.on_tail ' all include all the above traces'
o.on_tail ' none disable all traces'
o.on('-v', 'reserved, do nothing') { }
o.on('-v', '--verbose', "same as '--report=state'") {|_v| @report << 'states' }
o.separator ''
o.separator 'Diagnostics:'
o.on('-W', '--warnings', 'report the warnings') {|v| @options.diagnostic = true }
Expand All @@ -106,8 +106,8 @@ def parse_by_option_parser(argv)
end
end

ALIASED_REPORTS = { cex: :counterexamples }
VALID_REPORTS = %i[states itemsets lookaheads solved counterexamples rules terms verbose]
ALIASED_REPORTS = { cex: :counterexamples }.freeze
VALID_REPORTS = %i[states itemsets lookaheads solved counterexamples rules terms verbose].freeze

def validate_report(report)
h = { grammar: true }
Expand Down Expand Up @@ -138,11 +138,11 @@ def aliased_report_option(opt)
locations scan parse automaton bitsets closure
grammar rules actions resource sets muscles
tools m4-early m4 skeleton time ielr cex
]
].freeze
NOT_SUPPORTED_TRACES = %w[
locations scan parse bitsets grammar resource
sets muscles tools m4-early m4 skeleton ielr cex
]
].freeze

def validate_trace(trace)
h = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/lrama/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def partial_file(file)
end

def template_dir
File.expand_path("../../../template", __FILE__)
File.expand_path('../../template', __dir__)
end

def string_array_to_string(ary)
Expand Down
Loading

0 comments on commit 395f5c3

Please sign in to comment.