passing through comments as tags on Values, but not printing them out quite yet...

This commit is contained in:
Jeremy Ashkenas
2009-12-22 10:48:58 -05:00
parent 9b8f018646
commit d45643c527
5 changed files with 24 additions and 17 deletions

View File

@@ -32,6 +32,7 @@ module CoffeeScript
# Token cleaning regexes.
JS_CLEANER = /(\A`|`\Z)/
MULTILINER = /[\r\n]/
COMMENT_CLEANER = /^\s*#\s*/
# Tokens that always constitute the start of an expression.
EXP_START = ['{', '(', '[']
@@ -111,6 +112,8 @@ module CoffeeScript
# Matches and consumes comments.
def remove_comment
return false unless comment = @chunk[COMMENT, 1]
cleaned = comment.gsub(COMMENT_CLEANER, '')
@prev_comment ? @prev_comment << cleaned : @prev_comment = [cleaned]
@i += comment.length
end
@@ -139,10 +142,12 @@ module CoffeeScript
@i += value.length
end
# Add a token to the results, taking note of the line number for syntax
# errors later in the parse.
# Add a token to the results, taking note of the line number, and
# immediately-preceding comment.
def token(tag, value)
@tokens << [tag, Value.new(value, @line)]
comment = @prev_comment
@prev_comment = nil
@tokens << [tag, Value.new(value, @line, comment)]
end
# Peek at the previous token.