コード例 #1
0
ファイル: _proof_parser.py プロジェクト: tlaplus/tla_python
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])))
            ])))
コード例 #2
0
ファイル: _module_parser.py プロジェクト: tlaplus/tla_python
    def apply_def(local):
        # let ex = if Option.is_some l then Local else Export in
        if local is None:
            ex = nodes.Export()
        else:
            ex = nodes.Local()

        def choices():
            # NOTE: The order of choices was INSTANCE, def
            # changed for efficiency reasons
            #
            # use (defn false)
            yield use(
                ep.defn(False)
                # <$> (fun df -> [ Definition (df, User, Hidden, ex) ]) ;
            ) << apply >> (
                lambda df:
                [nodes.Definition(df, nodes.User(), nodes.Hidden(), ex)])
            # use (instance false)
            yield use(
                ep.instance(False)
                # <$> (fun inst -> [ Anoninst (inst, ex) ]) ;
            ) << apply >> (lambda inst: [nodes.AnonymousInstance(inst, ex)])

        return choice_iter(choices)
コード例 #3
0
ファイル: _proof_parser.py プロジェクト: tlaplus/tla_python
def suppress():
    while True:
        yield choice([
            intf.pragma(punct('_') << or_ >> intf.ident('suppress')) << bang >>
            tla_ast.Suppress(),
            succeed(tla_ast.Emit())
        ])
コード例 #4
0
ファイル: _proof_parser.py プロジェクト: tlaplus/tla_python
def proof():
    while True:
        yield choice([
            star1(use(preproof())),
            intf.locate(succeed(tla_ast.PreOmitted(tla_ast.Implicit()))) <<
            apply >> (lambda pp: [pp])
        ]) << apply >> toplevel
コード例 #5
0
ファイル: _module_parser.py プロジェクト: tlaplus/tla_python
 def apply_theorem_proof(args):
     (((name, body), meth), prf) = args
     ctx = body.context
     goal = body.goal
     goal_ = with_meth(goal, meth)
     body_ = nodes.Sequent(ctx, goal_)
     return [nodes.Theorem(name, body_, prf)]
コード例 #6
0
ファイル: _proof_parser.py プロジェクト: tlaplus/tla_python
 def f(form):
     if isinstance(form, tokens.ST):
         step_name = form.kind
         step_label = form.string
         ndots = form.i
         if isinstance(step_name, tokens.StepStar):
             return tla_ast.StepStar(step_label)
         elif isinstance(step_name, tokens.StepPlus):
             return tla_ast.StepPlus(step_label)
         elif isinstance(step_name, tokens.StepNum):
             return tla_ast.StepNum(step_name.value, step_label)
         else:
             raise TypeError(step_name)
     else:
         return None
コード例 #7
0
ファイル: _module_parser.py プロジェクト: tlaplus/tla_python
 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])
コード例 #8
0
ファイル: _module_parser.py プロジェクト: tlaplus/tla_python
 def choices():
     # NOTE: The order of choices was INSTANCE, def
     # changed for efficiency reasons
     #
     # use (defn false)
     yield use(
         ep.defn(False)
         # <$> (fun df -> [ Definition (df, User, Hidden, ex) ]) ;
     ) << apply >> (
         lambda df:
         [nodes.Definition(df, nodes.User(), nodes.Hidden(), ex)])
     # use (instance false)
     yield use(
         ep.instance(False)
         # <$> (fun inst -> [ Anoninst (inst, ex) ]) ;
     ) << apply >> (lambda inst: [nodes.AnonymousInstance(inst, ex)])
コード例 #9
0
ファイル: _proof_parser.py プロジェクト: tlaplus/tla_python
def sequent():
    while True:
        yield choice([
            use(ep.sequent(False)),
            use(ep.expr(False)) << apply >>
            (lambda e: tla_ast.Sequent(list(), e))
        ])
コード例 #10
0
ファイル: _module_parser.py プロジェクト: tlaplus/tla_python
        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)])
            ])
コード例 #11
0
ファイル: _module_parser.py プロジェクト: tlaplus/tla_python
 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)
コード例 #12
0
ファイル: _module_parser.py プロジェクト: tlaplus/tla_python
    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()
