added yes, no, on and off as boolean aliases and a nice aliases section to the docs

This commit is contained in:
Jeremy Ashkenas
2009-12-23 20:24:55 -05:00
parent a4d014549b
commit 64879cdc66
10 changed files with 95 additions and 63 deletions

View File

@@ -211,13 +211,13 @@
</dict>
<dict>
<key>match</key>
<string>\btrue\b</string>
<string>\b(true|on|yes)\b</string>
<key>name</key>
<string>constant.language.boolean.true.cs</string>
</dict>
<dict>
<key>match</key>
<string>\bfalse\b</string>
<string>\b(false|off|no)\b</string>
<key>name</key>
<string>constant.language.boolean.false.cs</string>
</dict>

View File

@@ -3,7 +3,7 @@ class Parser
# Declare tokens produced by the lexer
token IF ELSE THEN UNLESS
token NUMBER STRING REGEX
token TRUE FALSE NULL
token TRUE FALSE YES NO ON OFF
token IDENTIFIER PROPERTY_ACCESS
token CODE PARAM NEW RETURN
token TRY CATCH FINALLY THROW
@@ -102,11 +102,14 @@ rule
| STRING { result = LiteralNode.new(val[0]) }
| JS { result = LiteralNode.new(val[0]) }
| REGEX { result = LiteralNode.new(val[0]) }
| TRUE { result = LiteralNode.new(true) }
| FALSE { result = LiteralNode.new(false) }
| NULL { result = LiteralNode.new(nil) }
| BREAK { result = LiteralNode.new(val[0]) }
| CONTINUE { result = LiteralNode.new(val[0]) }
| TRUE { result = LiteralNode.new(true) }
| FALSE { result = LiteralNode.new(false) }
| YES { result = LiteralNode.new(true) }
| NO { result = LiteralNode.new(false) }
| ON { result = LiteralNode.new(true) }
| OFF { result = LiteralNode.new(false) }
;
# Assignment to a variable.

View File

@@ -7,7 +7,7 @@ module CoffeeScript
# The list of keywords passed verbatim to the parser.
KEYWORDS = ["if", "else", "then", "unless",
"true", "false", "null",
"true", "false", "yes", "no", "on", "off",
"and", "or", "is", "aint", "not",
"new", "return",
"try", "catch", "finally", "throw",
@@ -21,7 +21,7 @@ module CoffeeScript
IDENTIFIER = /\A([a-zA-Z$_]\w*)/
NUMBER = /\A\b((0(x|X)[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?(e[+\-]?[0-9]+)?))\b/i
STRING = /\A(""|''|"(.*?)[^\\]"|'(.*?)[^\\]')/m
JS = /\A(`(.*?)`)/
JS = /\A(``|`(.*?)[^\\]`)/m
OPERATOR = /\A([+\*&|\/\-%=<>:]+)/
WHITESPACE = /\A([ \t\r]+)/
NEWLINE = /\A(\n+)/

View File

@@ -601,7 +601,7 @@ module CoffeeScript
@body = body && body.unwrap
@else_body = else_body && else_body.unwrap
@tags = tags
@condition = OpNode.new("!", @condition) if @tags[:invert]
@condition = OpNode.new("!", ParentheticalNode.new(@condition)) if @tags[:invert]
end
def <<(else_body)
@@ -656,7 +656,7 @@ module CoffeeScript
def compile_statement(o)
indent = o[:indent]
o[:indent] += TAB
if_part = "if (#{@condition.compile(o.merge(:no_paren => true))}) {\n#{Expressions.wrap(@body).compile(o)}\n#{indent}}"
if_part = "if (#{@condition.compile(o)}) {\n#{Expressions.wrap(@body).compile(o)}\n#{indent}}"
return if_part unless @else_body
else_part = chain? ?
" else #{@else_body.compile(o.merge(:indent => indent))}" :