def __init__(self, name, description=None, kind=None, traits=None, children=None, element=None, element_name=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) self.description = description self.traits = traits or [] self.children = children or [] self.base_kind = kind if self.base_kind == 'SyntaxCollection': self.base_type = 'Syntax' else: self.base_type = kind_to_type(self.base_kind) if self.base_kind not in SYNTAX_BASE_KINDS: 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 "" # For SyntaxCollections make sure that the element_name is set. assert(not self.is_syntax_collection() or element_name or (element and element != 'Syntax')) # If there's a preferred name for the collection element that differs # from its supertype, use that. self.collection_element_name = element_name or self.collection_element self.collection_element_type = kind_to_type(self.collection_element) self.collection_element_choices = element_choices or []
def __init__(self, name, description=None, kind=None, traits=None, children=None, element=None, element_name=None, element_choices=None): self.syntax_kind = name self.swift_syntax_kind = lowercase_first_word(name) self.name = kind_to_type(self.syntax_kind) self.description = description self.traits = traits or [] self.children = children or [] self.base_kind = kind self.base_type = kind_to_type(self.base_kind) if self.base_kind not in SYNTAX_BASE_KINDS: error("unknown base kind '%s' for node '%s'" % (self.base_kind, self.syntax_kind)) self.collection_element = element or "" # If there's a preferred name for the collection element that differs # from its supertype, use that. self.collection_element_name = element_name or self.collection_element self.collection_element_type = kind_to_type(self.collection_element) self.collection_element_choices = element_choices or []
def __init__(self, name, kind, is_optional=False, token_choices=None, text_choices=None): self.name = name self.swift_name = lowercase_first_word(name) self.syntax_kind = kind self.swift_syntax_kind = lowercase_first_word(self.syntax_kind) self.type_name = kind_to_type(self.syntax_kind) # If the child has "token" anywhere in the kind, it's considered # a token node. Grab the existing reference to that token from the # global list. self.token_kind = \ self.syntax_kind if "Token" in self.syntax_kind else None self.token = SYNTAX_TOKEN_MAP.get(self.token_kind) self.is_optional = is_optional # A restricted set of token kinds that will be accepted for this # child. self.token_choices = [] if self.token: self.token_choices.append(self.token) for choice in token_choices or []: token = SYNTAX_TOKEN_MAP[choice] self.token_choices.append(token) # A list of valid text for tokens, if specified. # This will force validation logic to check the text passed into the # token against the choices. self.text_choices = text_choices or []
def __init__(self, name, kind=None, children=None, element=None, element_name=None): self.syntax_kind = name self.name = kind_to_type(self.syntax_kind) self.children = children or [] self.base_kind = kind self.base_type = kind_to_type(self.base_kind) if self.base_kind not in SYNTAX_BASE_KINDS: error("unknown base kind '%s' for node '%s'" % (self.base_kind, self.syntax_kind)) self.collection_element = element or "" # If there's a preferred name for the collection element that differs # from its supertype, use that. self.collection_element_name = element_name or self.collection_element self.collection_element_type = kind_to_type(self.collection_element)
def __init__(self, name, kind, description=None, is_optional=False, token_choices=None, text_choices=None, node_choices=None, collection_element_name=None, classification=None, force_classification=False): """ If a classification is passed, it specifies the color identifiers in that subtree should inherit for syntax coloring. Must be a member of SyntaxClassification in SyntaxClassifier.h.gyb If force_classification is also set to true, all child nodes (not only identifiers) inherit the syntax classification. """ self.name = name self.swift_name = lowercase_first_word(name) self.syntax_kind = kind self.description = description self.swift_syntax_kind = lowercase_first_word(self.syntax_kind) self.type_name = kind_to_type(self.syntax_kind) self.collection_element_name = collection_element_name self.classification = classification_by_name(classification) self.force_classification = force_classification # If the child has "token" anywhere in the kind, it's considered # a token node. Grab the existing reference to that token from the # global list. self.token_kind = \ self.syntax_kind if "Token" in self.syntax_kind else None self.token = SYNTAX_TOKEN_MAP.get(self.token_kind) self.is_optional = is_optional # A restricted set of token kinds that will be accepted for this # child. self.token_choices = [] if self.token: self.token_choices.append(self.token) for choice in token_choices or []: token = SYNTAX_TOKEN_MAP[choice] self.token_choices.append(token) # A list of valid text for tokens, if specified. # This will force validation logic to check the text passed into the # token against the choices. self.text_choices = text_choices or [] # A list of valid choices for a child self.node_choices = node_choices or [] # Check the choices are either empty or multiple assert len(self.node_choices) != 1 # Check node choices are well-formed for choice in self.node_choices: assert not choice.is_optional, \ "node choice %s cannot be optional" % choice.name assert not choice.node_choices, \ "node choice %s cannot have further choices" % choice.name
def __init__(self, name, kind=None, children=None, element=None, element_name=None): self.syntax_kind = name self.swift_syntax_kind = lowercase_first_word(name) self.name = kind_to_type(self.syntax_kind) self.children = children or [] self.base_kind = kind self.base_type = kind_to_type(self.base_kind) if self.base_kind not in SYNTAX_BASE_KINDS: error("unknown base kind '%s' for node '%s'" % (self.base_kind, self.syntax_kind)) self.collection_element = element or "" # If there's a preferred name for the collection element that differs # from its supertype, use that. self.collection_element_name = element_name or self.collection_element self.collection_element_type = kind_to_type(self.collection_element)
def __init__(self, name, kind, description=None, is_optional=False, token_choices=None, text_choices=None, node_choices=None): self.name = name self.swift_name = lowercase_first_word(name) self.syntax_kind = kind self.description = description self.swift_syntax_kind = lowercase_first_word(self.syntax_kind) self.type_name = kind_to_type(self.syntax_kind) # If the child has "token" anywhere in the kind, it's considered # a token node. Grab the existing reference to that token from the # global list. self.token_kind = \ self.syntax_kind if "Token" in self.syntax_kind else None self.token = SYNTAX_TOKEN_MAP.get(self.token_kind) self.is_optional = is_optional # A restricted set of token kinds that will be accepted for this # child. self.token_choices = [] if self.token: self.token_choices.append(self.token) for choice in token_choices or []: token = SYNTAX_TOKEN_MAP[choice] self.token_choices.append(token) # A list of valid text for tokens, if specified. # This will force validation logic to check the text passed into the # token against the choices. self.text_choices = text_choices or [] # A list of valid choices for a child self.node_choices = node_choices or [] # Check the choices are either empty or multiple assert len(self.node_choices) != 1 # Check node choices are well-formed for choice in self.node_choices: assert not choice.is_optional, \ "node choice %s cannot be optional" % choice.name assert not choice.node_choices, \ "node choice %s cannot have further choices" % choice.name