Class: Luaof::Lexer
- Inherits:
-
Object
- Object
- Luaof::Lexer
- Extended by:
- Forwardable
- Defined in:
- lib/luaof/lexer.rb
Instance Method Summary collapse
-
#initialize ⇒ Lexer
constructor
A new instance of Lexer.
- #push(line) {|:linebreak| ... } ⇒ Object
Constructor Details
#initialize ⇒ Lexer
Returns a new instance of Lexer.
8 9 10 |
# File 'lib/luaof/lexer.rb', line 8 def initialize @scanner = StringScanner.new(+'') end |
Instance Method Details
#push(line) {|:linebreak| ... } ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/luaof/lexer.rb', line 12 def push(line) if line.empty? yield :emptyline return end concat(line) until eos? if skip(/ @ (\w+) ({)? /x) if @scanner[2] yield({ tag: @scanner[1].intern }) else yield({ keyword: @scanner[1].intern }) end elsif skip('{') yield :leftbrace elsif skip('}') yield :closer elsif (text = scan(/ [|] \s* /x)) yield({ pipe: text }) elsif (text = scan(/ [^@{}|]+ /x)) yield text else raise ">>>#{rest}" end end yield :linebreak end |