Exemplo n.º 1
0
    def _nonkey_extended():
        """parser for 'word (or word) (paren stuff)'.
        (or word) gives a synonym as a parenthetical within
        a word pattern.  Side effect is a new global synonym."""
        p = ((Pattern._nonkey() + c.paren(
            (next_word('or') + Pattern._nonkey()).treat(
                lib.snd).plus()).possibly()) +
             c.paren(Pattern._nonkey().plus()).many())

        def f(item):
            item1 = p.process(item)
            ((a, bs), cs) = item1.acc
            vals = [a.value] + [i.value for i in bs]
            c.synonym_add(vals)
            return c.update((a, cs), item1)

        return Parse(f)
Exemplo n.º 2
0
def atomic():
    #I forget why I am converting integers.
    """parser for atomic identifiers, converting words and integers as needed"""
    def f(item):
        item1 = Parse.next_token().process(item)
        result = item1.tok
        if result.type == 'INTEGER' or result.type == 'WORD':
            tok = copy.copy(result)
            if tok.type == 'WORD':
                tok.value = c.synonymize(tok.value)
            tok.type = 'ATOMIC_IDENTIFIER'
            return (tok, item1)
        if result.type == 'ATOMIC_IDENTIFIER':
            return result
        raise ParseError(item)

    return Parse(f).expect('atomic')