Exemplo n.º 1
0
def lit(s):
    """parser generator for 's'-like words or phrases"""
    if s in ['record', 'doc', 'location']:
        if s == 'record':
            return (Parse.word('we').possibly() +
                    first_word('record register') +
                    Parse.word('identification').possibly() +
                    Parse.word('that').possibly())
        if s == 'doc':
            return lit['document'] | lit['end-document']
        if s == 'location':
            return Parse.first(
                [lit_dict['document'], lit_dict['theorem'], lit_dict['axiom']])
    return lit_dict[s]
Exemplo n.º 2
0
    def _syn():
        """parsing synonyms"""
        def p(tok):
            tok.value in ['/', '/-'] or c.can_wordify(tok)

        synlist = Parse.next_token().if_test(p).plus()
        return c.comma_nonempty_list(synlist)
Exemplo n.º 3
0
    def by_method():
        def no_that(tok):
            return tok.value == 'that'  # exclude avoids goal_prefix ambig.

        return (
            next_word('by') +
            (first_phrase(['contradiction', 'case analysis']) |
             (next_word('induction') +
              (next_word('on') + c.balanced_condition(no_that)).possibly())) +
            Parse.probe(next_word('that') | period))
Exemplo n.º 4
0
 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)
Exemplo n.º 5
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.º 6
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')
Exemplo n.º 7
0
    def instruction():
        """parsing and processing of synonyms and other instructions"""
        def treat_syn(acc):
            for ac in acc:
                vs = [t.value for t in ac]
                v_expand = Instruction._expand_slashdash(vs)
                c.synonym_add(v_expand)
                return ()

        def treat_instruct(acc):
            keyword, ls = acc
            instruct[keyword.value] = Instruction._param_value(ls)
            return ()

        keyword_instruct = (first_word("""exit timelimit printgoal dump 
                         ontored read library error warning""") +
                            Parse.next_token().possibly())
        return (c.bracket(
            next_word('synonym') + Instruction._syn().treat(treat_syn)
            | c.bracket(keyword_instruct.treat(treat_instruct))))
Exemplo n.º 8
0
 def id():
     def f(acc):
         return (acc.type,acc.value)
     return Parse.next_token().if_types(['TY','ID']).treat(f)
Exemplo n.º 9
0
def var():
    """parser for a single variable.
    Accepts a single token that is a variable."""
    return Parse.next_token().if_type(['VAR']).expect('var')
Exemplo n.º 10
0
def phrase_list_filler():
    """parser for filler words"""
    return (Parse.word('we').possibly() +
            first_word('put write have know see') +
            Parse.word('that').possibly()).nil()
Exemplo n.º 11
0
def phrase_list_transition():
    """parser for transition phrases"""
    prs = [next_phrase(s) for s in word_lists.transition]
    return (Parse.first(prs) + next_word('that').possibly()).nil()
Exemplo n.º 12
0
 def this_directive_pred():
     return c.andcomma_nonempty_list(Parse.next_token().if_test(adjective))
Exemplo n.º 13
0
def hierarchical_identifier():
    """parser for hierarchical identifiers.
    Parser output is a single token."""
    return Parse.next_token().if_type(['HIERARCHICAL_IDENTIFIER'])
Exemplo n.º 14
0
def var_or_atomics():
    """parser for a sequence of one or more var or atomics"""
    return Parse.plus(var_or_atomic())