コード例 #13
0
ファイル: _proof_parser.py プロジェクト: tlaplus/tla_python
def to_proof(currlv, arg):
    #   | [] ->
    if not arg:
        #       (Omitted Implicit @@ currlv, [])
        omitted = tla_ast.Omitted(tla_ast.Implicit())
        return (omitted, list())
#   | {core = PreBy (supp, onl, use, meth)} as p :: ps ->
    elif isinstance(arg[0], tla_ast.PreBy):
        p = arg[0]
        ps = arg[1:]
        supp = p.supp
        only = p.only
        usable = p.usable
        meth = p.method
        #       let p = By (use, onl = Only) @@ p in
        p = tla_ast.By(usable, isinstance(only, tla_ast.Only))
        #       let p = Property.assign p Props.step
        #                   (Unnamed (currlv.core, 0)) in
        p.step_number = tla_ast.Unnamed(currlv, 0)
        #       (annotate supp meth p, ps)
        annotate(supp, meth, p)
        return (p, ps)
#   | {core = PreObvious (supp, meth)} as p :: ps ->
    elif isinstance(arg[0], tla_ast.PreObvious):
        p = arg[0]
        ps = arg[1:]
        supp = p.supp
        meth = p.method
        #       let p = Obvious @@ p in
        obvious = tla_ast.Obvious()
        #       (annotate supp meth p, ps)
        annotate(supp, meth, obvious)
        return (obvious, ps)
#   | {core = PreOmitted om} as p :: ps ->
    elif isinstance(arg[0], tla_ast.PreOmitted):
        p = arg[0]
        ps = arg[1:]
        om = p.omission
        #       (Omitted om @@ p, ps)
        omitted = tla_ast.Omitted(om)
        return (omitted, ps)
    else:
        #   | ps -> begin
        ps = arg
        #       try
        try:
            #         let (ss, qp, ps) = to_steps ~first:true currlv ps in
            (ss, qp, ps) = to_steps(first=True, currlv=currlv, ps=ps)
            #         let sloc = List.fold_left begin
            #           fun l s -> Loc.merge l (Util.get_locus s)
            #         end (try
            #               Util.get_locus qp.core
            #              with _ -> Util.get_locus
            #                           (get_qed_proof qp.core)) ss in
            # TODO: locus
            #         let prf = Util.locate (Steps (ss, qp.core)) sloc in
            prf = tla_ast.Steps(ss, qp)
            #         let prf = Property.assign prf Props.step
            #                   (Property.get qp Props.step) in
            prf.step_number = qp.step_number
            #         (prf, ps)
            return (prf, ps)
#       with Backtrack ->
        except Backtrack:
            #         (Omitted Implicit @@ currlv, ps)
            omitted = tla_ast.Omitted(tla_ast.Implicit())
            return (omitted, ps)
コード例 #14
0
ファイル: _proof_parser.py プロジェクト: tlaplus/tla_python
def to_step(currlv, st, ps):
    #   | PreQed ->
    if isinstance(st, tla_ast.PreQed):
        #       let (p, ps) = to_proof (currlv + 1 @@ st) ps in
        p, ps = to_proof(currlv + 1, ps)
        #       (QED p, ps)
        return (QED(p), ps)
#   | PreHide use ->
    elif isinstance(st, tla_ast.PreHide):
        use = st.usable
        #       (STEP (Hide use @@ st), ps)
        hide = tla_ast.Hide(use)
        return (STEP(hide), ps)
#   | PreUse (supp, onl, use, meth) ->
    elif isinstance(st, tla_ast.PreUse):
        supp = st.supp
        only = st.only
        usable = st.usable
        meth = st.method
        #       let u = Use (use, onl = Only) @@ st in
        use = tla_ast.Use(usable, isinstance(only, tla_ast.Only))
        #       (STEP (annotate supp meth u), ps)
        annotate(supp, meth, use)
        return (STEP(use), ps)
#   | PreDefine dfs ->
    elif isinstance(st, tla_ast.PreDefine):
        dfs = st.definitions
        #       (STEP (Define dfs @@ st), ps)
        define = tla_ast.Define(dfs)
        return (STEP(define), ps)
