Class: RaccMatchParser
- Inherits:
-
Racc::Parser
- Object
- Racc::Parser
- RaccMatchParser
- Defined in:
- lib/sportdb/parser/racc_tree.rb,
lib/sportdb/parser/parser.rb,
lib/sportdb/parser/racc_parser.rb
Overview
RaccMatchParser support machinery (incl. node classes/abstract syntax tree)
Defined Under Namespace
Classes: Card, DateHeader, Goal, GoalLine, GroupDef, GroupHeader, Lineup, LineupLine, MatchLine, Minute, RoundDef, RoundHeader, Sub
Constant Summary collapse
- Racc_arg =
[ racc_action_table, racc_action_check, racc_action_default, racc_action_pointer, racc_goto_table, racc_goto_check, racc_goto_default, racc_goto_pointer, racc_nt_base, racc_reduce_table, racc_token_table, racc_shift_n, racc_reduce_n, racc_use_result_var ]
- Racc_token_to_s_table =
[ "$end", "error", "PROP", "\".\"", "NEWLINE", "\",\"", "\"-\"", "PROP_NAME", "\"(\"", "\")\"", "\"[\"", "\"]\"", "YELLOW_CARD", "RED_CARD", "GROUP_DEF", "\"|\"", "TEAM", "ROUND_DEF", "DATE", "DURATION", "GROUP", "ROUND", "ORD", "TIME", "STATUS", "\"@\"", "TIMEZONE", "TEXT", "VS", "SCORE", "\";\"", "PLAYER", "MINUTE", "OG", "PEN", "$start", "statements", "statement", "date_header", "group_header", "round_header", "group_def", "round_def", "match_line", "goal_lines", "empty_line", "lineup_lines", "lineup", "lineup_name", "lineup_sep", "lineup_name_more", "card", "lineup_sub", "minute", "card_body", "card_type", "team_values", "round_date_opts", "round_values", "round_sep", "match_opts", "match", "more_match_opts", "more_matches", "date_opts", "geo_opts", "geo_values", "match_result", "match_fixture", "match_sep", "goal_lines_body", "goals", "goal_sep", "goal", "minutes", "minute_opts" ]
- Racc_debug_parser =
false
Instance Method Summary collapse
- #_reduce_none(val, _values, result) ⇒ Object
-
#initialize(txt) ⇒ RaccMatchParser
constructor
A new instance of RaccMatchParser.
- #next_token ⇒ Object
- #on_error(*args) ⇒ Object
-
#parse ⇒ Object
on_error do |error_token_id, error_value, value_stack| puts “Parse error on token: #error_token_id, value: #error_value” end.
Constructor Details
#initialize(txt) ⇒ RaccMatchParser
Returns a new instance of RaccMatchParser.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sportdb/parser/racc_parser.rb', line 8 def initialize( txt ) ## puts "==> txt:" ## puts txt parser = SportDb::Parser.new @tokens = parser.tokenize( txt ) ## pp @tokens ## quick hack - convert to racc format single char literal tokens e.g. '@' etc. @tokens = @tokens.map do |tok| if tok.size == 1 [tok[0].to_s, tok[0].to_s] else tok end end end |
Instance Method Details
#_reduce_none(val, _values, result) ⇒ Object
933 934 935 |
# File 'lib/sportdb/parser/parser.rb', line 933 def _reduce_none(val, _values, result) val[0] end |
#next_token ⇒ Object
27 28 29 30 31 |
# File 'lib/sportdb/parser/racc_parser.rb', line 27 def next_token tok = @tokens.shift puts "next_token => #{tok.pretty_inspect}" tok end |
#on_error(*args) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/sportdb/parser/racc_parser.rb', line 45 def on_error(*args) puts puts "!! on parse error:" puts "args=#{args.pretty_inspect}" exit 1 ## exit for now - get and print more info about context etc.!! end |
#parse ⇒ Object
on_error do |error_token_id, error_value, value_stack|
puts "Parse error on token: #{error_token_id}, value: #{error_value}"
end
37 38 39 40 41 42 |
# File 'lib/sportdb/parser/racc_parser.rb', line 37 def parse puts "parse:" @tree = [] do_parse @tree end |