Skip to content

Commit 96add38

Browse files
Parse negative numbers
1 parent 4ec14f8 commit 96add38

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

examples/scripts/forEach.mcscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#file: ./foreach
22
# basic loop
3-
forEach(var i = 0; i < 10; i++){
3+
forEach(var i = -5; i < 5; i++){
44
/say hey
55
}
66

lib/parser.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,13 @@ function parse_atom() {
695695
return tok;
696696

697697
}
698+
if (tok.type == "op" && tok.value == "-") {
699+
let num = input.next()
700+
if(num.type != "num") {
701+
unexpected()
702+
}
703+
tok = { type: "num", value: -num.value }
704+
}
698705
if (tok.type == "num" || tok.type == "str") return tok;
699706

700707
unexpected();

0 commit comments

Comments
 (0)