mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
making assignment token detection a regex like all the others
This commit is contained in:
@@ -29,6 +29,7 @@ module CoffeeScript
|
|||||||
REGEX = /\A(\/(.*?)[^\\]\/[imgy]{0,4})/
|
REGEX = /\A(\/(.*?)[^\\]\/[imgy]{0,4})/
|
||||||
MULTI_DENT = /\A((\n([ \t]*)?)+)/
|
MULTI_DENT = /\A((\n([ \t]*)?)+)/
|
||||||
LAST_DENT = /\n([ \t]*)/
|
LAST_DENT = /\n([ \t]*)/
|
||||||
|
ASSIGNMENT = /\A(:|=)\Z/
|
||||||
|
|
||||||
# Token cleaning regexes.
|
# Token cleaning regexes.
|
||||||
JS_CLEANER = /(\A`|`\Z)/
|
JS_CLEANER = /(\A`|`\Z)/
|
||||||
@@ -36,9 +37,6 @@ module CoffeeScript
|
|||||||
COMMENT_CLEANER = /(^\s*#|\n\s*$)/
|
COMMENT_CLEANER = /(^\s*#|\n\s*$)/
|
||||||
NO_NEWLINE = /\A([+\*&|\/\-%=<>:!.\\][<>=&|]*|and|or|is|isnt|not|delete|typeof|instanceof)\Z/
|
NO_NEWLINE = /\A([+\*&|\/\-%=<>:!.\\][<>=&|]*|and|or|is|isnt|not|delete|typeof|instanceof)\Z/
|
||||||
|
|
||||||
# Assignment tokens.
|
|
||||||
ASSIGN = [':', '=']
|
|
||||||
|
|
||||||
# Scan by attempting to match tokens one character at a time. Slow and steady.
|
# Scan by attempting to match tokens one character at a time. Slow and steady.
|
||||||
def tokenize(code)
|
def tokenize(code)
|
||||||
@code = code.chomp # Cleanup code by remove extra line breaks
|
@code = code.chomp # Cleanup code by remove extra line breaks
|
||||||
@@ -174,7 +172,7 @@ module CoffeeScript
|
|||||||
value = @chunk[OPERATOR, 1]
|
value = @chunk[OPERATOR, 1]
|
||||||
tag_parameters if value && value.match(CODE)
|
tag_parameters if value && value.match(CODE)
|
||||||
value ||= @chunk[0,1]
|
value ||= @chunk[0,1]
|
||||||
tag = ASSIGN.include?(value) ? :ASSIGN : value
|
tag = value.match(ASSIGNMENT) ? :ASSIGN : value
|
||||||
token(tag, value)
|
token(tag, value)
|
||||||
@i += value.length
|
@i += value.length
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user