mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
got a lexer working along the lines of what kamatsu proposes
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user