commas remain mandatory for separating values. Will do spaces later
This commit is contained in:
parent
3651b7fe18
commit
d7ecddbad5
3 changed files with 7 additions and 12 deletions
12
README.md
12
README.md
|
|
@ -18,17 +18,15 @@ The repl has the following syntax (It's work in progress, new capabilities will
|
||||||
* and then ```@0```
|
* and then ```@0```
|
||||||
> > vector@0{x0:0, y0: 1, x:1, y:1}
|
> > vector@0{x0:0, y0: 1, x:1, y:1}
|
||||||
* method calls:
|
* 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@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.
|
```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.
|
* 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 vector. I'll have to think of another way to create an array of length 2...
|
* \[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
|
* properties
|
||||||
* ```a = vector(12, 1)```
|
* ```a = [1,2]```
|
||||||
* ```a.type```
|
* ```a.type```
|
||||||
> > vector
|
> > vector
|
||||||
* ```a.x+1```
|
* ```a.x+1```
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ export const parse = function (tokens) {
|
||||||
} else {
|
} else {
|
||||||
throw {message: "Expect ')' after arguments."};
|
throw {message: "Expect ')' after arguments."};
|
||||||
}
|
}
|
||||||
match([token_types.COMMA, token_types.SPACE]);
|
match([token_types.COMMA]);
|
||||||
} while (!match([token_types.RIGHT_PAREN]));
|
} while (!match([token_types.RIGHT_PAREN]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,7 +157,7 @@ export const parse = function (tokens) {
|
||||||
} else {
|
} else {
|
||||||
throw {message: "Expect ']' after array elements."};
|
throw {message: "Expect ']' after array elements."};
|
||||||
}
|
}
|
||||||
match([token_types.COMMA, token_types.SPACE]);
|
match([token_types.COMMA]);
|
||||||
} while (!match([token_types.RIGHT_BRACKET]));
|
} while (!match([token_types.RIGHT_BRACKET]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,6 @@ export const scan = function (command) {
|
||||||
return token_types.RIGHT_BRACKET;
|
return token_types.RIGHT_BRACKET;
|
||||||
case ',':
|
case ',':
|
||||||
return token_types.COMMA;
|
return token_types.COMMA;
|
||||||
case ' ':
|
|
||||||
return token_types.SPACE;
|
|
||||||
case '.':
|
case '.':
|
||||||
return token_types.DOT;
|
return token_types.DOT;
|
||||||
case '-':
|
case '-':
|
||||||
|
|
@ -194,7 +192,6 @@ export const token_types = {
|
||||||
LEFT_BRACKET: {type: 'left_bracket'},
|
LEFT_BRACKET: {type: 'left_bracket'},
|
||||||
RIGHT_BRACKET: {type: 'right_bracket'},
|
RIGHT_BRACKET: {type: 'right_bracket'},
|
||||||
COMMA: {type: 'comma'},
|
COMMA: {type: 'comma'},
|
||||||
SPACE: {type: 'space'},
|
|
||||||
DOT: {type: 'dot'},
|
DOT: {type: 'dot'},
|
||||||
MINUS: {type: 'minus'},
|
MINUS: {type: 'minus'},
|
||||||
PLUS: {type: 'plus'},
|
PLUS: {type: 'plus'},
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue