TeensyMud - 'A ruby mud server.'

Browse repository
back

boolexp.rb

#
# DO NOT MODIFY!!!!
# This file is automatically generated by Racc 1.4.9
# from Racc grammer file "".
#

require 'racc/parser.rb'


#
# file:: boolexp_parser.rb
# author:: Jon A. Lambert
# version:: 2.8.0
# date:: 01/19/2006
#
# This source code copyright (C) 2005, 2006 by Jon A. Lambert
# All rights reserved.
#
# Released under the terms of the TeensyMUD Public License
# See LICENSE file for additional information.
#
$:.unshift "lib" if !$:.include? "lib"
$:.unshift "vendor" if !$:.include? "vendor"

if $0 == __FILE__
Dir.chdir("../..")
$:.unshift "../../lib"
require 'pp'
end
require 'core/script'

class BoolExpParser < Racc::Parser

module_eval(<<'...end boolexp.y/module_eval...', 'boolexp.y', 58)

def initialize(obj)
@obj = obj
end

def parse(str)
@q = []
until str.empty?
case str
when /\A\s+/
when /\A[#]?(\d+)/
@q.push [:NUMBER, $1.to_i]
when /\A.|\n/o
s = $&
@q.push [s, s]
end
str = $'
end
@q.push [false, '$end']
do_parse
end

def next_token
@q.shift
end

...end boolexp.y/module_eval...
##### State transition tables begin ###

racc_action_table = [
3, 3, 10, 2, 2, 4, 4, 3, 3, 9,
2, 2, 4, 4, 5, 6, nil, 6, 7, 6,
7, nil, 13 ]

racc_action_check = [
0, 7, 5, 0, 7, 0, 7, 2, 6, 3,
2, 6, 2, 6, 1, 12, nil, 1, 1, 8,
8, nil, 8 ]

racc_action_pointer = [
-2, 14, 5, 2, nil, 2, 6, -1, 16, nil,
nil, nil, 12, nil ]

racc_action_default = [
-6, -6, -6, -6, -5, -6, -6, -6, -6, -4,
14, -1, -2, -3 ]

racc_goto_table = [
1, nil, 8, nil, nil, nil, 11, 12 ]

racc_goto_check = [
1, nil, 1, nil, nil, nil, 1, 1 ]

racc_goto_pointer = [
nil, 0 ]

racc_goto_default = [
nil, nil ]

racc_reduce_table = [
0, 0, :racc_error,
3, 9, :_reduce_1,
3, 9, :_reduce_2,
3, 9, :_reduce_3,
2, 9, :_reduce_4,
1, 9, :_reduce_5 ]

racc_reduce_n = 6

racc_shift_n = 14

racc_token_table = {
false => 0,
:error => 1,
"!" => 2,
"&" => 3,
"|" => 4,
"(" => 5,
")" => 6,
:NUMBER => 7 }

racc_nt_base = 8

racc_use_result_var = true

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",
"\"!\"",
"\"&\"",
"\"|\"",
"\"(\"",
"\")\"",
"NUMBER",
"$start",
"exp" ]

Racc_debug_parser = false

##### State transition tables end #####

# reduce 0 omitted

module_eval(<<'.,.,', 'boolexp.y', 23)
def _reduce_1(val, _values, result)
result &&= val[2]
result
end
.,.,

module_eval(<<'.,.,', 'boolexp.y', 24)
def _reduce_2(val, _values, result)
result ||= val[2]
result
end
.,.,

module_eval(<<'.,.,', 'boolexp.y', 25)
def _reduce_3(val, _values, result)
result = val[1]
result
end
.,.,

module_eval(<<'.,.,', 'boolexp.y', 26)
def _reduce_4(val, _values, result)
result = !@obj.contents.include?(val[1])
result
end
.,.,

module_eval(<<'.,.,', 'boolexp.y', 27)
def _reduce_5(val, _values, result)
result = @obj.contents.include?(val[0])
result
end
.,.,

def _reduce_none(val, _values, result)
val[0]
end

end # class BoolExpParser



#
# BoolExp testing
#
if $0 == __FILE__
class Obj
attr_accessor :contents
end

actor = Obj.new
actor.contents = [234]
str ="((!#245)&#234)"

begin
x = BoolExpParser.new(actor).parse(str)
pp str, actor.contents, x
actor.contents = [234,245]
x = BoolExpParser.new(actor).parse(str)
pp str, actor.contents, x
str ="((!#1)&#1)"
x = BoolExpParser.new(actor).parse(str)
pp str, actor.contents, x
str ="234|1"
x = BoolExpParser.new(actor).parse(str)
pp str, actor.contents, x
str ="xxxxxxxx"
x = BoolExpParser.new(actor).parse(str)
pp str, actor.contents, x

rescue Racc::ParseError, Exception
pp $!
exit
end
end