예제 #1
0
 def exitInterval(self, ctx: puffinParser.IntervalContext):
     if self.target == 'Python3':
         ctx.text = child_catcher(ctx, 'puffin').replace(
             '[', 'puffin.I(').replace(']', ')')
     if self.target == 'R':
         ctx.text = child_catcher(ctx, 'puffin').replace(
             '[', 'interval(').replace(']', ')')
예제 #2
0
    def exitTerm(self, ctx: Python3Parser.TermContext):

        expr = child_catcher(ctx, 'Python3')
        args = child_catcher(ctx, 'Python3', list=True)

        if len(args) != 1:

            while len(args) != 1:
                nargs = args[0:3]

                if nargs[0] in self.dependencies.index and nargs[
                        2] in self.dependencies.index:
                    methodtext = ',method = \'%s\'' % self.dependencies.loc[
                        nargs[0], nargs[2]]
                else:
                    methodtext = ''

                if nargs[1] == "*":
                    text = 'puffin.mul(%s,%s%s)' % (nargs[0], nargs[2],
                                                    methodtext)
                elif nargs[1] == "/":
                    text = 'puffin.div(%s,%s%s)' % (nargs[0], nargs[2],
                                                    methodtext)

                del args[0:3]

                args = [text] + args
        else:
            text = expr

        ctx.text = text
예제 #3
0
    def exitStmt(self, ctx: Python3Parser.StmtContext):

        if self.indent == 0:
            if ctx.getText().strip() in self.changes.keys():

                ctx.text = self.changes[ctx.getText().strip()]
            else:
                ctx.text = child_catcher(ctx, 'Python3')
            self.output += ctx.text
        else:
            ctx.text = child_catcher(ctx, 'Python3', indent=self.indent)
예제 #4
0
    def exitExpr_stmt(self, ctx: Python3Parser.ExprlistContext):
        ctx.text = child_catcher(ctx, 'Python3')

        if self.vardec:

            # Find variable name
            varname = ctx.text.split('=')[0].strip()
            var = varname

            if self.funname != '':
                # If in function add function name to varname
                varname = "%s.%s" % (self.funname, varname)

            if varname in self.repvar.keys():
                # If varname is repeated add count flag

                if self.repvar[varname] != 1 or "%s!%i" % (
                        varname, self.repvar[varname]) in self.varlist:

                    varname = "%s!%i" % (varname, self.repvar[var])

                # Add to number of repeats
                self.repvar[var] += 1

            if varname in self.varlist:
                ctx.text = "%s = %s" % (var, self.uncerts[varname])

                self.varlist.remove(varname)
예제 #5
0
    def exitInterval_plusminus(self,
                               ctx: puffinParser.Interval_plusminusContext):
        asList = child_catcher(ctx, 'puffin', list=True)
        a = mp.mpf(asList[1])
        b = mp.mpf(asList[3])

        ctx.text = '[%s,%s]' % (a - b, a + b)
예제 #6
0
    def exitElement(self, ctx: puffinParser.ElementContext):
        ctx.text = child_catcher(ctx, 'puffin')

        if not self.directChange:
            if '<<' in ctx.text:
                ctx.text = ctx.text.replace('<<', '').replace('>>', '')
            else:
                ctx.text = ctx.text.replace('«', '').replace('»', '')
        else:
            ctx.text = ctx.text.replace('<<', '«').replace('>>', '»')
            self.directChange = False
예제 #7
0
    def exitPdistribution(self, ctx: puffinParser.PdistributionContext):

        asList = child_catcher(ctx, 'puffin', list=True)

        if self.target == 'Python3':

            asList[0] = 'puffin.' + asList[0]

        elif self.target == 'R':

            pass  # No syntax change

        ctx.text = ''
        for i in asList:
            ctx.text += i
예제 #8
0
    def enterDependence(self, ctx: puffinParser.DependenceContext):

        # detect dependancies

        # puffin format will is as follows:
        # a <fiop> b,c,d,....

        # will be stored in a dataframe

        children = child_catcher(ctx, 'puffin', list=True, noTerm=True)

        named = children.pop(0)

        deptype = children.pop(0).replace('<', '').replace('>', '')

        for child in children:

            # check to see if dependence already specified
            if named in self.dependencies.index and child in self.dependencies.index:
                # check if dependencies clash
                if deptype != 'f' and self.dependencies.loc[named,
                                                            child] == 'f':
                    # this is allowed
                    pass
                elif deptype == self.dependencies.loc[named, child]:
                    # this is allowed
                    pass
                else:
                    raise Exception('Stated Dependancies Clash')

            else:
                # if not specided specify them
                if named not in self.dependencies.index:
                    self.dependencies.loc[named, named] = 'p'
                if child not in self.dependencies.index:
                    self.dependencies.loc[child, child] = 'p'

            self.dependencies.loc[named, child] = deptype
            self.dependencies.loc[child, named] = deptype

            self.dependencies = self.dependencies.fillna('f')
