Exemplo n.º 1
0
def preproof():
    while True:
        yield (proof_kwd() << shift_eq >> (
            lambda pk: choice([
                use(suppress()) << shift_eq >> (lambda supp: choice([
                    intf.locate(kwd('BY')) << times2 >> only() << times2 >>
                    use(usebody()) << times >> read_method() << apply >>
                    (lambda args: tla_ast.PreBy(supp, args[0][0][1], args[0][
                        1], args[1])),
                    intf.locate(
                        kwd('OBVIOUS') << second >> read_method() << apply >>
                        (lambda meth: tla_ast.PreObvious(supp, meth)))
                ])),

                # locate (kwd "OMITTED" <!> (PreOmitted Explicit)) ;
                intf.locate(
                    kwd('OMITTED') << bang >> tla_ast.PreOmitted(tla_ast.
                                                                 Explicit())),

                #  locate begin
                #           preno <**> use prestep
                #           <$> (fun (pn, stp) ->
                #                   PreStep (pk, pn, stp))
                #         end ;
                intf.locate(preno() << times2 >> use(prestep()) << apply >>
                            (lambda pn_stp: tla_ast.PreStep(
                                pk, pn_stp[0], pn_stp[1])))
            ])))
Exemplo n.º 2
0
 def f():
     # RULE: ('AXIOM' | 'ASSUME' | 'ASSUMPTION')
     #       [anyident '=='] expr [read_method]
     return (
         (kwd('AXIOM') << or_ >> kwd('ASSUME') << or_ >>
          kwd('ASSUMPTION')) << second_commit >> optional(
              intf.locate(intf.anyident() << first >> punct('==') <<
                          times2 >> use(ep.expr(False)))) << times >>
         optional(use(pfp.read_method())) << apply >> apply_axiom)
Exemplo n.º 3
0
 def f():
     return (
         (kwd('THEOREM') << or_ >> kwd('PROPOSITION') << or_ >>
          kwd('COROLLARY') << or_ >> kwd('LEMMA')) << second_commit >>
         optional(intf.locate(intf.anyident() << first >> punct('==')))
         << times >> choice([
             use(ep.sequent(False)),
             use(ep.expr(False)) << apply >>
             (lambda e: nodes.Sequent(list(), e))
         ]) << times >> optional(use(pfp.method_prs_read_method())) <<
         times >> use(pfp.proof()) << apply >> apply_theorem_proof)
Exemplo n.º 4
0
def parse_():
    def apply_module(nm_exs_mus):
        (name, extends), modunits = nm_exs_mus
        extends = list() if extends is None else extends
        return nodes.Module(name=name,
                            extendees=extends,
                            instancees=list(),
                            body=[i for j in modunits for i in j])

    while True:
        yield (intf.punct('----') << second_commit >> intf.kwd('MODULE') <<
               second_commit >> intf.locate(intf.anyname()) << first >>
               intf.punct('----') << times >> optional(
                   intf.kwd('EXTENDS') << second >> sep1(
                       intf.punct(','), intf.locate(intf.anyident()))) <<
               times2 >> use(modunits()) << first >> intf.punct('====') <<
               apply >> apply_module)
Exemplo n.º 5
0
        def f():
            return choice([
                # ['CONSTANT' | 'CONSTANTS'] opdecl (',' opdecl)*
                kwd('CONSTANT') << or_ >> kwd('CONSTANTS') << second_commit >>
                sep1(punct(','), use(ep.opdecl())) << apply >>
                (lambda cs: [nodes.Constants(cs)]),

                # 'RECURSIVE' opdecl (',' opdecl)*
                kwd('RECURSIVE') << second_commit >> sep1(
                    punct(','), use(ep.opdecl())) << apply >>
                (lambda cs: [nodes.Recursives(cs)]),

                # ['VARIABLE' | 'VARIABLES'] anyident (',' anyident)*
                kwd('VARIABLE') << or_ >> kwd('VARIABLES') << second_commit >>
                sep1(punct(','), locate(intf.anyident())) << apply >>
                (lambda vs: [nodes.Variables(vs)])
            ])
