got a lexer working along the lines of what kamatsu proposes

This commit is contained in:
Jeremy Ashkenas
2009-12-26 10:59:47 -08:00
parent 556f8cb68a
commit 191875a85b

View File

@@ -132,17 +132,24 @@ module CoffeeScript
return literal_token if size == @indent return literal_token if size == @indent
if size > @indent if size > @indent
token(:INDENT, size - @indent) token(:INDENT, size - @indent)
@indents << size - @indent
@indent = size @indent = size
@indents << @indent
else else
token(:OUTDENT, @indent - size) outdent_token(@indent - size)
@indents.pop while @indents.last && ((@indents.last || 0) > size)
@indent = @indents.last || 0
end end
@line += 1 @line += 1
@i += (size + 1) @i += (size + 1)
end end
def outdent_token(move_out)
while move_out > 0
last_indent = @indents.pop
token(:OUTDENT, last_indent)
move_out -= last_indent
end
@indent = @indents.last || 0
end
# Matches and consumes non-meaningful whitespace. # Matches and consumes non-meaningful whitespace.
def whitespace_token def whitespace_token
return false unless whitespace = @chunk[WHITESPACE, 1] return false unless whitespace = @chunk[WHITESPACE, 1]
@@ -214,9 +221,7 @@ module CoffeeScript
# Close up all remaining open blocks. # Close up all remaining open blocks.
def close_indentation def close_indentation
while indent = @indents.pop outdent_token(@indent)
token(:OUTDENT, @indents.first || 0)
end
end end
end end