commas remain mandatory for separating values. Will do spaces later

This commit is contained in:
Sander Hautvast 2021-03-09 15:31:20 +01:00
parent 3651b7fe18
commit d7ecddbad5
3 changed files with 7 additions and 12 deletions

View file

@ -18,17 +18,15 @@ The repl has the following syntax (It's work in progress, new capabilities will
* and then ```@0```
> > vector@0{x0:0, y0: 1, x:1, y:1}
* method calls:
```a = vector(12, 1)```
```a = vector(12, 1)``` works as well. The start is now the origin.
> > vector@0{x0:0, y0: 2, x:12, y:1}
* ```vector(1 2)``` works as well. The start is now the origin.
commas are not mandatory.
* This means spaces are meaningful.
```vector(-1 -1)``` != ```vector(-1-1)``` and the latter would mean ```vector(-2)``` which is not legal.
* arrays: \[i<sub>0</sub> i<sub>1</sub> i<sub>2</sub> ... i<sub>n</sub>] or \[i<sub>0</sub>, i<sub>1</sub>, i<sub>2</sub>, ... i<sub>n</sub>] creates an array.
* \[i<sub>0</sub> i<sub>1</sub>] is special: it is a shorthand for creating a vector. I'll have to think of another way to create an array of length 2...
* arrays: \[i<sub>0</sub>, i<sub>1</sub>, i<sub>2</sub>, ... i<sub>n</sub>] creates an array.
* \[i<sub>0</sub>, i<sub>1</sub>] is special: it is a shorthand for creating a 2-dimensional vector. I'll have to think of another way to create an array of length 2...
* properties
* ```a = vector(12, 1)```
* ```a = [1,2]```
* ```a.type```
> &gt; vector
* ```a.x+1```

View file

@ -103,7 +103,7 @@ export const parse = function (tokens) {
} else {
throw {message: "Expect ')' after arguments."};
}
match([token_types.COMMA, token_types.SPACE]);
match([token_types.COMMA]);
} while (!match([token_types.RIGHT_PAREN]));
}
@ -157,7 +157,7 @@ export const parse = function (tokens) {
} else {
throw {message: "Expect ']' after array elements."};
}
match([token_types.COMMA, token_types.SPACE]);
match([token_types.COMMA]);
} while (!match([token_types.RIGHT_BRACKET]));
}

View file

@ -31,8 +31,6 @@ export const scan = function (command) {
return token_types.RIGHT_BRACKET;
case ',':
return token_types.COMMA;
case ' ':
return token_types.SPACE;
case '.':
return token_types.DOT;
case '-':
@ -194,7 +192,6 @@ export const token_types = {
LEFT_BRACKET: {type: 'left_bracket'},
RIGHT_BRACKET: {type: 'right_bracket'},
COMMA: {type: 'comma'},
SPACE: {type: 'space'},
DOT: {type: 'dot'},
MINUS: {type: 'minus'},
PLUS: {type: 'plus'},