Exemplo n.º 6
0
def usebody():
    #     let defs =
    #       (kwd "DEF" <|> kwd "DEFS")
    #       >*> sep1 (punct ",") (use definable)
    defns = ((kwd('DEF') << or_ >> kwd('DEFS')) << second_commit >> sep1(
        punct(','), use(definable())))

    #     in
    #     sep (punct ",") (use (expr false)) >>= function
    #       | [] ->
    #           defs <$> (fun ds -> { facts = [] ; defs = ds })
    #       | fs ->
    #           optional defs <$> begin function
    #             | None -> {
    #                   facts = List.map filter_usebody_fact fs ;
    #                   defs = [] }
    #             | Some ds -> {
    #                   facts = List.map filter_usebody_fact fs ;
    #                   defs = ds }
    #           end
    def apply_usebody(fs, ds):
        if ds is None:
            return dict(facts=[filter_usebody_fact(f) for f in fs],
                        defs=list())
        else:
            return dict(facts=[filter_usebody_fact(f) for f in fs], defs=ds)

    def shift_usebody(fs):
        if fs:
            return (optional(defns) << apply >> functools.partial(
                apply_usebody, fs))
        else:
            return defns << apply >> (lambda ds: dict(facts=list(), defs=ds))

    while True:
        yield sep(punct(','), use(ep.expr(False))) << shift_eq >> shift_usebody
Exemplo n.º 7
0
 def f():
     return (use(pfp.suppress()) << times >>
             (kwd('USE') << or_ >> kwd('HIDE')) << times2 >>
             pfp.usebody() << apply >> apply_use_hide)
