tidied up formatting I broke at ad79e142

This commit is contained in:
satyr
2010-10-26 04:57:20 +09:00
parent ad79e142ca
commit b2be475f93
6 changed files with 75 additions and 79 deletions

View File

@@ -237,10 +237,10 @@ grammar =
# The general group of accessors into an object, by property, by prototype
# or by array index or slice.
Accessor: [
o '. Identifier', -> new Accessor $2
o ':: Identifier', -> new Accessor $2, 'prototype'
o '. Identifier', -> new Accessor $2
o '?. Identifier', -> new Accessor $2, 'soak'
o ':: Identifier', -> new Accessor $2, 'proto'
o '::', -> new Accessor new Literal 'prototype'
o '?. Identifier', -> new Accessor $2, 'soak'
o 'Index'
]

View File

@@ -116,16 +116,11 @@ exports.Lexer = class Lexer
@identifierError id
unless forcedIdentifier
id = COFFEE_ALIASES[id] if COFFEE_ALIASES.hasOwnProperty id
tag = if id is '!'
'UNARY'
else if id in ['==', '!=']
'COMPARE'
else if id in ['&&', '||']
'LOGIC'
else if id in ['true', 'false', 'null']
'BOOL'
else
tag
tag = if id is '!' then 'UNARY'
else if id in ['==', '!='] then 'COMPARE'
else if id in ['&&', '||'] then 'LOGIC'
else if id in ['true', 'false', 'null'] then 'BOOL'
else tag
@token tag, id
@token ':', ':' if colon
input.length
@@ -534,16 +529,15 @@ IDENTIFIER = /// ^
///
NUMBER = /^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?/i
HEREDOC = /^("""|''')([\s\S]*?)(?:\n[ \t]*)?\1/
OPERATOR = /// ^
(?: [-=]> # function
| [-+*/%<>&|^!?=]= # compound assign / compare
| >>>=? # zero-fill right shift
| ([-+:])\1 # doubles
| ([&|<>])\2=? # logic / shift
| \?\. # soak access
| \.{3} # splat
)
///
OPERATOR = /// ^ (
?: [-=]> # function
| [-+*/%<>&|^!?=]= # compound assign / compare
| >>>=? # zero-fill right shift
| ([-+:])\1 # doubles
| ([&|<>])\2=? # logic / shift
| \?\. # soak access
| \.{3} # splat
) ///
WHITESPACE = /^[ \t]+/
COMMENT = /^###([^#][\s\S]*?)(?:###[ \t]*\n|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/
CODE = /^[-=]>/
@@ -575,14 +569,11 @@ ASSIGNED = /^\s*@?[$A-Za-z_][$\w]*[ \t]*?[:=][^:=>]/
LINE_CONTINUER = /// ^ \s* (?: , | \??\.(?!\.) | :: ) ///
LEADING_SPACES = /^\s+/
TRAILING_SPACES = /\s+$/
NO_NEWLINE = /// ^
(?: # non-capturing...
[-+*&|/%=<>!.\\][<>=&|]* | # symbol operators
and | or | is(?:nt)? | n(?:ot|ew) | # word operators
delete | typeof | instanceof
)$
///
NO_NEWLINE = /// ^ (?: # non-capturing group
[-+*&|/%=<>!.\\][<>=&|]* | # symbol operators
and | or | is(?:nt)? | n(?:ot|ew) | # word operators
delete | typeof | instanceof
) $ ///
# Compound assignment tokens.
COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|=']

View File

@@ -527,7 +527,7 @@ exports.Accessor = class Accessor extends Base
constructor: (@name, tag) ->
super()
@proto = if tag is 'prototype' then '.prototype' else ''
@proto = if tag is 'proto' then '.prototype' else ''
@soak = tag is 'soak'
compile: (o) ->
@@ -679,11 +679,11 @@ exports.Class = class Class extends Base
if @parent
applied = new Value @parent, [new Accessor new Literal 'apply']
constructor = new Code [], new Expressions [
ctor = new Code [], new Expressions [
new Call applied, [new Literal('this'), new Literal('arguments')]
]
else
constructor = new Code [], new Expressions [new Return new Literal 'this']
ctor = new Code [], new Expressions [new Return new Literal 'this']
for prop in @properties
{variable: pvar, value: func} = prop
@@ -699,33 +699,37 @@ exports.Class = class Class extends Base
func.body.push new Return new Literal 'this'
variable = new Value variable
variable.namespaced = 0 < className.indexOf '.'
constructor = func
constructor.comment = props.expressions.pop() if last(props.expressions) instanceof Comment
ctor = func
ctor.comment = props.expressions.pop() if last(props.expressions) instanceof Comment
continue
if func instanceof Code and func.bound
if prop.context is 'this'
func.context = className
else
func.bound = false
constScope or= new Scope o.scope, constructor.body, constructor
constScope or= new Scope o.scope, ctor.body, ctor
me or= constScope.freeVariable 'this'
pname = pvar.compile o
constructor.body.push new Return new Literal 'this' if constructor.body.isEmpty()
constructor.body.unshift new Literal "this.#{pname} = function(){ return #{className}.prototype.#{pname}.apply(#{me}, arguments); }"
ctor.body.push new Return new Literal 'this' if ctor.body.isEmpty()
ret = "return #{className}.prototype.#{pname}.apply(#{me}, arguments);"
ctor.body.unshift new Literal "this.#{pname} = function() { #{ret} }"
if pvar
access = if prop.context is 'this' then pvar.properties[0] else new Accessor(pvar, 'prototype')
val = new Value variable, [access]
prop = new Assign val, func
access = if prop.context is 'this'
pvar.properties[0]
else
new Accessor pvar, 'proto'
val = new Value variable, [access]
prop = new Assign val, func
props.push prop
constructor.className = className.match /[$\w]+$/
constructor.body.unshift new Literal "#{me} = this" if me
ctor.className = className.match /[$\w]+$/
ctor.body.unshift new Literal "#{me} = this" if me
o.sharedScope = constScope
construct = @tab + new Assign(variable, constructor).compile(o) + ';'
construct += '\n' + @tab + extension.compile(o) + ';' if extension
construct += '\n' + props.compile o if !props.isEmpty()
construct += '\n' + new Return(variable).compile o if @returns
construct
code = @tab + new Assign(variable, ctor).compile(o) + ';'
code += '\n' + @tab + extension.compile(o) + ';' if extension
code += '\n' + props.compile o if !props.isEmpty()
code += '\n' + new Return(variable).compile o if @returns
code
#### Assign