lib/import/shake_grammar/lexer.rb in tracksperanto-1.6.8 vs lib/import/shake_grammar/lexer.rb in tracksperanto-1.6.9

- old
+ new

@@ -13,12 +13,12 @@ # The first argument is the IO handle to the data of the Shake script. # The second argument is a "sentinel" that is going to be passed # to the downstream lexers instantiated for nested data structures. # You can use the sentinel to collect data from child nodes for example. - def initialize(with_io, sentinel = nil) - @io, @stack, @buf, @sentinel = with_io, [], '', sentinel + def initialize(with_io, sentinel = nil, limit_to_one_stmt = false) + @io, @stack, @buf, @sentinel, @limit_to_one_stmt = with_io, [], '', sentinel, @limit_to_one_stmt catch(STOP_TOKEN) { parse until @io.eof? } in_comment? ? consume_comment("\n") : consume_atom! end private @@ -42,52 +42,52 @@ if !@buf.empty? && (c == "(") # Funcall push([:funcall, @buf.strip] + self.class.new(@io, @sentinel).stack) @buf = '' elsif c == "[" # Array, booring - push([:arr] + self.class.new(@io).stack) - elsif (c == "]" || c == ")") - # Funcall end, and when it happens assume we are called as - # a subexpression. + push([:arr, self.class.new(@io).stack]) + elsif (c == "]" || c == ")" || c == ";" && @limit_to_one_stmt) + # Bailing out of a subexpression consume_atom! throw STOP_TOKEN elsif (c == ",") consume_atom! + elsif (c == "@") + consume_atom! + @buf << c elsif (c == ";" || c == "\n") # Skip these - the subexpression already is expanded anyway elsif (c == "=") - push [:var, @buf.strip] - push [:eq] + push [:assign, @buf.strip, self.class.new(@io, @sentinel, to_semicolon = true).stack.shift] @buf = '' else @buf << c end end INT_ATOM = /^(\d+)$/ FLOAT_ATOM = /^([\-\d\.]+)$/ STR_ATOM = /^\"/ - AT_ATOM = /^([\-\d\.]+)@([\-\d\.]+)$/ - AT_CONSUMED = /^@(\d+)/ - VAR_ASSIGN = /^([\w_]+)(\s+?)\=(\s+?)(.+)/ + AT_FRAME = /^@(\d+)/ # Grab the minimum atomic value def consume_atom! at, @buf = @buf.strip, '' return if at.empty? the_atom = case at when INT_ATOM - [:atom_i, at.to_i] + at.to_i when STR_ATOM - [:atom_c, unquote_s(at)] + unquote_s(at) when FLOAT_ATOM - [:atom_f, at.to_f] - when AT_ATOM - v, f = at.strip.split("@") - [[:atom_f, v.to_f], [:atom_at_i, f.to_i]] - when AT_CONSUMED - [:atom_at_i, $1.to_i] + at.to_f + when AT_FRAME + if $1.include?(".") + [:value_at, $1.to_f, @stack.pop] + else + [:value_at, $1.to_i, @stack.pop] + end else [:atom, at] end push(the_atom) \ No newline at end of file