m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-08-22 15:19:56 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-08-22 15:19:56 -0400
commit845ed56bb448e52a7f708504b91a6c5d492f228d (patch)
tree0026f5a04f20fc1be718faf1b863e67ad7b9d6f5 /src
parenta31c3a1fd44a37cf0fcfff8c1cc52792565247b3 (diff)
parent034d62f90d9c748f38209991c812692e5a99bbd9 (diff)
Merge branch 'addToken' into bonus
Diffstat (limited to 'src')
-rw-r--r--src/lexer.js10
-rw-r--r--src/parser.js6
2 files changed, 6 insertions, 10 deletions
diff --git a/src/lexer.js b/src/lexer.js
index fd0d0a3..8635e4a 100644
--- a/src/lexer.js
+++ b/src/lexer.js
@@ -14,19 +14,15 @@ const newValueLexeme = (type, regex, converter = v => v) => {
})
}
-const newSkippableLexeme = (type, regex) => {
- newLexemeType(type, regex, () => {})
-}
-
newValueLexeme('constant', '\\d+', Number)
newLexemeType('d', 'd')
-newLexemeType('+', '\\+')
-newLexemeType('-', '-')
+newLexemeType('bigPlus', ' \\+ ' )
+newLexemeType('bigMinus', ' - ')
+newLexemeType('minus', '-')
newLexemeType('(', '\\(')
newLexemeType(')', '\\)')
newLexemeType('E', 'E')
newLexemeType('K', 'K')
-newSkippableLexeme('whitespace', '\\s+')
const lex = (expressionString) => {
let lexemes = []
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)