[incrParse] Fix parsing of nodes covering no source text

This commit is contained in:
Alex Hoppen
2018-05-08 13:13:46 -07:00
parent 9d3233c556
commit e1a99efd57
8 changed files with 43 additions and 5 deletions

View File

@@ -18,7 +18,7 @@ class Node(object):
def __init__(self, name, description=None, kind=None, traits=None,
children=None, element=None, element_name=None,
element_choices=None):
element_choices=None, omit_when_empty=False):
self.syntax_kind = name
self.swift_syntax_kind = lowercase_first_word(name)
self.name = kind_to_type(self.syntax_kind)
@@ -36,6 +36,7 @@ class Node(object):
error("unknown base kind '%s' for node '%s'" %
(self.base_kind, self.syntax_kind))
self.omit_when_empty = omit_when_empty
self.collection_element = element or ""
# If there's a preferred name for the collection element that differs
# from its supertype, use that.
@@ -74,3 +75,10 @@ class Node(object):
return not self.is_base() and \
not self.is_unknown() and \
not self.is_syntax_collection()
def shall_be_omitted_when_empty(self):
"""
Returns 'True' if this node shall not be created while parsing if it
has no children.
"""
return self.omit_when_empty