Class: RaccMatchParser
- Inherits:
-
Racc::Parser
- Object
- Racc::Parser
- RaccMatchParser
- Defined in:
- lib/sportdb/parser/parser.rb,
lib/sportdb/parser/racc_tree.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, Heading1, Heading2, Heading3, Lineup, LineupLine, MatchLine, MatchLineBye, MatchLineLegs, MatchLineWalkover, Minute, NotaBene, NoteLine, PenaltiesLine, Penalty, Referee, RefereeLine, RoundDef, RoundOutline, 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", "H1", "NEWLINE", "H2", "H3", "NOTE", "NOTA_BENE", "\"|\"", "\":\"", "GROUP_DEF", "TEAM", "\",\"", "ROUND_OUTLINE", "ROUND_DEF", "DATE", "DURATION", "YEAR", "DATETIME", "TIME", "DATE_LEGS", "\"@\"", "GEO", "\"-\"", "VS", "INLINE_NP", "INLINE_CANC", "INLINE_PPD", "SCORE_FULL", "SCORE_FULLER", "SCORE", "SCORE_AWD", "SCORE_ABD", "SCORE_FULLER_MORE", "INLINE_AWD", "INLINE_ABD", "INLINE_VOID", "INLINE_SUSP", "TEAM_HOME", "TEAM_AWAY", "TEAM_NEUTRAL", "ORD", "match_line_alt_props", "STATUS", "INLINE_ATTENDANCE", "INLINE_ATTENDANCE_SEP", "INLINE_GOALS", "GOALS_END", "INLINE_BYE", "INLINE_WO", "SCORE_LEGS", "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", "PROP_NAME", "ENCLOSED_NAME", "ATTENDANCE", "PROP_YELLOWCARDS", "PROP_REDCARDS", "PROP_PENALTIES", "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", "date_header_legs", "match_line_legs", "note_line", "nota_bene", "goal_lines", "goal_lines_alt", "goal_lines_compat", "lineup_lines", "yellowcard_lines", "redcard_lines", "penalties_lines", "referee_line", "attendance_line", "opt_blank_lines", "blank_lines", "group_def_sep", "team_values", "round_def_sep", "round_date_opts", "date", "datetime", "time", "date_datetime", "opt_date", "geo", "geo_names", "opt_geo", "match_sep", "match_fixture", "match_fixture_not_played", "match_fixture_postponed", "SCORE_FULL_OR_FULLER", "match_result", "match_fixture_base", "match_result_base", "ord", "opt_ord", "match_header", "match_line_header", "match", "more_match_header_opts", "opt_inline_attendance", "inline_attendance", "opt_inline_note", "match_opts", "more_match_opts", "match_bye", "match_walkover", "goal_lines_body", "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", "card_body", "player_w_minute", "card_sep", "penalties_body", "penalty_sep", "penalty", "lineup", "coach_opt", "lineup_sep", "lineup_name", "lineup_name_plus_cards_opts", "lineup_sub_opts", "lineup_captain_opt", "lineup_cards_opts", "cards" ]
- 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
- #_trace(*args) ⇒ 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
fix-fix-fix rename to _trace check lexer - add [debug] Parser - or such!!!.
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.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/sportdb/parser/racc_parser.rb', line 9 def initialize( txt, debug: false ) @tree = [] @errors = [] 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 end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
75 76 77 |
# File 'lib/sportdb/parser/racc_parser.rb', line 75 def errors @errors end |
Instance Method Details
#_reduce_none(val, _values, result) ⇒ Object
2179 2180 2181 |
# File 'lib/sportdb/parser/parser.rb', line 2179 def _reduce_none(val, _values, result) val[0] end |
#_trace(*args) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/sportdb/parser/racc_parser.rb', line 34 def _trace( *args ) ## if debug? print "[DEBUG] Parser -- " args.each { |arg| puts args } ## end end |
#debug(value) ⇒ Object
fix: use setter-style e.g. debug=(value) !!!
21 |
# File 'lib/sportdb/parser/racc_parser.rb', line 21 def debug( value ) @debug = value; end |
#debug? ⇒ Boolean
22 |
# File 'lib/sportdb/parser/racc_parser.rb', line 22 def debug?() @debug == true; end |
#errors? ⇒ Boolean
76 |
# File 'lib/sportdb/parser/racc_parser.rb', line 76 def errors?() @errors.size > 0; end |
#next_token ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/sportdb/parser/racc_parser.rb', line 42 def next_token tok = @tokens.shift _trace( "next_token => #{tok.pretty_inspect}" ) ## convert to racc format single char literal tokens e.g. '@' etc. ## note - literal token MUST be string (NOT symbol) ## note - racc expects array with to items ## - item[0] is the token id ## - item[1] is the token value ## note - returns nil for end-of-file !!! tok = [tok.type, tok] if tok tok end |
#on_error(error_token_id, error_value, value_stack) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/sportdb/parser/racc_parser.rb', line 79 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_value.pretty_inspect}<, stack: #{value_stack.pretty_inspect}" end |
#parse ⇒ Object
convenience shortcut (ignores errors)
69 70 71 72 |
# File 'lib/sportdb/parser/racc_parser.rb', line 69 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
63 64 65 66 67 |
# File 'lib/sportdb/parser/racc_parser.rb', line 63 def parse_with_errors _trace( "start parse:" ) do_parse [@tree, @errors] end |
#trace(msg) ⇒ Object
fix-fix-fix rename to _trace
check lexer - add [debug] Parser - or such!!!
debug - trace / print message
29 30 31 32 |
# File 'lib/sportdb/parser/racc_parser.rb', line 29 def trace( msg ) puts " fix-fix-fix use _trace() in parser!!" puts " [parse] " + msg end |