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: AttendanceLine, Booking, Card, CardsLine, DateHeader, Goal, GoalAlt, GoalLine, GoalLineAlt, GroupDef, GroupHeader, Lineup, LineupLine, MatchLine, Minute, PenaltiesLine, Penalty, RefereeLine, 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", "BLANK", "TEAMS", "NEWLINE", "\"---\"", "TEXT", "\"--\"", "\"-\"", "PROP_ATTENDANCE", "PROP_NUM", "PROP_END", "PROP_REFEREE", "\";\"", "ATTENDANCE", "PROP_NAME", "ENCLOSED_NAME", "PROP_PENALTIES", "\",\"", "SCORE", "PROP_YELLOWCARDS", "PROP_REDCARDS", "MINUTE", "PROP", "COACH", "\"(\"", "\")\"", "\"[\"", "\"]\"", "YELLOW_CARD", "RED_CARD", "GROUP_DEF", "\"|\"", "TEAM", "ROUND_DEF", "DATE", "DURATION", "DATETIME", "GROUP", "\"/\"", "ROUND", "ORD", "TIME", "WDAY", "STATUS", "NOTE", "\"@\"", "TIMEZONE", "VS", "SCORE_MORE", "PLAYER", "PROP_GOALS", "NONE", "OG", "PEN", "$start", "document", "elements", "element", "date_header", "group_header", "round_header", "group_def", "round_def", "match_line", "goal_lines", "goal_lines_alt", "teams_list", "lineup_lines", "yellowcard_lines", "redcard_lines", "penalties_lines", "referee_line", "attendance_line", "list", "list_item", "referee", "attendance_opt", "penalties_body", "penalty", "penalty_sep", "card_body", "player_w_minute", "card_sep", "lineup", "coach_opt", "lineup_name", "lineup_sep", "lineup_card_opts", "lineup_sub_opts", "card", "card_type", "team_values", "round_date_opts", "date_header_body", "date_header_date", "geo_opts", "round_values", "group_sep", "round_sep", "match_opts", "match", "more_match_opts", "more_matches", "date_opts", "geo_values", "match_result", "match_fixture", "match_sep", "score", "goals_alt", "goal_alt", "goal_alt_sep", "minute", "goal_lines_body", "goals", "goal_sep", "goal", "minutes", "minute_opts" ]
- Racc_debug_parser =
false
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #_reduce_none(val, _values, result) ⇒ Object
- #debug(value) ⇒ Object
- #debug? ⇒ Boolean
- #errors? ⇒ Boolean
-
#initialize(txt, debug: false) ⇒ RaccMatchParser
constructor
A new instance of RaccMatchParser.
- #next_token ⇒ Object
- #on_error(error_token_id, error_value, value_stack) ⇒ Object
-
#parse ⇒ Object
convenience shortcut (ignores errors).
-
#parse_with_errors ⇒ Object
on_error do |error_token_id, error_value, value_stack| puts “Parse error on token: #error_token_id, value: #error_value” end.
-
#trace(msg) ⇒ Object
debug - trace / print message.
Constructor Details
#initialize(txt, debug: false) ⇒ RaccMatchParser
Returns a new instance of RaccMatchParser.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sportdb/parser/racc_parser.rb', line 8 def initialize( txt, debug: false ) ## puts "==> txt:" ## puts txt @tree = [] @errors = [] ### todo: ## - pass along debug flag lexer = SportDb::Lexer.new( txt, debug: debug ) ## note - use tokenize_with_errors and add/collect tokenize errors @tokens, @errors = lexer.tokenize_with_errors ## 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 Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
66 67 68 |
# File 'lib/sportdb/parser/racc_parser.rb', line 66 def errors @errors end |
Instance Method Details
#_reduce_none(val, _values, result) ⇒ Object
1509 1510 1511 |
# File 'lib/sportdb/parser/parser.rb', line 1509 def _reduce_none(val, _values, result) val[0] end |
#debug(value) ⇒ Object
33 |
# File 'lib/sportdb/parser/racc_parser.rb', line 33 def debug( value ) @debug = value; end |
#debug? ⇒ Boolean
34 |
# File 'lib/sportdb/parser/racc_parser.rb', line 34 def debug?() @debug == true; end |
#errors? ⇒ Boolean
67 |
# File 'lib/sportdb/parser/racc_parser.rb', line 67 def errors?() @errors.size > 0; end |
#next_token ⇒ Object
44 45 46 47 48 |
# File 'lib/sportdb/parser/racc_parser.rb', line 44 def next_token tok = @tokens.shift trace( "next_token => #{tok.pretty_inspect}" ) tok end |
#on_error(error_token_id, error_value, value_stack) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/sportdb/parser/racc_parser.rb', line 70 def on_error(error_token_id, error_value, value_stack) ## auto-add error_token (as string) error_token = Racc_token_to_s_table[error_token_id] args = [error_token, error_token_id, error_value, value_stack] puts puts "!! on parse error:" puts "args=#{args.pretty_inspect}" @errors << "parse error on token: #{error_token} (#{error_token_id}) with value: #{error_value}, stack: #{value_stack.pretty_inspect}" ## exit 1 ## exit for now - get and print more info about context etc.!! end |
#parse ⇒ Object
convenience shortcut (ignores errors)
60 61 62 63 |
# File 'lib/sportdb/parser/racc_parser.rb', line 60 def parse ## convenience shortcut (ignores errors) tree, _ = parse_with_errors tree end |
#parse_with_errors ⇒ Object
on_error do |error_token_id, error_value, value_stack|
puts "Parse error on token: #{error_token_id}, value: #{error_value}"
end
54 55 56 57 58 |
# File 'lib/sportdb/parser/racc_parser.rb', line 54 def parse_with_errors trace( "start parse:" ) do_parse [@tree, @errors] end |
#trace(msg) ⇒ Object
debug - trace / print message
37 38 39 |
# File 'lib/sportdb/parser/racc_parser.rb', line 37 def trace( msg ) puts " [parse] " + msg if debug? end |