o 7]h#@s dZddlmZGdddeZedddddZdZejZeZd Zd d l Td d l Td d l Td d l m Z mZd d lTd d l Td d l mZd d lTd d lmZd dlmZmZmZd dlmZd dlmZmZdevrleZdevrseZdevrzeZeee7ZgdZdS)a pyparsing module - Classes and methods to define and execute parsing grammars ============================================================================= The pyparsing module is an alternative approach to creating and executing simple grammars, vs. the traditional lex/yacc approach, or the use of regular expressions. With pyparsing, you don't need to learn a new syntax for defining grammars or matching expressions - the parsing module provides a library of classes that you use to construct the grammar directly in Python. Here is a program to parse "Hello, World!" (or any greeting of the form ``", !"``), built up using :class:`Word`, :class:`Literal`, and :class:`And` elements (the :meth:`'+'` operators create :class:`And` expressions, and the strings are auto-converted to :class:`Literal` expressions):: from pip._vendor.pyparsing import Word, alphas # define grammar of a greeting greet = Word(alphas) + "," + Word(alphas) + "!" hello = "Hello, World!" print(hello, "->", greet.parse_string(hello)) The program outputs the following:: Hello, World! -> ['Hello', ',', 'World', '!'] The Python representation of the grammar is quite readable, owing to the self-explanatory class names, and the use of :class:`'+'`, :class:`'|'`, :class:`'^'` and :class:`'&'` operators. The :class:`ParseResults` object returned from :class:`ParserElement.parseString` can be accessed as a nested list, a dictionary, or an object with named attributes. The pyparsing module handles some of the problems that are typically vexing when writing text parsers: - extra or missing whitespace (the above program will also handle "Hello,World!", "Hello , World !", etc.) - quoted strings - embedded comments Getting Started - ----------------- Visit the classes :class:`ParserElement` and :class:`ParseResults` to see the base classes that most other pyparsing classes inherit from. Use the docstrings for examples of how to: - construct literal match expressions from :class:`Literal` and :class:`CaselessLiteral` classes - construct character word-group expressions using the :class:`Word` class - see how to create repetitive expressions using :class:`ZeroOrMore` and :class:`OneOrMore` classes - use :class:`'+'`, :class:`'|'`, :class:`'^'`, and :class:`'&'` operators to combine simple expressions into more complex ones - associate names with your parsed results using :class:`ParserElement.setResultsName` - access the parsed data, which is returned as a :class:`ParseResults` object - find some helpful expression short-cuts like :class:`delimitedList` and :class:`oneOf` - find more useful common expressions in the :class:`pyparsing_common` namespace class ) NamedTuplec@sReZdZUeed<eed<eed<eed<eed<eddZdd Zd d Z d S) version_infomajorminormicro releaselevelserialcCsJd|j|j|jd|jddkrdnd|jd|jdf|jdkS)Nz{}.{}.{}z{}{}{}rcrfinal)formatrrrrrselfr@/usr/lib/python3/dist-packages/pip/_vendor/pyparsing/__init__.py __version__jszversion_info.__version__cCsdt|jtS)Nz {} {} / {})r __name__r__version_time__rrrr__str__uszversion_info.__str__c Cs,dtt|jdddt|j|DS)Nz {}.{}({})z, css|]}dj|VqdS)z{}={!r}N)r ).0nvrrr |sz(version_info.__repr__..)r rtypejoinzip_fieldsrrrr__repr__xs zversion_info.__repr__N) r __module__ __qualname__int__annotations__strpropertyrrrrrrrrcs   rr z15 Jan 2022 04:10 UTCz+Paul McGuire )*)__diag__ __compat__)_builtin_exprs) unicode_setUnicodeRangeListpyparsing_unicode)pyparsing_test)pyparsing_commonr*r-r/r.)rr __author__r)r(And AtLineStart AtStringStartCaselessKeywordCaselessLiteral CharsNotInCombineDictEachEmpty FollowedByForward GoToColumnGroup IndentedBlockKeywordLineEnd LineStartLiteralLocated PrecededBy MatchFirstNoMatchNotAny OneOrMoreOnlyOnceOpAssocOptOptionalOrParseBaseExceptionParseElementEnhanceParseExceptionParseExpressionParseFatalException ParseResultsParseSyntaxException ParserElement PositionToken QuotedStringRecursiveGrammarExceptionRegexSkipTo StringEnd StringStartSuppressTokenTokenConverterWhiteWordWordEnd WordStart ZeroOrMoreChar alphanumsalphas alphas8bit any_close_tag any_open_tagc_style_commentcolcommon_html_entity counted_arraycpp_style_commentdbl_quoted_stringdbl_slash_commentdelimited_listdict_ofemptyhexnums html_comment identcharsidentbodycharsjava_style_commentlineline_end line_startlinenomake_html_tags make_xml_tagsmatch_only_at_colmatch_previous_exprmatch_previous_literal nested_exprnull_debug_actionnumsone_of printablespunc8bitpython_style_comment quoted_string remove_quotes replace_withreplace_html_entity rest_of_linesgl_quoted_stringsrange string_end string_starttrace_parse_actionunicode_stringwith_attribute indentedBlockoriginal_text_forungroupinfix_notation locatedExpr with_class CloseMatch token_mapr/r-r+condition_as_parse_actionr.__versionTime__ anyCloseTag anyOpenTag cStyleCommentcommonHTMLEntity countedArraycppStyleCommentdblQuotedStringdblSlashComment delimitedListdictOf htmlCommentjavaStyleCommentlineEnd lineStart makeHTMLTags makeXMLTagsmatchOnlyAtColmatchPreviousExprmatchPreviousLiteral nestedExprnullDebugActiononeOfopAssocpythonStyleComment quotedString removeQuotesreplaceHTMLEntity replaceWith restOfLinesglQuotedString stringEnd stringStarttraceParseAction unicodeString withAttributeroriginalTextFor infixNotationr withClasstokenMapconditionAsParseActionautoname_elementsN)__doc__typingrr__version_info__rrrr0util exceptionsactionscorer(r)resultsr*core_builtin_exprshelpershelper_builtin_exprsunicoder+r,r-testingr.commonr/common_builtin_exprsglobals__all__rrrrs8 G