MCPcopy Create free account
hub / github.com/ColdGrub1384/Pyto / parseString

Method parseString

site-packages/pyparsing.py:1766–1816  ·  view source on GitHub ↗

Execute the parse expression with the given string. This is the main interface to the client code, once the complete expression has been built. If you want the grammar to require that the entire input string be successfully parsed, then set ``parseAll`` to T

( self, instring, parseAll=False )

Source from the content-addressed store, hash-verified

1764 ParserElement._parse = ParserElement._parseCache
1765
1766 def parseString( self, instring, parseAll=False ):
1767 """
1768 Execute the parse expression with the given string.
1769 This is the main interface to the client code, once the complete
1770 expression has been built.
1771
1772 If you want the grammar to require that the entire input string be
1773 successfully parsed, then set ``parseAll`` to True (equivalent to ending
1774 the grammar with ``StringEnd()``).
1775
1776 Note: ``parseString`` implicitly calls ``expandtabs()`` on the input string,
1777 in order to report proper column numbers in parse actions.
1778 If the input string contains tabs and
1779 the grammar uses parse actions that use the ``loc`` argument to index into the
1780 string being parsed, you can ensure you have a consistent view of the input
1781 string by:
1782
1783 - calling ``parseWithTabs`` on your grammar before calling ``parseString``
1784 (see :class:`parseWithTabs`)
1785 - define your parse action using the full ``(s,loc,toks)`` signature, and
1786 reference the input string using the parse action's ``s`` argument
1787 - explictly expand the tabs in your input string before calling
1788 ``parseString``
1789
1790 Example::
1791
1792 Word('a').parseString('aaaaabaaa') # -> ['aaaaa']
1793 Word('a').parseString('aaaaabaaa', parseAll=True) # -> Exception: Expected end of text
1794 """
1795 ParserElement.resetCache()
1796 if not self.streamlined:
1797 self.streamline()
1798 #~ self.saveAsList = True
1799 for e in self.ignoreExprs:
1800 e.streamline()
1801 if not self.keepTabs:
1802 instring = instring.expandtabs()
1803 try:
1804 loc, tokens = self._parse( instring, 0 )
1805 if parseAll:
1806 loc = self.preParse( instring, loc )
1807 se = Empty() + StringEnd()
1808 se._parse( instring, loc )
1809 except ParseBaseException as exc:
1810 if ParserElement.verbose_stacktrace:
1811 raise
1812 else:
1813 # catch and re-raise exception from here, clears out pyparsing internal stack trace
1814 raise exc
1815 else:
1816 return tokens
1817
1818 def scanString( self, instring, maxMatches=_MAX_INT, overlap=False ):
1819 """

Callers 4

parseFileMethod · 0.95
matchesMethod · 0.95
runTestsMethod · 0.95
srangeFunction · 0.45

Calls 8

streamlineMethod · 0.95
preParseMethod · 0.95
expandtabsMethod · 0.80
EmptyClass · 0.70
StringEndClass · 0.70
resetCacheMethod · 0.45
streamlineMethod · 0.45
_parseMethod · 0.45

Tested by

no test coverage detected