Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/parser/DeclParser.cj
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,11 @@ internal open class DeclParser {
// the problem will be solved.
if (helper.matches(TKH.PREFIX_UNARY_OPERATOR)) {
let oper: Token = helper.previous()
if (oper.kind == TK.SUB && helper.matches(TK.INTEGER_LITERAL, TK.FLOAT_LITERAL)) {
let literal: Token = helper.previous()
return LitConstExpr(NodeIdManager.nextId(),
Token(literal.kind, "-" + literal.value, oper.pos))
}
let right: Expr = expectExpression(prefixUnaryExpression,
"Expected a postfixExpression after ${oper.value}, found '\u{001b}[31m${helper.peek().value}\u{001b}[0m'")
return UnaryExpr(NodeIdManager.nextId(), oper, right)
Expand Down
4 changes: 3 additions & 1 deletion src/test/Parser_test.cj
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class ParserTests {
func unaryExpr_test() {
let test: String = """
main(){
-134
-(134)
!134
}"""

Expand All @@ -278,9 +278,11 @@ class ParserTests {
let test: String = """
main(){
1231
-1231
"string"
()
1.2
-1.2
true
false
r'a'
Expand Down