예제 #9
0
    def exitFile_input(self, ctx: puffinParser.File_inputContext):
        for line in child_catcher(ctx, 'puffin', list=True, noTerm=True):
            if line.strip() != "":
                parts = [x.strip() for x in line.split('->')]
                # print(line)
                if '«' in line:

                    self.changes[parts[0].replace("«",
                                                  '').replace("»",
                                                              "")] = parts[1]

                else:

                    if parts[0] in self.uncerts.keys():

                        print(
                            "%s has been reassinged multiple times. Only the last entry will be used"
                            % (parts[0]))

                    # print(parts)
                    self.uncerts[parts[0]] = parts[1]
예제 #10
0
    def exitStmt(self, ctx: RParser.StmtContext):

        if self.vardec:
            if self.list_text != "":

                text = ctx.getText().split(
                    '=')[0] + ' -> ' + self.list_text + '\n'
            else:

                text = child_catcher(ctx, 'R', space_needed=True) + '\n'

            if self.funname != "":

                text = "%s.%s" % (self.funname, text)

            varname = text.split('->')[0].strip()
            if varname not in self.repvar.keys():
                self.repvar[varname] = 1
            else:
                self.repvar[varname] += 1
                text = text.replace(varname,
                                    "%s!%i" % (varname, self.repvar[varname]))

            self.output.write(text)
예제 #11
0
 def exitEncoding_decl(self, ctx: Python3Parser.Encoding_declContext):
     ctx.text = child_catcher(ctx, 'Python3')
예제 #12
0
 def exitArgument(self, ctx: Python3Parser.ArgumentContext):
     ctx.text = child_catcher(ctx, 'Python3')
예제 #13
0
 def exitComp_if(self, ctx: Python3Parser.Comp_ifContext):
     ctx.text = child_catcher(ctx, 'Python3')
예제 #14
0
 def exitDictorsetmaker(self, ctx: Python3Parser.DictorsetmakerContext):
     ctx.text = child_catcher(ctx, 'Python3')
예제 #15
0
 def exitClassdef(self, ctx: Python3Parser.ClassdefContext):
     ctx.text = child_catcher(ctx, 'Python3')
예제 #16
0
 def exitSliceop(self, ctx: Python3Parser.SliceopContext):
     ctx.text = child_catcher(ctx, 'Python3')
예제 #17
0
 def exitTestlist(self, ctx: Python3Parser.TestlistContext):
     ctx.text = child_catcher(ctx, 'Python3')
예제 #18
0
 def exitYield_arg(self, ctx: Python3Parser.Yield_argContext):
     ctx.text = child_catcher(ctx, 'Python3')
예제 #19
0
 def exitNonlocal_stmt(self, ctx: Python3Parser.Nonlocal_stmtContext):
     ctx.text = child_catcher(ctx, 'Python3')
예제 #20
0
 def exitTry_stmt(self, ctx: Python3Parser.Try_stmtContext):
     ctx.text = child_catcher(ctx, 'Python3')
예제 #21
0
 def exitFuncdef(self, ctx: Python3Parser.FuncdefContext):
     ctx.text = child_catcher(ctx, 'Python3')
     self.funname = ""
예제 #22
0
 def exitTest_nocond(self, ctx: Python3Parser.Test_nocondContext):
     ctx.text = child_catcher(ctx, 'Python3')
예제 #23
0
 def exitWith_item(self, ctx: Python3Parser.With_itemContext):
     ctx.text = child_catcher(ctx, 'Python3')
예제 #24
0
 def exitExcept_clause(self, ctx: Python3Parser.Except_clauseContext):
     ctx.text = child_catcher(ctx, 'Python3')
예제 #25
0
 def exitLambdef_nocond(self, ctx: Python3Parser.Lambdef_nocondContext):
     ctx.text = child_catcher(ctx, 'Python3')
예제 #26
0
 def exitSubscript(self, ctx: Python3Parser.SubscriptContext):
     ctx.text = child_catcher(ctx, 'Python3')
예제 #27
0
 def exitSuite(self, ctx: Python3Parser.SuiteContext):
     ctx.text = child_catcher(ctx,
                              'Python3',
                              isSuite=True,
                              indent=self.indent)
     self.indent -= 1
예제 #28
0
 def exitStar_expr(self, ctx: Python3Parser.Star_exprContext):
     ctx.text = child_catcher(ctx, 'Python3')
예제 #29
0
 def enterFuncdef(self, ctx: Python3Parser.FuncdefContext):
     self.funname = child_catcher(ctx, 'Python3', list=True)[1]
예제 #30
0
 def exitTrailer(self, ctx: Python3Parser.TrailerContext):
     ctx.text = child_catcher(ctx, 'Python3')