m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-08-22 15:19:12 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-08-22 15:19:12 -0400
commitb84fe7672ad62a7e507b10704fbbd216afaaff44 (patch)
tree934b69b60432bc9ced9f8219c28f58b05d9ab1ed
parentee9a05d3c4fbdcb34777ae75a9ae1499b1098add (diff)
Stop ignoring whitespace
-rw-r--r--__tests__/lexer.test.js12
-rw-r--r--src/lexer.js5
2 files changed, 6 insertions, 11 deletions
diff --git a/__tests__/lexer.test.js b/__tests__/lexer.test.js
index 76cb421..12835df 100644
--- a/__tests__/lexer.test.js
+++ b/__tests__/lexer.test.js
@@ -10,24 +10,24 @@ describe('lex', () => {
})
it('throws on unexpected input at the end', () => {
- expect(() => { lex('1d6 `') }).toThrow(/Syntax error/)
+ expect(() => { lex('1d6`') }).toThrow(/Syntax error/)
})
it('throws on unexpected input in the middle', () => {
- expect(() => { lex('2d3 + b 3d4') }).toThrow(/Syntax error/)
+ expect(() => { lex('2d3 + b3d4') }).toThrow(/Syntax error/)
})
- describe('ignores whitespace', () => {
+ describe('throws on unexpected whitespace', () => {
it('2 d 4', () => {
- expect(lex('2 d 4')).not.toBe('error')
+ expect(() => { lex('2 d 4') }).toThrow(/Syntax error/)
})
it(' 1d8', () => {
- expect(lex(' 1d8')).not.toBe('error')
+ expect(() => { lex(' 1d8') }).toThrow(/Syntax error/)
})
it('3d4 ', () => {
- expect(lex('3d4 ')).not.toBe('error')
+ expect(() => { lex('3d4 ') }).toThrow(/Syntax error/)
})
})
diff --git a/src/lexer.js b/src/lexer.js
index 5831541..8635e4a 100644
--- a/src/lexer.js
+++ b/src/lexer.js
@@ -14,10 +14,6 @@ const newValueLexeme = (type, regex, converter = v => v) => {
})
}
-const newSkippableLexeme = (type, regex) => {
- newLexemeType(type, regex, () => {})
-}
-
newValueLexeme('constant', '\\d+', Number)
newLexemeType('d', 'd')
newLexemeType('bigPlus', ' \\+ ' )
@@ -27,7 +23,6 @@ newLexemeType('(', '\\(')
newLexemeType(')', '\\)')
newLexemeType('E', 'E')
newLexemeType('K', 'K')
-newSkippableLexeme('whitespace', '\\s+')
const lex = (expressionString) => {
let lexemes = []