qasim/mapparser.rb
2009-06-09 08:27:52 +00:00

394 lines
8.1 KiB
Ruby
Executable file

#
# DO NOT MODIFY!!!!
# This file is automatically generated by racc 1.4.5
# from racc grammer file "mapparser.y".
#
require 'racc/parser'
# calc.rb : generated by racc
#
require 'strscan'
#require 'map.rb'
class MapParser < Racc::Parser
module_eval <<'..end mapparser.y modeval..id78efd83f53', 'mapparser.y', 68
def parse( str )
puts "parse start..."
tokens = []
scanner = StringScanner.new( str )
puts ( "scanner?" + scanner.string )
until scanner.eos?
puts "scanning.. at #{scanner.pos}"
case
when m = scanner.scan( /\/\/.*$/ )
# comments
when m = scanner.scan( /(\s+|\n)/ )
# whitespace and newlines
when m = scanner.scan( /\{/ )
tokens.push [:OBRACE, m]
when m = scanner.scan( /\}/ )
tokens.push [:EBRACE, m]
when m = scanner.scan( /;/ )
tokens.push [:SEMICOLON, m]
when m = scanner.scan( /\d+/ )
tokens.push [:NUMBER, m]
when m = scanner.scan( /user/i )
tokens.push [:USER, m]
when m = scanner.scan( /automount/i )
tokens.push [:AUTOMOUNT, m]
when m = scanner.scan( /reconnect/i )
tokens.push [:RECONNECT, m]
when m = scanner.scan( /compress/i )
tokens.push [:COMPRESS, m]
when m = scanner.scan( /port/i )
tokens.push [:PORT, m]
when m = scanner.scan( /(true|1|yes)/i )
tokens.push [:BOOL_TRUE, m]
when m = scanner.scan( /(false|0|no)/i )
tokens.push [:BOOL_FALSE, m]
when m = scanner.scan( /".+?"/i )
tokens.push [:STRING, m]
when m = scanner.scan( /map/i )
tokens.push [:MAP, m]
when m = scanner.scan( /server/i )
tokens.push [:SERVER, m]
when m = scanner.scan( /./ )
tokens.push [:UNMATCHED, m]
puts "UNMATCHED #{m} after #{scanner.pre_match}"
end
end
puts "tokenization ok"
tokens.push [false, false]
@last_value = yyparse( tokens, :each )
puts "parse end... "
end
def on_error(error_token_id, error_value, value_stack)
msg = "parse error "
msg << "after #{value_stack.last} " if value_stack.length > 1
#msg << "after #{value_stack.last} " unless value_stack.empty?
msg << "on #{token_to_str(error_token_id)} #{error_value}"
raise ParseError, msg
end
..end mapparser.y modeval..id78efd83f53
##### racc 1.4.5 generates ###
racc_reduce_table = [
0, 0, :racc_error,
3, 20, :_reduce_1,
0, 20, :_reduce_2,
1, 21, :_reduce_none,
1, 21, :_reduce_none,
5, 23, :_reduce_5,
4, 22, :_reduce_none,
3, 24, :_reduce_none,
0, 24, :_reduce_none,
1, 25, :_reduce_9,
1, 25, :_reduce_10,
1, 25, :_reduce_11,
1, 25, :_reduce_12,
1, 25, :_reduce_13,
1, 25, :_reduce_14,
5, 31, :_reduce_none,
3, 32, :_reduce_none,
0, 32, :_reduce_none,
2, 26, :_reduce_18,
2, 27, :_reduce_19,
2, 28, :_reduce_20,
2, 29, :_reduce_21,
2, 30, :_reduce_22,
1, 33, :_reduce_23,
1, 33, :_reduce_24 ]
racc_reduce_n = 25
racc_shift_n = 44
racc_action_table = [
25, 33, 34, 28, 3, 16, 17, 5, 18, 20,
22, 6, 41, 33, 34, 30, 42, 33, 34, 15,
12, 13, 31, 11, 35, 10, 9, 38, 39, 8,
43 ]
racc_action_check = [
14, 18, 18, 14, 1, 14, 14, 1, 14, 14,
14, 1, 40, 22, 22, 16, 40, 20, 20, 13,
9, 10, 17, 7, 19, 6, 5, 28, 38, 3,
42 ]
racc_action_pointer = [
nil, 4, nil, 29, nil, 22, 20, 21, nil, 15,
13, nil, nil, 13, -6, nil, 11, 9, -16, 22,
0, nil, -4, nil, nil, nil, nil, nil, 23, nil,
nil, nil, nil, nil, nil, nil, nil, nil, 23, nil,
6, nil, 28, nil ]
racc_action_default = [
-2, -25, -3, -25, -4, -25, -25, -25, 44, -25,
-25, -1, -8, -25, -25, -6, -25, -25, -25, -25,
-25, -9, -25, -10, -11, -5, -12, -13, -25, -14,
-18, -19, -20, -23, -24, -7, -21, -22, -25, -17,
-25, -15, -25, -16 ]
racc_goto_table = [
32, 23, 36, 2, 37, 4, 14, 19, 21, 7,
24, 26, 27, 29, 40, 1 ]
racc_goto_check = [
14, 8, 14, 3, 14, 4, 5, 6, 7, 2,
9, 10, 11, 12, 13, 1 ]
racc_goto_pointer = [
nil, 15, 8, 2, 4, -6, -7, -6, -13, -4,
-3, -2, -1, -25, -18 ]
racc_goto_default = [
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
nil, nil, nil, nil, nil ]
racc_token_table = {
false => 0,
Object.new => 1,
:SEMICOLON => 2,
:SERVER => 3,
:STRING => 4,
:OBRACE => 5,
:EBRACE => 6,
:GLOBAL => 7,
:global_opts => 8,
:MAP => 9,
:server_map_opt => 10,
:USER => 11,
:PORT => 12,
:NUMBER => 13,
:AUTOMOUNT => 14,
:COMPRESS => 15,
:RECONNECT => 16,
:BOOL_TRUE => 17,
:BOOL_FALSE => 18 }
racc_use_result_var = true
racc_nt_base = 19
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',
'SEMICOLON',
'SERVER',
'STRING',
'OBRACE',
'EBRACE',
'GLOBAL',
'global_opts',
'MAP',
'server_map_opt',
'USER',
'PORT',
'NUMBER',
'AUTOMOUNT',
'COMPRESS',
'RECONNECT',
'BOOL_TRUE',
'BOOL_FALSE',
'$start',
'commands',
'command_blk',
'global_blk',
'server_blk',
'server_opts',
'server_opt',
'user_opt',
'port_opt',
'automount_opt',
'compress_opt',
'reconnect_opt',
'server_map_blk',
'server_map_opts',
'boolean']
Racc_debug_parser = false
##### racc system variables end #####
# reduce 0 omitted
module_eval <<'.,.,', 'mapparser.y', 5
def _reduce_1( val, _values, result )
puts "GOT A COMMAND"
result
end
.,.,
module_eval <<'.,.,', 'mapparser.y', 6
def _reduce_2( val, _values, result )
puts "no command found"
result
end
.,.,
# reduce 3 omitted
# reduce 4 omitted
module_eval <<'.,.,', 'mapparser.y', 13
def _reduce_5( val, _values, result )
puts "[server #{val[1]}]"
result
end
.,.,
# reduce 6 omitted
# reduce 7 omitted
# reduce 8 omitted
module_eval <<'.,.,', 'mapparser.y', 23
def _reduce_9( val, _values, result )
puts "=> user opt"
result
end
.,.,
module_eval <<'.,.,', 'mapparser.y', 24
def _reduce_10( val, _values, result )
puts "=> port opt"
result
end
.,.,
module_eval <<'.,.,', 'mapparser.y', 25
def _reduce_11( val, _values, result )
puts "=> automount opt"
result
end
.,.,
module_eval <<'.,.,', 'mapparser.y', 26
def _reduce_12( val, _values, result )
puts "=> compress opt"
result
end
.,.,
module_eval <<'.,.,', 'mapparser.y', 27
def _reduce_13( val, _values, result )
puts "=> reconnect opt"
result
end
.,.,
module_eval <<'.,.,', 'mapparser.y', 28
def _reduce_14( val, _values, result )
puts "=> server_map blk"
result
end
.,.,
# reduce 15 omitted
# reduce 16 omitted
# reduce 17 omitted
module_eval <<'.,.,', 'mapparser.y', 39
def _reduce_18( val, _values, result )
puts "* user = #{val[1]}"
result
end
.,.,
module_eval <<'.,.,', 'mapparser.y', 42
def _reduce_19( val, _values, result )
puts "* port = #{val[1]}"
result
end
.,.,
module_eval <<'.,.,', 'mapparser.y', 45
def _reduce_20( val, _values, result )
puts "* automount = #{@bool_result}"
result
end
.,.,
module_eval <<'.,.,', 'mapparser.y', 48
def _reduce_21( val, _values, result )
puts "* compress = #{@bool_result}"
result
end
.,.,
module_eval <<'.,.,', 'mapparser.y', 51
def _reduce_22( val, _values, result )
puts ( "* reconnect = #{@bool_result}" )
result
end
.,.,
module_eval <<'.,.,', 'mapparser.y', 54
def _reduce_23( val, _values, result )
@bool_result = true
result
end
.,.,
module_eval <<'.,.,', 'mapparser.y', 55
def _reduce_24( val, _values, result )
@bool_result = false
result
end
.,.,
def _reduce_none( val, _values, result )
result
end
end # class MapParser
puts "GOO"
bigstr = ""
STDIN.read.split(/\n/).each do |a|
puts "READING #{a}"
bigstr = bigstr + a
end
puts "PARSING NOW..."
parser = MapParser.new
begin
val = parser.parse( bigstr )
print '= ', val, "\n"
rescue ParseError
puts $!
end