diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-08-22 15:15:07 -0400 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-08-22 15:15:07 -0400 |
commit | ee9a05d3c4fbdcb34777ae75a9ae1499b1098add (patch) | |
tree | 46a48f46c10497a4b35b647edc96334a0f703fa8 /src | |
parent | 56d36c9129292cd0dd0b5e79eea14d79a4219a94 (diff) |
Change arithmetic lexing
- Rename tokens from symbols ('+', '-'), to words
- Differentiate between symbols with and without surrounding whitespace
- Update parser to work with new token names
Diffstat (limited to 'src')
-rw-r--r-- | src/lexer.js | 5 | ||||
-rw-r--r-- | src/parser.js | 6 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/lexer.js b/src/lexer.js index fd0d0a3..5831541 100644 --- a/src/lexer.js +++ b/src/lexer.js @@ -20,8 +20,9 @@ const newSkippableLexeme = (type, regex) => { newValueLexeme('constant', '\\d+', Number) newLexemeType('d', 'd') -newLexemeType('+', '\\+') -newLexemeType('-', '-') +newLexemeType('bigPlus', ' \\+ ' ) +newLexemeType('bigMinus', ' - ') +newLexemeType('minus', '-') newLexemeType('(', '\\(') newLexemeType(')', '\\)') newLexemeType('E', 'E') diff --git a/src/parser.js b/src/parser.js index fd974bc..588f480 100644 --- a/src/parser.js +++ b/src/parser.js @@ -63,9 +63,9 @@ newSymbol('d', (parser) => { newDieOperation('E') newDieOperation('K') -newInfix('+', 20, { type: 'add' }) -newInfix('-', 20, { type: 'subtract' }) -newSymbol('-', (parser) => { +newInfix('bigPlus', 20, { type: 'add' }) +newInfix('bigMinus', 20, { type: 'subtract' }) +newSymbol('minus', (parser) => { return { type: 'negative', value: parser.expression(40) |