Skip to content

Commit

Permalink
fixed n&-n
Browse files Browse the repository at this point in the history
  • Loading branch information
satyr committed Oct 21, 2012
1 parent ca361c6 commit 8327a08
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
15 changes: 9 additions & 6 deletions lib/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1160,17 +1160,15 @@ function addImplicitParentheses(tokens){
}
tag = token[0];
prev = tokens[i - 1];
if (tag === '[') {
brackets.push(prev[0] === 'DOT');
}
tag === '[' && brackets.push(prev[0] === 'DOT');
if (prev[0] === ']') {
if (brackets.pop()) {
prev.index = true;
} else {
continue;
}
}
if (tag === 'BITWISE' && token[1] === '&' && !of$(tokens[i + 1][0], ARG)) {
if (tag === 'BITWISE' && token[1] === '&' && !exp(tokens[i + 1])) {
tag = token[0] = 'LITERAL';
}
if (!(((ref$ = prev[0]) === 'FUNCTION' || ref$ === 'LET') || prev.spaced && able(tokens, i, true))) {
Expand All @@ -1181,18 +1179,23 @@ function addImplicitParentheses(tokens){
tpair[0] = ')CALL';
continue;
}
if (!(of$(tag, ARG) || !token.spaced && (tag === '+-' || tag === '^'))) {
if (!exp(token)) {
continue;
}
if (tag === 'CREMENT') {
if (token.spaced || !of$((ref$ = tokens[i + 1]) != null ? ref$[0] : void 8, CHAIN)) {
if (token.spaced || !of$(tokens[i + 1][0], CHAIN)) {
continue;
}
}
skipBlock = seenSwitch = false;
tokens.splice(i++, 0, ['CALL(', '', token[2]]);
detectEnd(tokens, i, ok, go);
}
function exp(token){
var tag;
tag = token[0];
return of$(tag, ARG) || !token.spaced && (tag === '+-' || tag === '^');
}
function ok(token, i){
var tag, ref$, pre;
tag = token[0];
Expand Down
11 changes: 7 additions & 4 deletions src/lexer.co
Original file line number Diff line number Diff line change
Expand Up @@ -796,23 +796,26 @@ character = if JSON!? then uxxxx else ->
token.doblock = true
tokens.splice i, 1
[tag] = token; prev = tokens[i-1]
brackets.push prev.0 is \DOT if tag is \[
tag is \[ and brackets.push prev.0 is \DOT
if prev.0 is \]
if brackets.pop! then prev.index = true else continue
if tag is \BITWISE and token.1 is \& and tokens[i+1]0 not of ARG
if tag is \BITWISE and token.1 is \& and not exp tokens[i+1]
tag = token.0 = \LITERAL
continue unless prev.0 of <[ FUNCTION LET ]>
or prev.spaced and able tokens, i, true
if token.doblock
token.0 = \CALL(
tpair.0 = \)CALL
continue
continue unless tag of ARG or not token.spaced and tag of <[ +- ^ ]>
continue unless exp token
if tag is \CREMENT
continue if token.spaced or tokens[i+1]?0 not of CHAIN
continue if token.spaced or tokens[i+1]0 not of CHAIN
skipBlock = seenSwitch = false
tokens.splice i++, 0 [\CALL( '' token.2]
detectEnd tokens, i, ok, go
# Does the token start an expression?
function exp [tag]:token
tag of ARG or not token.spaced and tag of <[ +- ^ ]>
function ok token, i
tag = token.0
return true if tag of <[ |> POST_IF ]>
Expand Down
2 changes: 2 additions & 0 deletions test/operator.co
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ n = 1
eq 1, n&n
eq 1, n& n
eq 1, n & n
eq 1, n&-n
eq 1, n & -n

compileThrows 'stray reference' 2 '\n&'

Expand Down

0 comments on commit 8327a08

Please sign in to comment.