#   | PreHave (supp, e, meth) ->
    elif isinstance(st, tla_ast.PreHave):
        supp = st.supp
        e = st.expr
        meth = st.method
        #       let h = Have e @@ st in
        have = tla_ast.Have(e)
        #       (STEP (annotate supp meth h), ps)
        annotate(supp, meth, have)
        return (STEP(have), ps)
#   | PreTake (supp, bs, meth) ->
    elif isinstance(st, tla_ast.PreTake):
        supp = st.supp
        bs = st.bounds
        meth = st.method
        #       let t = Take bs @@ st in
        take = tla_ast.Take(bs)
        #       (STEP (annotate supp meth t), ps)
        annotate(supp, meth, take)
        return (STEP(take), ps)
#   | PreWitness (supp, es, meth) ->
    elif isinstance(st, tla_ast.PreWitness):
        supp = st.supp
        es = st.exprs
        meth = st.method
        #       let w = Witness es @@ st in
        witness = tla_ast.Witness(es)
        #       (STEP (annotate supp meth w), ps)
        annotate(supp, meth, witness)
        return (STEP(witness), ps)
#   | PreAssert sq ->
    elif isinstance(st, tla_ast.PreAssert):
        sq = st.sequent
        #       let (p, ps) = to_proof (currlv + 1 @@ st) ps in
        p, ps = to_proof(currlv + 1, ps)
        #       let st = enlarge_loc st p in
        enlarge_loc(st, p)
        #       (STEP (Assert (sq, p) @@ st), ps)
        assert_ = tla_ast.Assert(sq, p)
        return (STEP(assert_), ps)
#   | PreSuffices sq ->
    elif isinstance(st, tla_ast.PreSuffices):
        sq = st.sequent
        #       let (p, ps) = to_proof (currlv + 1 @@ st) ps in
        p, ps = to_proof(currlv + 1, ps)
        #       let st = enlarge_loc st p in
        enlarge_loc(st, p)
        #       (STEP (Suffices (sq, p) @@ st), ps)
        suffices = tla_ast.Suffices(sq, p)
        return (STEP(suffices), ps)
#   | PreCase e ->
    elif isinstance(st, tla_ast.PreCase):
        e = st.expr
        #       let (p, ps) = to_proof (currlv + 1 @@ st) ps in
        p, ps = to_proof(currlv + 1, ps)
        #       let st = enlarge_loc st p in
        enlarge_loc(st, p)
        #       (STEP (Pcase (e, p) @@ st), ps)
        pcase = tla_ast.Pcase(e, p)
        return (STEP(pcase), ps)
#   | PrePick (bs, e) ->
    elif isinstance(st, tla_ast.PrePick):
        bs = st.bounds
        e = st.expr
        #       let (p, ps) = to_proof (currlv + 1 @@ st) ps in
        p, ps = to_proof(currlv + 1, ps)
        #       let st = enlarge_loc st p in
        enlarge_loc(st, p)
        #       (STEP (Pick (bs, e, p) @@ st), ps)
        pick = tla_ast.Pick(bs, e, p)
        return (STEP(pick), ps)
    else:
        raise TypeError(st)
コード例 #15
0
ファイル: _proof_parser.py プロジェクト: tlaplus/tla_python
def only():
    while True:
        yield choice([
            kwd('ONLY') << bang >> tla_ast.Only(),
            succeed(tla_ast.Default())
        ])
コード例 #16
0
ファイル: _proof_parser.py プロジェクト: tlaplus/tla_python
def set_level(n, preno):
    label = preno.label
    if label == '':
        return tla_ast.Unnamed(n, uuid.uuid4())
    else:
        return tla_ast.Named(n, label, False)
コード例 #17
0
ファイル: _module_parser.py プロジェクト: tlaplus/tla_python
def with_meth(e, meth):
    if meth is None:
        return e
    else:
        return nodes.With(e, meth)
コード例 #18
0
ファイル: _module_parser.py プロジェクト: tlaplus/tla_python
 def apply_axiom(args):
     ((nm, e), meth) = args
     return [nodes.Axiom(nm, with_meth(e, meth))]
