From 5fdeefdfc4273a8e57e760aae234b1411da8788c Mon Sep 17 00:00:00 2001 From: Tommy Yu Date: Sat, 5 May 2018 17:39:38 +1200 Subject: [PATCH] Add the LET keyword to lexer. --- src/calmjs/parse/lexers/es2015.py | 10 +++++++++- src/calmjs/parse/tests/lexer.py | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/calmjs/parse/lexers/es2015.py b/src/calmjs/parse/lexers/es2015.py index 1d4182f..9debce4 100644 --- a/src/calmjs/parse/lexers/es2015.py +++ b/src/calmjs/parse/lexers/es2015.py @@ -20,6 +20,11 @@ ) +es2015_keywords = ( + 'LET', +) + + class Lexer(ES5Lexer): """ ES2015 lexer. @@ -32,7 +37,10 @@ class Lexer(ES5Lexer): t_ARROW = r'=>' t_SPREAD = r'\.\.\.' - tokens = ES5Lexer.tokens + ( + keywords = ES5Lexer.keywords + es2015_keywords + keywords_dict = dict((key.lower(), key) for key in keywords) + + tokens = ES5Lexer.tokens + es2015_keywords + ( # ES2015 punctuators 'ARROW', 'SPREAD', # => ... diff --git a/src/calmjs/parse/tests/lexer.py b/src/calmjs/parse/tests/lexer.py index 79efe8b..e7c52ae 100644 --- a/src/calmjs/parse/tests/lexer.py +++ b/src/calmjs/parse/tests/lexer.py @@ -463,6 +463,10 @@ 'const_keyword', ('const c', ['CONST const', 'ID c']), + ), ( + 'let_keyword', + ('let c', + ['LET let', 'ID c']), ), ( 'punctuators', ('=> ...',