Class: RaccMatchParser

Inherits:
Racc::Parser
  • Object
show all
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

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
# File 'lib/sportdb/parser/racc_parser.rb', line 8

def initialize( txt,  debug: false )
  ## puts "==> txt:"
  ## puts txt
 
  parser = SportDb::Parser.new
  ### todo:
  ##  -  pass along debug flag
  ##  -   use tokenize_with_errors and add/collect tokenize errors

  @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

#debug(value) ⇒ Object



31
# File 'lib/sportdb/parser/racc_parser.rb', line 31

def debug( value ) @debug = value; end

#debug?Boolean

Returns:

  • (Boolean)


32
# File 'lib/sportdb/parser/racc_parser.rb', line 32

def debug?()  @debug == true; end

#next_tokenObject



42
43
44
45
46
# File 'lib/sportdb/parser/racc_parser.rb', line 42

def next_token
  tok = @tokens.shift
  trace( "next_token => #{tok.pretty_inspect}" )
  tok
end

#on_error(*args) ⇒ Object



60
61
62
63
64
65
# File 'lib/sportdb/parser/racc_parser.rb', line 60

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

#parseObject

on_error do |error_token_id, error_value, value_stack|

    puts "Parse error on token: #{error_token_id}, value: #{error_value}"
end


52
53
54
55
56
57
# File 'lib/sportdb/parser/racc_parser.rb', line 52

def parse    
   trace( "start parse:" )
   @tree = [] 
   do_parse
   @tree
end

#trace(msg) ⇒ Object

debug - trace / print message



35
36
37
# File 'lib/sportdb/parser/racc_parser.rb', line 35

def trace( msg )
   puts "  [parse] " + msg    if debug?
end