Skip to content

Commit

Permalink
fixes #138; brought postcrement to the attention of *, / and !=
Browse files Browse the repository at this point in the history
  • Loading branch information
satyr committed Jun 7, 2012
1 parent 8949a6b commit ab6a645
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ exports.doJS = function(code, lastIndex){
};
exports.doRegex = function(code, index){
var divisable, input, body, flag, __ref;
if (divisable = able(this.tokens)) {
if (divisable = able(this.tokens) || this.last[0] === 'CREMENT') {
if (!this.last.spaced || ((__ref = code.charAt(index + 1)) === ' ' || __ref === '=')) {
return 0;
}
Expand Down Expand Up @@ -526,7 +526,7 @@ exports.doLiteral = function(code, index){
}
break;
case '!=':
if (!able(this.tokens)) {
if (!(able(this.tokens) || this.last[0] === 'CREMENT')) {
this.tokens.push(['UNARY', '!', this.line], ['ASSIGN', '=', this.line]);
return 2;
}
Expand Down Expand Up @@ -614,7 +614,7 @@ exports.doLiteral = function(code, index){
this.indent(index + that - 1 - this.dent - code.lastIndexOf('\n', index - 1));
return that;
}
tag = able(this.tokens) ? 'MATH' : 'STRNUM';
tag = able(this.tokens) || this.last[0] === 'CREMENT' && able(this.tokens, this.tokens.length - 1) ? 'MATH' : 'STRNUM';
break;
case '@':
case '@@':
Expand Down
8 changes: 5 additions & 3 deletions src/lexer.co
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ exports import
# f /re/ 9 /ex/ # f(/re/, 9, /ex/)
# a /= b / c / d # division
#
if divisable = able @tokens
if divisable = able @tokens or @last.0 is \CREMENT
return 0 if not @last.spaced or code.charAt(index+1) of [' ' \=]
[input, body, flag] = (REGEX <<< lastIndex: index)exec code
if input
Expand Down Expand Up @@ -356,7 +356,7 @@ exports import
case \, \[ \( \CALL( then @token \LITERAL \void
case \FOR \OWN then @token \ID ''
case \!=
unless able @tokens
unless able @tokens or @last.0 is \CREMENT
@tokens.push [\UNARY \! @line] [\ASSIGN \= @line]
return 2
fallthrough
Expand Down Expand Up @@ -398,7 +398,9 @@ exports import
@tokens.push [\LITERAL \void @line] [\ASSIGN \= @line]
@indent index + that - 1 - @dent - code.lastIndexOf \\n index-1
return that
tag = if able @tokens then \MATH else \STRNUM
tag = if able @tokens
or @last.0 is \CREMENT and able @tokens, @tokens.length-1
then \MATH else \STRNUM
case \@ \@@
@dotcat val or if val is \@
then @token \LITERAL \this true
Expand Down
7 changes: 6 additions & 1 deletion test/operator.co
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,12 @@ eq 1 a.0

# ACI applies on postcrement.
eq a.0 ++ -- a.0
eq 1 i
eq 1 a.0

# Infix after postcrement.
eq a.0++ * 2, 2
eq a.0-- / 2, 1
ok a.0++ != 2

throws 'increment of undeclared variable "C" on line 1' -> Coco.compile 'C++'
throws 'invalid decrement on line 1' -> Coco.compile 'q.=p--'
Expand Down

0 comments on commit ab6a645

Please sign in to comment.