From d7ecddbad52a34fe6440428172693d1ba25a0004 Mon Sep 17 00:00:00 2001 From: Sander Hautvast Date: Tue, 9 Mar 2021 15:31:20 +0100 Subject: [PATCH] commas remain mandatory for separating values. Will do spaces later --- README.md | 12 +++++------- src/js/parser.js | 4 ++-- src/js/scanner.js | 3 --- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index bb638bd..0ede108 100644 --- a/README.md +++ b/README.md @@ -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: \[i0 i1 i2 ... in] or \[i0, i1, i2, ... in] creates an array. - * \[i0 i1] 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: \[i0, i1, i2, ... in] creates an array. + * \[i0, i1] 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``` > > vector * ```a.x+1``` diff --git a/src/js/parser.js b/src/js/parser.js index efd8946..ffe6eb1 100644 --- a/src/js/parser.js +++ b/src/js/parser.js @@ -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])); } diff --git a/src/js/scanner.js b/src/js/scanner.js index d8f1b36..51055e7 100644 --- a/src/js/scanner.js +++ b/src/js/scanner.js @@ -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'},