コード例 #19
0
ファイル: _proof_parser.py プロジェクト: tlaplus/tla_python
def to_steps(first, currlv, ps):
    #   | {core = PreStep (kwd, sn, st)} as p :: ps ->
    p = ps[0]
    ps = ps[1:]
    kwd = p.boolean  # PROOF keyword
    sn = p.preno  # step number
    st = p.prestep
    #       if not first && kwd then begin
    #         Errors.set p
    #             ("PROOF keyword found in step that "
    #              "does not begin subproof");
    #         Util.eprintf ~at:p
    #             ("PROOF keyword found in step that " ^
    #              "does not begin subproof\n%!");
    #         failwith "Proof.Parser"
    #       end ;
    assert (first or not kwd)
    #       let thislv = match sn, kwd, first with
    #         | Num (n, _), _, _ -> n
    if isinstance(sn, tla_ast.StepNum):
        n = sn.level
        thislv = int(n)
#         | Star _, true, true ->
    elif (isinstance(sn, tla_ast.StepStar) and kwd and first):
        #             (*
        #              * Util.eprintf ~at:p
        #              *   "%d: <*> -> %d (because first and PROOF)\n%!"
        #              *   currlv.core currlv.core ;
        #              *)
        #             currlv.core
        thislv = currlv
#         | Star _, false, true ->
    elif (isinstance(sn, tla_ast.StepStar) and not kwd and first):
        #             (*
        #              * Util.eprintf ~at:p
        #              *   "%d: <*> -> %d (because first and no PROOF)\n%!"
        #              *   currlv.core (currlv.core - 1) ;
        #              *)
        #             currlv.core - 1
        thislv = currlv - 1
#         | Star _, _, false ->
    elif (isinstance(sn, tla_ast.StepStar) and not first):
        #             assert (not kwd) ;
        assert not kwd
        #             (*
        #              * Util.eprintf ~at:p
        #              *   "%d: <*> -> %d (because not first)\n%!"
        #              *   currlv.core currlv.core ;
        #              *)
        #             currlv.core
        thislv = currlv
#         | Plus _, _, false ->
    elif (isinstance(sn, tla_ast.StepPlus) and not first):
        #             Errors.set p "<+> used but no subproof expected" ;
        #               Util.eprintf ~at:p
        #                   "<+> used but no subproof expected\n%!" ;
        #             failwith "Proof.Parser"
        raise Exception('<+> usedd but no subproof expected')
#         | Plus _, _, _ ->
    elif isinstance(sn, tla_ast.StepPlus):
        #             (*
        #              * Util.eprintf ~at:p
        #              *   "%d: <+> -> %d\n%!"
        #              *   currlv.core currlv.core ;
        #              *)
        #             currlv.core
        thislv = currlv
    else:
        raise ValueError(sn, kwd, first)
#       in
#       if thislv < currlv.core then
    if thislv < currlv:
        #           raise Backtrack ;
        raise Backtrack()
#       if not first && thislv > currlv.core then
    if not first and thislv > currlv:
        #           raise Backtrack ;
        raise Backtrack()
#       let sn = set_level thislv sn in begin
    sn = set_level(thislv, sn)
    #         match to_step thislv (st @@ p) ps with
    to_stp = to_step(thislv, st, ps)
    #           | (STEP s, nps) ->
    if isinstance(to_stp[0], STEP):
        s = to_stp[0].step
        nps = to_stp[1]
        #               let s = Property.assign s Props.step sn in
        s.step_number = sn
        #               let thislv = Util.locate thislv
        #                       (Loc.right_of (Util.get_locus s)) in
        # TODO: locate
        #               let (ss, qp, ps) = to_steps thislv nps in
        ss, qp, ps = to_steps(first=False, currlv=thislv, ps=nps)
        #               (s :: ss, qp, ps)
        return ([s] + ss, qp, ps)
#           | (QED qp, ps) ->
    elif isinstance(to_stp[0], QED):
        qp = to_stp[0].proof
        ps = to_stp[1]
        #               let qp = { core =
        #                           {core = Qed qp;
        #                            props = [Props.step.Property.set sn]} ;
        #                          props = [Props.step.Property.set sn] } in
        #               ([], qp, ps)
        qed = tla_ast.Qed(qp)
        qed.step_number = sn
        return (list(), qed, ps)
