How to use the spade.pyparsing.ParseResults function in spade

To help you get started, we’ve selected a few spade examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github javipalanca / spade / spade / pyparsing.py View on Github external
raise ParseException(instring, loc, "Missing one or more required elements (%s)" % missing)

        resultlist = []
        for e in matchOrder:
            loc, results = e.parse(instring, loc, doActions)
            resultlist.append(results)

        finalResults = ParseResults([])
        for r in resultlist:
            dups = {}
            for k in r.keys():
                if k in finalResults.keys():
                    tmp = ParseResults(finalResults[k])
                    tmp += ParseResults(r[k])
                    dups[k] = tmp
            finalResults += ParseResults(r)
            for k, v in dups.items():
                finalResults[k] = v
        return loc, finalResults
github javipalanca / spade / spade / pyparsing.py View on Github external
raise
        else:
            if callPreParse:
                loc = self.preParse(instring, loc)
            tokensStart = loc
            if self.mayIndexError or loc >= len(instring):
                try:
                    loc, tokens = self.parseImpl(instring, loc, doActions)
                except IndexError:
                    raise ParseException(instring, len(instring), self.errmsg, self)
            else:
                loc, tokens = self.parseImpl(instring, loc, doActions)

        tokens = self.postParse(instring, loc, tokens)

        retTokens = ParseResults(tokens, self.resultsName, asList=self.saveAsList, modal=self.modalResults)
        if self.parseAction and doActions:
            if debugging:
                try:
                    tokens = self.parseAction(instring, tokensStart, retTokens)
                    if tokens is not None:
                        if isinstance(tokens, tuple):
                            tokens = tokens[1]
                        retTokens = ParseResults(tokens,
                                                 self.resultsName,
                                                 asList=self.saveAsList and isinstance(tokens, (ParseResults, list)),
                                                 modal=self.modalResults)
                except ParseException, err:
                    #~ print "Exception raised in user parse action:", err
                    if (self.debugActions[2]):
                        self.debugActions[2](instring, tokensStart, self, err)
                    raise
github javipalanca / spade / spade / pyparsing.py View on Github external
tokens = tokens[1]
                        retTokens = ParseResults(tokens,
                                                 self.resultsName,
                                                 asList=self.saveAsList and isinstance(tokens, (ParseResults, list)),
                                                 modal=self.modalResults)
                except ParseException, err:
                    #~ print "Exception raised in user parse action:", err
                    if (self.debugActions[2]):
                        self.debugActions[2](instring, tokensStart, self, err)
                    raise
            else:
                tokens = self.parseAction(instring, tokensStart, retTokens)
                if tokens is not None:
                    if isinstance(tokens, tuple):
                        tokens = tokens[1]
                    retTokens = ParseResults(tokens,
                                             self.resultsName,
                                             asList=self.saveAsList and isinstance(tokens, (ParseResults, list)),
                                             modal=self.modalResults)

        if debugging:
            #~ print "Matched",self,"->",retTokens.asList()
            if (self.debugActions[1]):
                self.debugActions[1](instring, tokensStart, loc, self, retTokens)

        return loc, retTokens
github javipalanca / spade / spade / pyparsing.py View on Github external
except IndexError:
                    raise ParseException(instring, len(instring), self.errmsg, self)
            else:
                loc, tokens = self.parseImpl(instring, loc, doActions)

        tokens = self.postParse(instring, loc, tokens)

        retTokens = ParseResults(tokens, self.resultsName, asList=self.saveAsList, modal=self.modalResults)
        if self.parseAction and doActions:
            if debugging:
                try:
                    tokens = self.parseAction(instring, tokensStart, retTokens)
                    if tokens is not None:
                        if isinstance(tokens, tuple):
                            tokens = tokens[1]
                        retTokens = ParseResults(tokens,
                                                 self.resultsName,
                                                 asList=self.saveAsList and isinstance(tokens, (ParseResults, list)),
                                                 modal=self.modalResults)
                except ParseException, err:
                    #~ print "Exception raised in user parse action:", err
                    if (self.debugActions[2]):
                        self.debugActions[2](instring, tokensStart, self, err)
                    raise
            else:
                tokens = self.parseAction(instring, tokensStart, retTokens)
                if tokens is not None:
                    if isinstance(tokens, tuple):
                        tokens = tokens[1]
                    retTokens = ParseResults(tokens,
                                             self.resultsName,
                                             asList=self.saveAsList and isinstance(tokens, (ParseResults, list)),
github javipalanca / spade / spade / pyparsing.py View on Github external
if tmpReqd:
            missing = ", ".join([str(e) for e in tmpReqd])
            raise ParseException(instring, loc, "Missing one or more required elements (%s)" % missing)

        resultlist = []
        for e in matchOrder:
            loc, results = e.parse(instring, loc, doActions)
            resultlist.append(results)

        finalResults = ParseResults([])
        for r in resultlist:
            dups = {}
            for k in r.keys():
                if k in finalResults.keys():
                    tmp = ParseResults(finalResults[k])
                    tmp += ParseResults(r[k])
                    dups[k] = tmp
            finalResults += ParseResults(r)
            for k, v in dups.items():
                finalResults[k] = v
        return loc, finalResults