documentation waypoint

This commit is contained in:
Jeremy Ashkenas
2009-12-21 11:41:45 -05:00
parent dcc70e5ab0
commit c7fa9c320a
42 changed files with 1026 additions and 53 deletions

View File

@@ -229,7 +229,7 @@
</dict>
<dict>
<key>match</key>
<string>\b(super|this)\b</string>
<string>\b(super|this|extends)\b</string>
<key>name</key>
<string>variable.language.cs</string>
</dict>

View File

@@ -10,7 +10,7 @@ token TRY CATCH FINALLY THROW
token BREAK CONTINUE
token FOR IN WHILE
token SWITCH CASE
token SUPER
token EXTENDS SUPER
token DELETE
token NEWLINE
token JS
@@ -28,8 +28,8 @@ prechigh
right '-=' '+=' '/=' '*=' '||=' '&&='
right DELETE
left "."
right THROW FOR IN WHILE
left UNLESS IF ELSE
right THROW FOR IN WHILE NEW
left UNLESS IF ELSE EXTENDS
left ":"
right RETURN
preclow
@@ -68,6 +68,7 @@ rule
| Call
| Code
| Operation
| Extend
;
# We have to take extra care to convert these statements into expressions.
@@ -246,6 +247,11 @@ rule
SUPER "(" ArgList ")" { result = CallNode.new(:super, val[2]) }
;
# Extending a class.
Extend:
IDENTIFIER EXTENDS Expression { result = ExtendNode.new(val[0], val[2]) }
;
# The array literal.
Array:
"[" ArgList "]" { result = ArrayNode.new(val[1]) }

View File

@@ -14,7 +14,7 @@ module CoffeeScript
"break", "continue",
"for", "in", "while",
"switch", "case",
"super",
"extends", "super",
"delete"]
# Token matching regexes.

View File

@@ -110,6 +110,10 @@ module CoffeeScript
STATEMENTS.include?(@value.to_s)
end
def line_ending
@value.to_s[-1..-1] == ';' ? '' : ';'
end
def compile(indent, scope, opts={})
code = @value.to_s
write(code)
@@ -171,6 +175,20 @@ module CoffeeScript
end
end
class ExtendNode < Node
attr_reader :subclass, :superclass
def initialize(subclass, superclass)
@subclass, @superclass = subclass, superclass
end
def compile(indent, scope, opts={})
"#{@subclass}.prototype = #{@superclass.compile(indent, scope, opts)}"
end
end
# A value, indexed or dotted into, or vanilla.
class ValueNode < Node
attr_reader :literal, :properties, :last
@@ -269,7 +287,7 @@ module CoffeeScript
def compile(indent, scope, opts={})
name = @variable.respond_to?(:compile) ? @variable.compile(indent, scope) : @variable
last = @variable.respond_to?(:last) ? @variable.last : name
last = @variable.respond_to?(:last) ? @variable.last.to_s : name.to_s
opts = opts.merge({:assign => name, :last_assign => last})
return write("#{@variable}: #{@value.compile(indent, scope, opts)}") if @context == :object
return write("#{name} = #{@value.compile(indent, scope, opts)}") if @variable.properties?