Class: ValveCfgParser
- Inherits:
-
Racc::Parser
- Object
- Racc::Parser
- ValveCfgParser
- Defined in:
- lib/valve-cfg.tab.rb,
lib/valve-cfg-parser.rb
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", "IDENT", "QUOTED_COMMAND", "QUOTED_STRING", "NUMBER", "COMMENT_STRING", "DELIMITER", "LINE_FEED", "$start", "target", "exp", "delim", "param", "cmd", "comment", "command", "argument_list", "argument" ]
- Racc_debug_parser =
false
Instance Attribute Summary collapse
-
#last_error ⇒ Object
Returns the value of attribute last_error.
Instance Method Summary collapse
-
#_reduce_none(val, _values, result) ⇒ Object
reduce 24 omitted.
- #next_token ⇒ Object
- #on_error(token, token_value, stack) ⇒ Object
- #parse(str) ⇒ Object
Instance Attribute Details
#last_error ⇒ Object
Returns the value of attribute last_error.
4 5 6 |
# File 'lib/valve-cfg-parser.rb', line 4 def last_error @last_error end |
Instance Method Details
#_reduce_none(val, _values, result) ⇒ Object
reduce 24 omitted
188 189 190 |
# File 'lib/valve-cfg.tab.rb', line 188 def _reduce_none(val, _values, result) val[0] end |
#next_token ⇒ Object
39 40 41 |
# File 'lib/valve-cfg-parser.rb', line 39 def next_token @q.shift end |
#on_error(token, token_value, stack) ⇒ Object
43 44 45 46 |
# File 'lib/valve-cfg-parser.rb', line 43 def on_error(token, token_value, stack) @last_error = [token, token_value, stack] raise "ERROR: token:#{token}, value:#{token_value}, stack:#{stack}" end |
#parse(str) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/valve-cfg-parser.rb', line 6 def parse(str) @q = [] until str.empty? case str when /\A(\r\n|\n)/ @q.push [:LINE_FEED, $&] when /\A\s+/ when /\A[\d\.]+/ @q.push [:NUMBER, $&] when /\A\/\/.*$/ @q.push [:COMMENT_STRING, $&] # when /\A"([^\\"]|\\")*"/ when /\A"[^\s]+"/ @q.push [:QUOTED_COMMAND, $&] when /\A".*"/ @q.push [:QUOTED_STRING, $&] # when /\A'([^\\']|\\')*'/ # @q.push [:QUOTED_STRING, $&] when /\A[a-zA-Z\-\+\\]\w*/ @q.push [:IDENT, $&] when /\A;/ @q.push [:DELIMITER, $&] when /\A./o s = $& @q.push [s, s] end str = $' end @q.push [false, '$end'] # p @q do_parse end |