Parse Boolean literals.

This commit is contained in:
Simon Forman 2021-04-06 11:34:46 -07:00
parent c00c6a4e32
commit 14c16d469f
1 changed files with 7 additions and 5 deletions

View File

@ -41,6 +41,7 @@ from .utils.stack import list_to_stack
#TODO: explain the details of float lits and strings. #TODO: explain the details of float lits and strings.
BOOL = 'true|false'
FLOAT = r'-?\d+\.\d*(e(-|\+)\d+)?' FLOAT = r'-?\d+\.\d*(e(-|\+)\d+)?'
INT = r'-?\d+' INT = r'-?\d+'
SYMBOL = r'[•\w!@$%^&*()_+<>?|\/;:`~,.=-]+' SYMBOL = r'[•\w!@$%^&*()_+<>?|\/;:`~,.=-]+'
@ -114,11 +115,12 @@ def _parse(tokens):
_scanner = Scanner([ _scanner = Scanner([
(FLOAT, lambda _, token: float(token)), ( BOOL, lambda _, token: token == 'true'),
(INT, lambda _, token: int(token)), ( FLOAT, lambda _, token: float(token)),
(SYMBOL, lambda _, token: Symbol(token)), ( INT, lambda _, token: int(token)),
(BRACKETS, lambda _, token: token), ( SYMBOL, lambda _, token: Symbol(token)),
( BRACKETS, lambda _, token: token),
(STRING_DOUBLE_QUOTED, lambda _, token: token[1:-1].replace('\\"', '"')), (STRING_DOUBLE_QUOTED, lambda _, token: token[1:-1].replace('\\"', '"')),
(STRING_SINGLE_QUOTED, lambda _, token: token[1:-1].replace("\\'", "'")), (STRING_SINGLE_QUOTED, lambda _, token: token[1:-1].replace("\\'", "'")),
(BLANKS, None), ( BLANKS, None),
]) ])