Class: EsiAttributeLanguage::GrammarParser

Inherits:
Racc::Parser
  • Object
show all
Defined in:
lib/esi_attribute_language/grammar/grammar.y.rb,
lib/esi_attribute_language/grammar/grammar.rex.rb

Defined Under Namespace

Classes: ScanError

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",
"DOLLAR",
"LSQUARE",
"RSQUARE",
"LPAREN",
"RPAREN",
"LBRACE",
"RBRACE",
"BSLASH",
"PIPE",
"PLUS",
"NUMBER",
"MINUS",
"STAR",
"SLASH",
"VARIABLE",
"STRING",
"EQ",
"NE",
"LTE",
"GTE",
"LT",
"GT",
"BANG",
"AMP",
"$start",
"expression",
"variable",
"hash_lookup" ]
Racc_debug_parser =
false

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



14
15
16
# File 'lib/esi_attribute_language/grammar/grammar.rex.rb', line 14

def filename
  @filename
end

#linenoObject (readonly)

Returns the value of attribute lineno.



13
14
15
# File 'lib/esi_attribute_language/grammar/grammar.rex.rb', line 13

def lineno
  @lineno
end

Instance Method Details

#_reduce_none(val, _values, result) ⇒ Object



393
394
395
# File 'lib/esi_attribute_language/grammar/grammar.y.rb', line 393

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

#action(&block) ⇒ Object



18
19
20
# File 'lib/esi_attribute_language/grammar/grammar.rex.rb', line 18

def action &block
  yield
end

#load_file(filename) ⇒ Object



27
28
29
30
31
32
# File 'lib/esi_attribute_language/grammar/grammar.rex.rb', line 27

def load_file( filename )
  @filename = filename
  open(filename, "r") do |f|
    scan_evaluate  f.read
  end
end

#next_tokenObject



39
40
41
# File 'lib/esi_attribute_language/grammar/grammar.rex.rb', line 39

def next_token
  @rex_tokens.shift
end

#scan_evaluate(str) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/esi_attribute_language/grammar/grammar.rex.rb', line 43

def scan_evaluate( str )
  scan_setup
  @rex_tokens = []
  @lineno  =  1
  ss = StringScanner.new(str)
  state = nil
  until ss.eos?
    text = ss.peek(1)
    @lineno  +=  1  if text == "\n"
    case state
    when nil
      case
      when (text = ss.scan(/'(\\'|[^'])*'/))
         @rex_tokens.push action { [:STRING,   text] }

      when (text = ss.scan(/==/))
         @rex_tokens.push action { [:EQ,       text] }

      when (text = ss.scan(/!=/))
         @rex_tokens.push action { [:NE,       text] }

      when (text = ss.scan(/<=/))
         @rex_tokens.push action { [:LTE,      text] }

      when (text = ss.scan(/>=/))
         @rex_tokens.push action { [:GTE,      text] }

      when (text = ss.scan(/</))
         @rex_tokens.push action { [:LT,       text] }

      when (text = ss.scan(/>/))
         @rex_tokens.push action { [:GT,       text] }

      when (text = ss.scan(/\$/))
         @rex_tokens.push action { [:DOLLAR,   text] }

      when (text = ss.scan(/\|/))
         @rex_tokens.push action { [:PIPE,     text] }

      when (text = ss.scan(/\[/))
         @rex_tokens.push action { [:LSQUARE,  text] }

      when (text = ss.scan(/\]/))
         @rex_tokens.push action { [:RSQUARE,  text] }

      when (text = ss.scan(/\{/))
         @rex_tokens.push action { [:LBRACE,   text] }

      when (text = ss.scan(/\}/))
         @rex_tokens.push action { [:RBRACE,   text] }

      when (text = ss.scan(/\(/))
         @rex_tokens.push action { [:LPAREN,   text] }

      when (text = ss.scan(/\)/))
         @rex_tokens.push action { [:RPAREN,   text] }

      when (text = ss.scan(/\\/))
         @rex_tokens.push action { [:BSLASH,   text] }

      when (text = ss.scan(/\+/))
         @rex_tokens.push action { [:PLUS,     text] }

      when (text = ss.scan(/\*/))
         @rex_tokens.push action { [:STAR,     text] }

      when (text = ss.scan(/\//))
         @rex_tokens.push action { [:SLASH,    text] }

      when (text = ss.scan(/\'/))
         @rex_tokens.push action { [:QUOTE,    text] }

      when (text = ss.scan(/\?/))
         @rex_tokens.push action { [:QMARK,    text] }

      when (text = ss.scan(/\./))
         @rex_tokens.push action { [:DOT,      text] }

      when (text = ss.scan(/\^/))
         @rex_tokens.push action { [:CARROT,   text] }

      when (text = ss.scan(/\-/))
         @rex_tokens.push action { [:MINUS,    text] }

      when (text = ss.scan(/&/))
         @rex_tokens.push action { [:AMP,      text] }

      when (text = ss.scan(/!/))
         @rex_tokens.push action { [:BANG,     text] }

      when (text = ss.scan(/[0-9]+/))
         @rex_tokens.push action { [:NUMBER,   text] }

      when (text = ss.scan(/[A-Za-z_-]+/))
         @rex_tokens.push action { [:VARIABLE, text] }

      when (text = ss.scan(/./))
        ;

      else
        text = ss.string[ss.pos .. -1]
        raise  ScanError, "can not match: '" + text + "'"
      end  # if

    else
      raise  ScanError, "undefined state: '" + state.to_s + "'"
    end  # case state
  end  # until ss
end

#scan_file(filename) ⇒ Object



34
35
36
37
# File 'lib/esi_attribute_language/grammar/grammar.rex.rb', line 34

def scan_file( filename )
  load_file  filename
  do_parse
end

#scan_setupObject



16
# File 'lib/esi_attribute_language/grammar/grammar.rex.rb', line 16

def scan_setup ; end

#scan_str(str) ⇒ Object



22
23
24
25
# File 'lib/esi_attribute_language/grammar/grammar.rex.rb', line 22

def scan_str( str )
  scan_evaluate  str
  do_parse
end