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, BlankLine, Booking, Card, CardsLine, DateHeader, DateHeaderLegs, Goal, GoalAlt, GoalCompat, GoalLine, GoalLineAlt, GoalLineCompat, GoalMinute, GoalType, GroupDef, HRuler, Heading1, Heading2, Heading3, Lineup, LineupLine, MatchLine, MatchLineBye, MatchLineLegs, MatchLineWalkover, Minute, NotaBene, NoteLine, PenaltiesLine, Penalty, Referee, RefereeLine, RoundDef, RoundOutline, Sub, TableDivider, TableHeading, TableLine, TableNote
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", "H1", "NEWLINE", "H2", "H3", "TABLE_HEADING", "TABLE_LINE", "TABLE_NOTE", "TABLE_DIVIDER", "NOTE", "NOTA_BENE", "HRULER", "\"|\"", "\":\"", "GROUP_DEF", "TEAM", "\",\"", "ROUND_OUTLINE", "ROUND_DEF", "DATE", "DURATION", "YEAR", "DATETIME", "TIME", "DATE_LEGS", "STATUS", "INLINE_ATTENDANCE", "INLINE_ATTENDANCE_SEP", "SCORE_LEGS", "INLINE_GOALS", "GOALS_END", "TEAMALT", "TEAMALT_PEN", "TEAMALT_NUM", "TTY_TEXT", "TTY_NUM", "ORD", "\"@\"", "GEO", "TEAM_HOME", "TEAM_AWAY", "TEAM_NEUTRAL", "INLINE_BYE", "INLINE_WO", "\"-\"", "VS", "INLINE_NP", "INLINE_CANC", "INLINE_PPD", "SCORE_FULL", "SCORE_FULLER", "SCORE", "SCORE_AWD", "INLINE_AWD", "SCORE_ABD", "INLINE_ABD", "INLINE_VOID", "INLINE_SUSP", "SCORE_FULLER_MORE", "GOALS", "GOALS_NONE", "\";\"", "GOAL_SEP_ALT", "PLAYER", "GOAL_COUNT", "GOAL_MINUTE_SEP", "GOAL_MINUTE", "GOALS_ALT", "GOAL_TYPE", "GOALS_COMPAT", "MINUTE", "PROP_ATTENDANCE", "PROP_NUM", "PROP_END", "PROP_REFEREE", "ATTENDANCE", "PROP_NAME", "ENCLOSED_NAME", "PROP_PENALTIES", "PROP_YELLOWCARDS", "PROP_REDCARDS", "PROP", "COACH", "INLINE_CAPTAIN", "\"(\"", "\")\"", "INLINE_YELLOW", "INLINE_YELLOW_RED", "INLINE_RED", "$start", "document", "elements", "element", "heading", "group_def", "round_def", "round_outline", "date_header", "match_line_with_header", "match_line", "match_line_alt", "date_header_legs", "match_line_legs", "note_line", "nota_bene", "hruler", "table_line", "goal_lines", "goal_lines_alt", "goal_lines_compat", "lineup_lines", "yellowcard_lines", "redcard_lines", "penalties_lines", "referee_line", "attendance_line", "group_def_sep", "team_values", "round_def_sep", "round_date_opts", "date", "datetime", "time", "date_clause", "opt_date", "opt_blank_lines", "blank_lines", "match_header", "match_line_header", "opt_ord", "match", "more_match_header_opts", "match_line_alt_props", "geo_opts", "opt_inline_attendance", "inline_attendance", "match_fixture", "opt_inline_note", "match_opts", "more_match_opts", "match_bye", "match_walkover", "match_result", "goal_lines_body", "match_alt_inline", "match_alt_block", "opt_status_line", "opt_newline", "ord", "opt_geo", "geo_values", "match_fixture_not_played", "match_fixture_postponed", "match_fixture_base", "match_result_base", "match_sep", "score_full_or_fuller", "goals", "goals_sep", "opt_goal_sep", "goal", "goal_minutes", "opt_goal_minute_sep", "goal_minute", "goals_alt", "goal_alt", "goals_compat", "goal_compat", "referees", "attendance_opt", "referee", "penalties_body", "penalty", "penalty_sep", "card_body", "player_w_minute", "card_sep", "lineup", "coach_opt", "lineup_name", "lineup_sep", "lineup_cards_opts", "cards", "lineup_captain_opt", "lineup_name_plus_cards_opts", "lineup_sub_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
fix: use setter-style e.g.
- #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.
Methods inherited from Racc::Parser
#_racc_do_parse_rb, #_racc_do_reduce, #_racc_evalact, #_racc_init_sysvars, #_racc_setup, #do_parse, #racc_accept, #racc_e_pop, #racc_next_state, #racc_print_stacks, #racc_print_states, #racc_read_token, #racc_reduce, #racc_shift, #racc_token2str, #token_to_str, #yyaccept, #yyerrok, #yyerror
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
2478 2479 2480 |
# File 'lib/sportdb/parser/parser.rb', line 2478 def _reduce_none(val, _values, result) val[0] end |
#debug(value) ⇒ Object
fix: use setter-style e.g. debug=(value) !!!
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 |