コード例 #20
0
ファイル: _module_parser.py プロジェクト: tlaplus/tla_python
 def apply_use_hide(args):
     ((supp, uh), use) = args
     if uh == 'USE':
         return [nodes.Mutate(nodes.ModuleUse(nodes.Suppress()), use)]
     else:
         return [nodes.Mutate(nodes.ModuleHide(), use)]
コード例 #21
0
ファイル: _proof_parser.py プロジェクト: tlaplus/tla_python
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))
            #     ]
        ])
コード例 #22
0
ファイル: _proof_parser.py プロジェクト: tlaplus/tla_python
def definable():
    while True:
        yield intf.locate(
            sep1(intf.punct('!'), choice([intf.anyop(),
                                          intf.anyident()])) << apply >>
            (lambda ids: tla_ast.Dvar('!'.join(ids))))
コード例 #23
0
def _generate_tlaops():
    tlaops = [
        ('Logic', [
            ('=>', (1, 1), Infix(Non()), list(), nodes.Implies()),
            ('<=>', (2, 2), Infix(Non()), ['\\equiv'], nodes.Equiv()),
            ('/\\', (3, 3), Infix(Left()), ['\\land'], nodes.Conj()),
            ('\\/', (3, 3), Infix(Left()), ['\\lor'], nodes.Disj()),
            ('~', (4, 4), Prefix(), ['\\neg', '\\lnot'], nodes.Neg()),
            ('=', (5, 5), Infix(Non()), list(), nodes.Eq()),
            ('#', (5, 5), Infix(Non()), ['/='], nodes.Neq()),
        ]),
        ('Sets', [
            ('SUBSET', (8, 8), Prefix(), list(), nodes.SUBSET()),
            ('UNION', (8, 8), Prefix(), list(), nodes.UNION()),
            ('DOMAIN', (9, 9), Prefix(), list(), nodes.DOMAIN()),
            ('\\subseteq', (5, 5), Infix(Non()), list(), nodes.Subseteq()),
            ('\\in', (5, 5), Infix(Non()), list(), nodes.Mem()),
            ('\\notin', (5, 5), Infix(Non()), [], nodes.Notmem()),
            ('\\', (8, 8), Infix(Non()), ['\\setminus'], nodes.Setminus()),
            ('\\cap', (8, 8), Infix(Left()), ['\\intersect'], nodes.Cap()),
            ('\\cup', (8, 8), Infix(Left()), ['\\union'], nodes.Cup()),
            ('\\X', (10, 13), Infix(Non()), ['\\times'], None),
        ]),
        ('Modal', [
            ("'", (15, 15), Postfix(), list(), nodes.Prime()),
            ('~>', (2, 2), Infix(Non()), ['\\leadsto'], nodes.LeadsTo()),
            ('ENABLED', (4, 15), Prefix(), list(), nodes.ENABLED()),
            ('UNCHANGED', (4, 15), Prefix(), list(), nodes.UNCHANGED()),
            ('\\cdot', (5, 14), Infix(Left()), list(), nodes.Cdot()),
            ('-+->', (2, 2), Infix(Non()), list(), nodes.WhilePlus()),
            ('[]', (4, 15), Prefix(), list(), nodes.Box(True)),
            ('<>', (4, 15), Prefix(), list(), nodes.Diamond()),
        ]),
        ('User', [(name, prec, fix, als, None) for name, prec, fix, als in [
            ('^', (14, 14), Infix(Non()), list()),
            ('/', (13, 13), Infix(Non()), list()),
            ('*', (13, 13), Infix(Left()), list()),
            ('-.', (12, 12), Prefix(), ['-']),
            ('-', (11, 11), Infix(Left()), list()),
            ('+', (10, 10), Infix(Left()), list()),
            ('^+', (15, 15), Postfix(), list()),
            ('^*', (15, 15), Postfix(), list()),
            ('^#', (15, 15), Postfix(), list()),
            ('<', (5, 5), Infix(Non()), list()),
            ('=<', (5, 5), Infix(Non()), ['<=', '\\leq']),
            ('>', (5, 5), Infix(Non()), list()),
            ('>=', (5, 5), Infix(Non()), ['\\geq']),
            ('...', (9, 9), Infix(Non()), list()),
            ('..', (9, 9), Infix(Non()), list()),
            ('|', (10, 11), Infix(Left()), list()),
            ('||', (10, 11), Infix(Left()), list()),
            ('&&', (13, 13), Infix(Left()), list()),
            ('&', (13, 13), Infix(Left()), list()),
            ('$$', (9, 13), Infix(Left()), list()),
            ('$', (9, 13), Infix(Left()), list()),
            ('??', (9, 13), Infix(Left()), list()),
            ('%%', (10, 11), Infix(Left()), list()),
            ('%', (10, 11), Infix(Left()), ['\\mod']),
            ('##', (9, 13), Infix(Left()), list()),
            ('++', (10, 10), Infix(Left()), list()),
            ('--', (11, 11), Infix(Left()), list()),
            ('**', (13, 13), Infix(Left()), list()),
            ('//', (13, 13), Infix(Non()), list()),
            ('^^', (14, 14), Infix(Non()), list()),
            ('@@', (6, 6), Infix(Left()), list()),
            ('!!', (9, 13), Infix(Non()), list()),
            ('|-', (5, 5), Infix(Non()), list()),
            ('|=', (5, 5), Infix(Non()), list()),
            ('-|', (5, 5), Infix(Non()), list()),
            ('=|', (5, 5), Infix(Non()), list()),
            ('<:', (7, 7), Infix(Non()), list()),
            (':>', (7, 7), Infix(Non()), list()),
            (':=', (5, 5), Infix(Non()), list()),
            ('::=', (5, 5), Infix(Non()), list()),
            ('(+)', (10, 10), Infix(Left()), ['\\oplus']),
            ('(-)', (11, 11), Infix(Left()), ['\\ominus']),
            ('(.)', (13, 13), Infix(Left()), ['\\odot']),
            ('(/)', (13, 13), Infix(Non()), ['\\oslash']),
            ('(\\X)', (13, 13), Infix(Left()), ['\\otimes']),
            ('\\uplus', (9, 13), Infix(Left()), list()),
            ('\\sqcap', (9, 13), Infix(Left()), list()),
            ('\\sqcup', (9, 13), Infix(Left()), list()),
            ('\\div', (13, 13), Infix(Non()), list()),
            ('\\wr', (9, 14), Infix(Non()), list()),
            ('\\star', (13, 13), Infix(Left()), list()),
            ('\\o', (13, 13), Infix(Left()), ['\\circ']),
            ('\\bigcirc', (13, 13), Infix(Left()), list()),
            ('\\bullet', (13, 13), Infix(Left()), list()),
            ('\\prec', (5, 5), Infix(Non()), list()),
            ('\\succ', (5, 5), Infix(Non()), list()),
            ('\\preceq', (5, 5), Infix(Non()), list()),
            ('\\succeq', (5, 5), Infix(Non()), list()),
            ('\\sim', (5, 5), Infix(Non()), list()),
            ('\\simeq', (5, 5), Infix(Non()), list()),
            ('\\ll', (5, 5), Infix(Non()), list()),
            ('\\gg', (5, 5), Infix(Non()), list()),
            ('\\asymp', (5, 5), Infix(Non()), list()),
            ('\\subset', (5, 5), Infix(Non()), list()),
            ('\\supset', (5, 5), Infix(Non()), list()),
            ('\\supseteq', (5, 5), Infix(Non()), list()),
            ('\\approx', (5, 5), Infix(Non()), list()),
            ('\\cong', (5, 5), Infix(Non()), list()),
            ('\\sqsubset', (5, 5), Infix(Non()), list()),
            ('\\sqsubseteq', (5, 5), Infix(Non()), list()),
            ('\\sqsupset', (5, 5), Infix(Non()), list()),
            ('\\sqsupseteq', (5, 5), Infix(Non()), list()),
            ('\\doteq', (5, 5), Infix(Non()), list()),
            ('\\propto', (5, 5), Infix(Non()), list()),
        ]])
    ]
    return tlaops