pyebnf/compiler.py
def _node_to_asn(self, node):
    """Convert a parse tree node into an absract syntax tree node."""
    if node.is_type(TokenType.identifier):
      return Identifier(node.svalue)

    elif node.is_type(TokenType.terminal):
      return Terminal(node.svalue)

    elif node.is_type(TokenType.option_group):
      expr = node.children[0]
      return OptionGroup(self._expression_to_asn(expr))

    elif node.is_type(TokenType.repetition_group):
      expr = node.children[0]
      return RepetitionGroup(self._expression_to_asn(expr))

    elif node.is_type(TokenType.grouping_group):
      expr = node.children[0]
      return GroupingGroup(self._expression_to_asn(expr))

    elif node.is_type(TokenType.special_handling):
      ident = node.children[0]
      return SpecialHandling(ident)

    elif node.is_type(TokenType.number):
      return Number(node.svalue)

    elif node.is_type((TokenType.operator, TokenType.op_mult, TokenType.op_add)):
      return OperatorNode(OPERATOR_INDEX[node.svalue], node.position)

    else:
      raise Exception("Unhandled parse tree node: {0}".format(node))
def _node_to_asn(self, node):
    if node.is_type(TokenType.identifier):
      return Identifier(node.svalue)

    elif node.is_type(TokenType.terminal):
      return Terminal(node.svalue)

    elif node.is_type(TokenType.option_group):
      expr = node.children[0]
      return OptionGroup(self._expression_to_asn(expr))

    elif node.is_type(TokenType.repetition_group):
      expr = node.children[0]
      return RepetitionGroup(self._expression_to_asn(expr))

    elif node.is_type(TokenType.grouping_group):
      expr = node.children[0]
      return GroupingGroup(self._expression_to_asn(expr))

    elif node.is_type(TokenType.special_handling):
      ident = node.children[0]
      return SpecialHandling(ident)

    elif node.is_type(TokenType.number):
      return Number(node.svalue)

    elif node.is_type((TokenType.operator, TokenType.op_mult, TokenType.op_add)):
      return OperatorNode(OPERATOR_INDEX[node.svalue], node.position)

    else:
      raise Exception("Unhandled parse tree node: {0}".format(node))
def _node_to_asn ( self , node ) : if node . is_type ( TokenType . identifier ) : return Identifier ( node . svalue ) elif node . is_type ( TokenType . terminal ) : return Terminal ( node . svalue ) elif node . is_type ( TokenType . option_group ) : expr = node . children [ 0 ] return OptionGroup ( self . _expression_to_asn ( expr ) ) elif node . is_type ( TokenType . repetition_group ) : expr = node . children [ 0 ] return RepetitionGroup ( self . _expression_to_asn ( expr ) ) elif node . is_type ( TokenType . grouping_group ) : expr = node . children [ 0 ] return GroupingGroup ( self . _expression_to_asn ( expr ) ) elif node . is_type ( TokenType . special_handling ) : ident = node . children [ 0 ] return SpecialHandling ( ident ) elif node . is_type ( TokenType . number ) : return Number ( node . svalue ) elif node . is_type ( ( TokenType . operator , TokenType . op_mult , TokenType . op_add ) ) : return OperatorNode ( OPERATOR_INDEX [ node . svalue ] , node . position ) else : raise Exception ( "Unhandled parse tree node: {0}" . format ( node ) )
Convert a parse tree node into an absract syntax tree node.
Convert a parse tree node into an absract syntax tree node .