Class: WMLAction::Parser
- Inherits:
-
Racc::Parser
- Object
- Racc::Parser
- WMLAction::Parser
- Defined in:
- lib/wml_action/lexer.rex.rb,
lib/wml_action/parser.tab.rb
Defined Under Namespace
Classes: ScanError
Constant Summary collapse
- OTAG =
/\[(\w+)\]/- CTAG =
/\[\/(\w+)\]/- ATTR =
/(\w+)=/- MACRO =
/\{.+\}/- ANUMBER =
/-?\d+(\.\d+)?/- ASTR =
/"[^"]*"/- APLAIN =
/.+/- SLASH =
/\//- COMMENT =
/\#.*$/- BACKQ =
/\`/- VAR =
/[\w]+/- BLANK =
/[ \t]+/- 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", "EUMIN", "\"*\"", "\"/\"", "\"+\"", "\"-\"", "\".\"", "OTAG", "CTAG", "MACRO", "BACKQ", "EPLUS", "EMINUS", "EMUL", "EDIV", "EDOT", "ENUMBER", "\"(\"", "\")\"", "ESTR", "ENUM", "EVAR", "ATTR", "APLAIN", "AMACRO", "ANUMBER", "ASTR", "UNDERSC", "APLUS", "SLASH", "$start", "target", "wml_doc", "tag", "contents", "content", "action", "attribute", "filter", "expression", "expr", "aop", "string_val" ]
- Racc_debug_parser =
false
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#lineno ⇒ Object
Returns the value of attribute lineno.
-
#ss ⇒ Object
(also: #match)
Returns the value of attribute ss.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #_reduce_none(val, _values, result) ⇒ Object
- #action ⇒ Object
- #matches ⇒ Object
- #next_token ⇒ Object
- #parse(str) ⇒ Object
- #parse_file(path) ⇒ Object
- #scanner_class ⇒ Object
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
31 32 33 |
# File 'lib/wml_action/lexer.rex.rb', line 31 def filename @filename end |
#lineno ⇒ Object
Returns the value of attribute lineno.
30 31 32 |
# File 'lib/wml_action/lexer.rex.rb', line 30 def lineno @lineno end |
#ss ⇒ Object Also known as: match
Returns the value of attribute ss.
32 33 34 |
# File 'lib/wml_action/lexer.rex.rb', line 32 def ss @ss end |
#state ⇒ Object
Returns the value of attribute state.
33 34 35 |
# File 'lib/wml_action/lexer.rex.rb', line 33 def state @state end |
Instance Method Details
#_reduce_none(val, _values, result) ⇒ Object
463 464 465 |
# File 'lib/wml_action/parser.tab.rb', line 463 def _reduce_none(val, _values, result) val[0] end |
#action ⇒ Object
43 44 45 |
# File 'lib/wml_action/lexer.rex.rb', line 43 def action yield end |
#matches ⇒ Object
37 38 39 40 41 |
# File 'lib/wml_action/lexer.rex.rb', line 37 def matches m = (1..9).map { |i| ss[i] } m.pop until m[-1] or m.empty? m end |
#next_token ⇒ Object
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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/wml_action/lexer.rex.rb', line 66 def next_token token = nil until ss.eos? or token do token = case state when nil then case when text = ss.scan(/#{COMMENT}/) then # do nothing when text = ss.scan(/#{OTAG}/) then action { [:OTAG, match[1]] } when text = ss.scan(/#{CTAG}/) then action { [:CTAG, match[1]] } when text = ss.scan(/#{ATTR}/) then action { @state = :INATTR; [:ATTR, match[1]] } when text = ss.scan(/#{MACRO}/) then action { [:MACRO, text] } when text = ss.scan(/#{SLASH}/) then action { [:SLASH, text] } when text = ss.scan(/\-/) then action { [text,text] } when text = ss.scan(/\+/) then action { [text,text] } when text = ss.scan(/./) then # do nothing when text = ss.scan(/\n/) then # do nothing else text = ss.string[ss.pos .. -1] raise ScanError, "can not match (#{state.inspect}): '#{text}'" end when :INATTR then case when text = ss.scan(/\n/) then action { @state = nil } when text = ss.scan(/#{BLANK}/) then # do nothing when text = ss.scan(/#{ANUMBER}\s+/) then action { @state = nil; [:ANUMBER, text.to_i] } when text = ss.scan(/#{ASTR}/) then action { [:ASTR, text] } when text = ss.scan(/#{MACRO}/) then action { [:AMACRO, text] } when text = ss.scan(/_/) then action { [:UNDERSC, text] } when text = ss.scan(/\+/) then action { [:APLUS, text] } when text = ss.scan(/#{BACKQ}/) then action { @state = :INEXPR; [:BACKQ, text] } when text = ss.scan(/#{APLAIN}/) then action { [:APLAIN, text] } else text = ss.string[ss.pos .. -1] raise ScanError, "can not match (#{state.inspect}): '#{text}'" end when :INEXPR then case when text = ss.scan(/#{BACKQ}/) then action { @state = nil; [:BACKQ, text] } when text = ss.scan(/\+/) then action { [:EPLUS,text] } when text = ss.scan(/\*/) then action { [:EMUL,text] } when text = ss.scan(/\//) then action { [:EDIV,text] } when text = ss.scan(/\-/) then action { [:EMINUS,text] } when text = ss.scan(/\./) then action { [:EDOT,text] } when text = ss.scan(/\(/) then action { [text,text] } when text = ss.scan(/\)/) then action { [text,text] } when text = ss.scan(/#{ANUMBER}/) then action { [:ENUM,text.to_f] } when text = ss.scan(/#{ASTR}/) then action { [:ESTR,text.slice(1..-2)] } when text = ss.scan(/#{VAR}/) then action { [:EVAR,text] } else text = ss.string[ss.pos .. -1] raise ScanError, "can not match (#{state.inspect}): '#{text}'" end else raise ScanError, "undefined state: '#{state}'" end # token = case state next unless token # allow functions to trigger redo w/ nil end # while raise "bad lexical result: #{token.inspect}" unless token.nil? || (Array === token && token.size >= 2) # auto-switch state self.state = token.last if token && token.first == :state token end |
#parse(str) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/wml_action/lexer.rex.rb', line 51 def parse str self.ss = scanner_class.new str self.lineno = 1 self.state ||= nil do_parse end |
#parse_file(path) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/wml_action/lexer.rex.rb', line 59 def parse_file path self.filename = path open path do |f| parse f.read end end |
#scanner_class ⇒ Object
47 48 49 |
# File 'lib/wml_action/lexer.rex.rb', line 47 def scanner_class StringScanner end |