Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
a5ef6415
Commit
a5ef6415
authored
Jul 08, 2017
by
Eckhart Arnold
Browse files
- full memoization ready; some optimizations
parent
1b34aa1d
Changes
1
Hide whitespace changes
Inline
Side-by-side
DHParser/syntaxtree.py
View file @
a5ef6415
...
...
@@ -153,8 +153,9 @@ ZOMBIE_PARSER = ZombieParser()
# msg: str
Error
=
NamedTuple
(
'Error'
,
[(
'pos'
,
int
),
(
'msg'
,
str
)])
StrictResultType
=
Union
[
Tuple
[
'Node'
,
...],
str
]
ResultType
=
Union
[
Tuple
[
'Node'
,
...],
'Node'
,
str
,
None
]
ChildrenType
=
Tuple
[
'Node'
,
...]
StrictResultType
=
Union
[
ChildrenType
,
str
]
ResultType
=
Union
[
ChildrenType
,
'Node'
,
str
,
None
]
class
Node
:
...
...
@@ -204,7 +205,7 @@ class Node:
"""
self
.
_result
=
''
# type: StrictResultType
self
.
_errors
=
[]
# type: List[str]
self
.
_children
=
()
# type:
Tuple['Node', ...]
self
.
_children
=
()
# type:
ChildrenType
self
.
result
=
result
self
.
_len
=
len
(
self
.
result
)
if
not
self
.
children
else
\
sum
(
child
.
_len
for
child
in
self
.
children
)
# type: int
...
...
@@ -254,11 +255,11 @@ class Node:
# or isinstance(result, Node)
# or isinstance(result, str)), str(result)
self
.
_result
=
(
result
,)
if
isinstance
(
result
,
Node
)
else
result
or
''
self
.
_children
=
cast
(
Tuple
[
'Node'
,
...]
,
self
.
_result
)
\
if
isinstance
(
self
.
_result
,
tuple
)
else
cast
(
Tuple
[
'Node'
,
...]
,
())
self
.
_children
=
cast
(
ChildrenType
,
self
.
_result
)
\
if
isinstance
(
self
.
_result
,
tuple
)
else
cast
(
ChildrenType
,
())
@
property
def
children
(
self
)
->
Tuple
[
'Node'
,
...]
:
def
children
(
self
)
->
ChildrenType
:
return
self
.
_children
@
property
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment