From ab6a645347edfc7ae3391a3b41083014e1cb1fd1 Mon Sep 17 00:00:00 2001 From: satyr Date: Thu, 7 Jun 2012 16:25:37 +0900 Subject: [PATCH] fixes #138; brought postcrement to the attention of `*`, `/` and `!=` --- lib/lexer.js | 6 +++--- src/lexer.co | 8 +++++--- test/operator.co | 7 ++++++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/lexer.js b/lib/lexer.js index 10bf3fd97..06936daa1 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -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; } @@ -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; } @@ -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 '@@': diff --git a/src/lexer.co b/src/lexer.co index 87dce2c06..7dfb391b8 100644 --- a/src/lexer.co +++ b/src/lexer.co @@ -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 @@ -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 @@ -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 diff --git a/test/operator.co b/test/operator.co index 2ad4bcaac..ef94c1981 100644 --- a/test/operator.co +++ b/test/operator.co @@ -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--'