Example #1
0
def convert_optional(node, additions):
    
    if node.has_type('Optional'):
        name = AST2.string("_optional_gen%d" % len(additions))
        e = AST2.Instance(('Alt'), 
                     left=AST2.Instance(('Reference'), name=AST2.string('EMPTY')),
                     right=deepcopy(node.expr.the)
                     )
        
        additions.append(AST2.Instance(('Production'), name=name, expr=e))
        node = AST2.Instance(('Reference'), name=name)
    return node
Example #2
0
def str_to_tok(node, tokens):
    
    if node.has_type("Literal"):
        name = tokens.get_name(node.text.the.lexrep)
        node = AST2.Instance(("Reference"), name=AST2.string(name))
    
    return node
Example #3
0
def node(type, **kwargs):
    n = AST2.Instance(RIFNS+type)
    for (k,v) in kwargs.items():
        if v is None:
            continue
        if isinstance(v, basestring):
            v = AST2.string(v)
        setattr(n, RIFNS+k, v)
    return n
Example #4
0
def node(type, **kwargs):
    debug('blindfold', 'new node', type)
    n = AST2.Instance(NS+type)
    for (k,v) in kwargs.items():
        debug('blindfold', '...', k, '=', v)
        if v is None:
            continue
        if isinstance(v, basestring):
            v = AST2.string(v)
        debug('blindfold', '... setattr', n, NS+k, v)
        setattr(n, NS+k, v)
    return n
Example #5
0
def parse(input_text):

   parts = input_text.split('\n%%\n')
   if len(parts) == 1:
       lex_extra = ""
       yacc_extra = ""
   elif len(parts) == 3:
       (input_text, lex_extra, yacc_extra) = parts
   else:
       raise RuntimeError, "unexpected number of %% parts: %d"%len(parts)

   try:
      result = parser.parse(input_text, debug=1, lexer=mylex.lexer)
      # strictly speaking, neither of these is part of the resulting
      # abstract document, but we do want to keep them and pass them 
      # along, for user happiness (ie nice qnames).
      ####result._base = parser.my_base
      ####result._prefix_map = parser.prefix_map
      result.lex_extra = AST2.string(lex_extra)
      result.yacc_extra = AST2.string(yacc_extra)
      return result
   except error.ParserError, e:
      e.input_text = input_text
      raise e
Example #6
0
def convert_plus(node, additions):
    
    if node.has_type('Plus'):
        name = AST2.string("_plus_gen%d" % len(additions))
        e = AST2.Instance(('Alt'), 
                     left=deepcopy(node.expr.the),
                     right=AST2.Instance(('Seq'),
                                    left=AST2.Instance(('Reference'),
                                                  name=name),
                                    right=deepcopy(node.expr.the)
                                    )
                     )
        
        additions.append(AST2.Instance(('Production'), name=name, expr=e))
        node = AST2.Instance(('Reference'), name=name)
    return node
Example #7
0
def p_IRICONST_1(t):
   '''IRICONST       : ANGLEBRACKIRI
                     | EXPANDED_CURIE'''
   #t[0] = node('Const', datatype=RIF_IRI, lexrep=t[1])
   t[0] = AST2.obtainDataValue(datatype=RIFNS+"iri", lexrep=t[1])
Example #8
0
def p_IRICONST_2(t):
   '''IRICONST       : STRING_HAT_HAT SYMSPACE'''
   #t[0] = node('Const', datatype=iri(t[2]), lexrep=t[1])
   t[0] = AST2.obtainDataValue(datatype=t[2], lexrep=t[1])
Example #9
0
def p_CONSTSHORT_5(t):
   '''CONSTSHORT    : LOCALNAME'''
   # t[0] = node('Const', datatype=iri(RIFNS+"local"), lexrep=t[1])
   t[0] = AST2.obtainDataValue(datatype=RIFNS+"local", lexrep=t[1])
Example #10
0
def p_CONSTSHORT_3(t):
   '''CONSTSHORT    : DECIMAL'''
   #t[0] = node('Const', datatype=iri(XSDNS+"decimal"), lexrep=t[1])
   t[0] = AST2.obtainDataValue(datatype=XSDNS+"decimal", lexrep=t[1])
Example #11
0
def p_CONSTSHORT_2(t):
   '''CONSTSHORT    : INTEGER'''
   #t[0] = node('Const', datatype=iri(XSDNS+"integer"), lexrep=t[1])
   t[0] = AST2.obtainDataValue(datatype=XSDNS+"integer", lexrep=t[1])
Example #12
0
def p_CONSTSHORT_1(t):
   '''CONSTSHORT    : STRING'''
   #t[0] = node('Const', datatype=iri(XSDNS+"string"), lexrep=t[1])
   t[0] = AST2.obtainDataValue(datatype=XSDNS+"string", lexrep=t[1])
Example #13
0
def p_Const_2(t):
   '''Const          : STRING_HAT_HAT SYMSPACE '''
   #t[0] = node('Const', lexrep=t[1], datatype=iri(t[2]))
   t[0] = AST2.obtainDataValue(lexrep=t[1], datatype=t[2])