Exemplo n.º 8
0
    def choices():
        #   choice [
        #     choice [
        #       (kwd "CONSTANT" <|> kwd "CONSTANTS") >*>
        #         sep1 (punct ",") (use opdecl)
        #       <$> (fun cs -> [ Constants cs ]) ;
        #
        #       (kwd "RECURSIVE") >*>
        #         sep1 (punct ",") (use opdecl)
        #       <$> (fun cs -> [ Recursives cs ]) ;
        #
        #       (kwd "VARIABLE" <|> kwd "VARIABLES") >*>
        #         sep1 (punct ",") (locate anyident)
        #       <$> (fun vs -> [ Variables vs ]) ;
        #     ] ;
        # variable and constant declarations, and recursive operators
        def f():
            return choice([
                # ['CONSTANT' | 'CONSTANTS'] opdecl (',' opdecl)*
                kwd('CONSTANT') << or_ >> kwd('CONSTANTS') << second_commit >>
                sep1(punct(','), use(ep.opdecl())) << apply >>
                (lambda cs: [nodes.Constants(cs)]),

                # 'RECURSIVE' opdecl (',' opdecl)*
                kwd('RECURSIVE') << second_commit >> sep1(
                    punct(','), use(ep.opdecl())) << apply >>
                (lambda cs: [nodes.Recursives(cs)]),

                # ['VARIABLE' | 'VARIABLES'] anyident (',' anyident)*
                kwd('VARIABLE') << or_ >> kwd('VARIABLES') << second_commit >>
                sep1(punct(','), locate(intf.anyident())) << apply >>
                (lambda vs: [nodes.Variables(vs)])
            ])

        yield ((tokens.KWD, ), f)

        #     optional (kwd "LOCAL") >>= begin fun l ->
        #       let ex = if Option.is_some l then Local else Export in
        #         choice [
        #           use (instance false)
        #           <$> (fun inst -> [ Anoninst (inst, ex) ]) ;
        #
        #           use (defn false)
        #           <$> (fun df -> [ Definition (df, User, Hidden, ex) ]) ;
        #         ]
        #     end ;
        yield optional(kwd('LOCAL')) << shift_eq >> apply_def

        #     use Proof.Parser.suppress
        #     <*> (kwd "USE" <|> kwd "HIDE")
        #     <**> use Proof.Parser.usebody
        #     <$> (fun ((supp, uh), use) -> match uh with
        #            | "USE" -> [ Mutate (`Use (supp = Proof.Parser.Suppress), use) ]
        #            | _ -> [ Mutate (`Hide, use) ]) ;
        def f():
            return (use(pfp.suppress()) << times >>
                    (kwd('USE') << or_ >> kwd('HIDE')) << times2 >>
                    pfp.usebody() << apply >> apply_use_hide)

        yield ((
            tokens.KWD('USE'),
            tokens.KWD('HIDE'),
            tokens.PUNCT('_'),
            tokens.ID('suppress'),
        ), f)

        #     (kwd "AXIOM" <|> kwd "ASSUME" <|> kwd "ASSUMPTION") >*>
        #       optional (locate anyident <<< punct "==") <**> use (expr false)
        #     <*> optional (use Method_prs.read_method)
        #     <$> (fun ((nm, e), meth) -> [ Axiom (nm, with_meth e meth) ]) ;
        def f():
            # RULE: ('AXIOM' | 'ASSUME' | 'ASSUMPTION')
            #       [anyident '=='] expr [read_method]
            return (
                (kwd('AXIOM') << or_ >> kwd('ASSUME') << or_ >>
                 kwd('ASSUMPTION')) << second_commit >> optional(
                     intf.locate(intf.anyident() << first >> punct('==') <<
                                 times2 >> use(ep.expr(False)))) << times >>
                optional(use(pfp.read_method())) << apply >> apply_axiom)

        yield ((
            tokens.KWD('AXIOM'),
            tokens.KWD('ASSUME'),
            tokens.KWD('ASSUMPTION'),
        ), f)

        #     (kwd "THEOREM" <|> kwd "PROPOSITION" <|>
        #      kwd "COROLLARY" <|> kwd "LEMMA") >*>
        #       optional (locate anyident <<< punct "==")
        #     <*> choice [ use (sequent false) ;
        #                  use (expr false)
        #                  <$> (fun e -> { context = Deque.empty ; active = e }) ]
        #     <*> optional (use Method_prs.read_method)
        #     <*> use Proof.Parser.proof
        #     <$> (fun (((nm, bod), meth), prf) ->
        #            [ Theorem (nm, {
        #                   bod with active = with_meth bod.active meth },
        #               0, prf, prf, empty_summary) ]) ;
        def f():
            return (
                (kwd('THEOREM') << or_ >> kwd('PROPOSITION') << or_ >>
                 kwd('COROLLARY') << or_ >> kwd('LEMMA')) << second_commit >>
                optional(intf.locate(intf.anyident() << first >> punct('==')))
                << times >> choice([
                    use(ep.sequent(False)),
                    use(ep.expr(False)) << apply >>
                    (lambda e: nodes.Sequent(list(), e))
                ]) << times >> optional(use(pfp.method_prs_read_method())) <<
                times >> use(pfp.proof()) << apply >> apply_theorem_proof)

        yield ((
            tokens.KWD('THEOREM'),
            tokens.KWD('PROPOSITION'),
            tokens.KWD('COROLLARY'),
            tokens.KWD('LEMMA'),
        ), f)
        #
        #     enabled (punct "----" <*> kwd "MODULE")
        #       >*> use parse <$> (fun m -> [ Submod m ]) ;
        yield (enabled(punct('----') << times >> kwd('MODULE')) <<
               second_commit >> use(parse()) << apply >>
               (lambda mod: [nodes.Submodule(mod)]))
        #
        #     punct "----" <!> [] ;
        yield intf.punct('----') << bang >> list()
