projects
/
fur
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Make stuctures and lists work
[fur]
/
tokenization.py
diff --git
a/tokenization.py
b/tokenization.py
index
f73ddf8
..
819a0de
100644
(file)
--- a/
tokenization.py
+++ b/
tokenization.py
@@
-5,12
+5,19
@@
import util
Token = collections.namedtuple(
'Token',
Token = collections.namedtuple(
'Token',
- [
+ (
'type',
'match',
'type',
'match',
+ 'metadata',
+ ),
+)
+
+NodeMetadata = collections.namedtuple(
+ 'NodeMetadata',
+ (
'index',
'line',
'index',
'line',
-
]
,
+
)
,
)
def _make_token_matcher(definition):
)
def _make_token_matcher(definition):
@@
-26,22
+33,34
@@
def _make_token_matcher(definition):
return (
True,
index + len(match.group()),
return (
True,
index + len(match.group()),
- Token(type=name, match=match.group(), index=index, line=line),
+ Token(
+ type=name,
+ match=match.group(),
+ metadata=NodeMetadata(
+ index=index,
+ line=line,
+ ),
+ ),
)
return token_matcher
_TOKEN_MATCHERS = [
)
return token_matcher
_TOKEN_MATCHERS = [
- ('keyword', r'(def|do|else|end|if)(?![a-z_])'),
+ ('keyword', r'(def|do|else|end|if|lambda)(?![a-z_])'),
+ ('open_bracket', r'\['),
+ ('close_bracket', r'\]'),
('open_parenthese', r'\('),
('close_parenthese', r'\)'),
('comma', r','),
('open_parenthese', r'\('),
('close_parenthese', r'\)'),
('comma', r','),
+ ('colon', r':'),
+ ('period', r'\.'),
('integer_literal', r'\d+'),
('symbol', r'[a-z_]+'),
('single_quoted_string_literal', r"'.*?'"),
('integer_literal', r'\d+'),
('symbol', r'[a-z_]+'),
('single_quoted_string_literal', r"'.*?'"),
- ('comparison_level_operator', r'(<=|>=|==|!=|<|>)'),
+ ('double_quoted_string_literal', r'".*?"'),
+ ('comparison_level_operator', r'(<=|>=|==|!=|<|>)'),
('assignment_operator', r'='),
('assignment_operator', r'='),
- ('addition_level_operator', r'(\+|-)'),
+ ('addition_level_operator', r'(\+
\+|\+
|-)'),
('multiplication_level_operator', r'(\*|//|%)'),
('newline', r'\n'),
]
('multiplication_level_operator', r'(\*|//|%)'),
('newline', r'\n'),
]