Class: EsiAttributeLanguage::SimpleGrammarParser
- Inherits:
-
Racc::Parser
- Object
- Racc::Parser
- EsiAttributeLanguage::SimpleGrammarParser
- Defined in:
- lib/esi_attribute_language/grammar/simple.y.rb,
lib/esi_attribute_language/grammar/simple.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", "LPAREN", "RPAREN", "STRING", "VARIABLE", "OTHER", "PIPE", "LBRACE", "RBRACE", "QUOTE", "$start", "expression", "variable" ]
- Racc_debug_parser =
false
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#lineno ⇒ Object
readonly
Returns the value of attribute lineno.
Instance Method Summary collapse
- #_reduce_none(val, _values, result) ⇒ Object
- #action(&block) ⇒ Object
- #load_file(filename) ⇒ Object
- #next_token ⇒ Object
- #scan_evaluate(str) ⇒ Object
- #scan_file(filename) ⇒ Object
- #scan_setup ⇒ Object
- #scan_str(str) ⇒ Object
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
14 15 16 |
# File 'lib/esi_attribute_language/grammar/simple.rex.rb', line 14 def filename @filename end |
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno.
13 14 15 |
# File 'lib/esi_attribute_language/grammar/simple.rex.rb', line 13 def lineno @lineno end |
Instance Method Details
#_reduce_none(val, _values, result) ⇒ Object
162 163 164 |
# File 'lib/esi_attribute_language/grammar/simple.y.rb', line 162 def _reduce_none(val, _values, result) val[0] end |
#action(&block) ⇒ Object
18 19 20 |
# File 'lib/esi_attribute_language/grammar/simple.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/simple.rex.rb', line 27 def load_file( filename ) @filename = filename open(filename, "r") do |f| scan_evaluate f.read end end |
#next_token ⇒ Object
39 40 41 |
# File 'lib/esi_attribute_language/grammar/simple.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 |
# File 'lib/esi_attribute_language/grammar/simple.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 { [:LBRACE, text] } when (text = ss.scan(/\}/)) @rex_tokens.push action { [:RBRACE, 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 { [:LPAREN, text] } when (text = ss.scan(/\)/)) @rex_tokens.push action { [:RPAREN, text] } when (text = ss.scan(/[0-9]+/)) @rex_tokens.push action { [:NUMBER, text] } when (text = ss.scan(/'(\\'|[^'])*'/)) @rex_tokens.push action { [:OTHER, text] } when (text = ss.scan(/(\\\|\\\$|\\\[|\\\]|\\\)|[^\|\(\)\$\{\}]{1})*/)) @rex_tokens.push action { [:OTHER, text] } 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/simple.rex.rb', line 34 def scan_file( filename ) load_file filename do_parse end |
#scan_setup ⇒ Object
16 |
# File 'lib/esi_attribute_language/grammar/simple.rex.rb', line 16 def scan_setup ; end |
#scan_str(str) ⇒ Object
22 23 24 25 |
# File 'lib/esi_attribute_language/grammar/simple.rex.rb', line 22 def scan_str( str ) scan_evaluate str do_parse end |