Exemplo n.º 9
0
def prestep():
    while True:
        yield choice([
            #     choice [
            #       kwd "QED" <!> PreQed ;
            kwd('QED') << bang >> tla_ast.PreQed(),
            #
            #       kwd "HIDE"
            #       >*> use usebody
            #       <$> (fun use -> PreHide use) ;
            kwd('HIDE') << second_commit >> use(usebody()) << apply >>
            (lambda use: tla_ast.PreHide(use)),
            #
            #       kwd "SUFFICES"
            #       >*> use sequent
            #       <$> (fun sq -> PreSuffices sq) ;
            kwd('SUFFICES') << second_commit >> use(sequent()) << apply >>
            (lambda sq: tla_ast.PreSuffices(sq)),
            #
            #       kwd "CASE"
            #       >*> use (expr false)
            #       <$> (fun e -> PreCase e) ;
            kwd('CASE') << second_commit >> use(ep.expr(False)) << apply >>
            (lambda e: tla_ast.PreCase(e)),
            #
            #       kwd "PICK"
            #       >*> use (bounds false)
            #       <**> (punct ":"
            #             >>> use (expr false))
            #       <$> (fun (bs, e) -> PrePick (bs, e)) ;
            kwd('PICK') << second_commit >> use(ep.bounds(False)) << times2 >>
            (punct(':') << second >> use(ep.expr(False))) << apply >>
            (lambda bs_e: tla_ast.PrePick(bs_e[0], bs_e[1])),
            #
            #       use suppress >>= begin fun supp ->
            use(suppress()) << shift_eq >> (
                lambda supp: choice([
                    #         choice [
                    #           kwd "USE"
                    #           >*> only
                    #           <*> use usebody
                    #           <*> read_method
                    #           <$> (fun ((onl, use), meth) ->
                    #                   PreUse (supp, onl, use, meth)) ;
                    kwd('USE') << second_commit >> only() << times >> use(
                        usebody()) << times >> read_method() << apply >>
                    (lambda args: tla_ast.PreUse(supp, args[0][0], args[0][1],
                                                 args[1])),
                    #
                    #           kwd "HAVE"
                    #           >*> use (expr false)
                    #           <*> read_method
                    #           <$> (fun (e, meth) -> PreHave (supp, e, meth)) ;
                    kwd('HAVE') << second_commit >> use(ep.expr(
                        False)) << times >> read_method() << apply >>
                    (lambda e_meth: tla_ast.PreHave(supp, e_meth[0], e_meth[1])
                     ),
                    #
                    #           kwd "TAKE"
                    #           >*> use (bounds false)
                    #           <*> read_method
                    #           <$> (fun (bs, meth) -> PreTake (supp, bs, meth)) ;
                    kwd('TAKE') << second_commit >> use(ep.bounds(
                        False)) << times >> read_method() << apply >>
                    (lambda bs_meth: tla_ast.PreTake(supp, bs_meth[0], bs_meth[
                        1])),
                    #
                    #           kwd "WITNESS"
                    #           >*> sep1 (punct ",") (use (expr false))
                    #           <*> read_method
                    #           <$> (fun (es, meth) -> PreWitness (supp, es, meth)) ;
                    kwd('WITNESS') << second_commit >> sep1(
                        punct(','), use(ep.expr(False))
                    ) << times >> read_method() << apply >>
                    (lambda es_meth: tla_ast.PreWitness(
                        supp, es_meth[0], es_meth[1]))
                    #         ]
                    #       end ;
                ])),
            #
            #       attempt (optional (kwd "DEFINE") >>> star1 (use (defn false)))
            #       <$> (fun dfs -> PreDefine dfs) ;
            attempt(
                optional(kwd('DEFINE')) << second >> star1(use(ep.defn(False)))
            ) << apply >> (lambda defns: tla_ast.PreDefine(defns)),
            #
            #       use sequent <$> (fun sq -> PreAssert sq) ;
            use(sequent()) << apply >> (lambda sq: tla_ast.PreAssert(sq))
            #     ]
        ])
Exemplo n.º 10
0
def proof_kwd():
    while True:
        yield choice([kwd('PROOF') << bang >> True, succeed(False)])
Exemplo n.º 11
0
def only():
    while True:
        yield choice([
            kwd('ONLY') << bang >> tla_ast.Only(),
            succeed(tla_ast.Default())
        ])