K iO#TdZddlmZGddeZeddddd Zd Zej ZeZd Zd d l d d l d d l d d l m Z mZd d ld d l d dl mZd d ld dlmZd dlmZmZmZd dlmZd dlmZmZdevreZdevreZdevreZeeezz ZgdZy)a pyparsing - Classes and methods to define and execute parsing grammars ====================================================================== Pyparsing 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): .. testcode:: from 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: .. testoutput:: 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.parse_string` 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.set_results_name` - access the parsed data, which is returned as a :class:`ParseResults` object - find some helpful expression short-cuts like :class:`DelimitedList` and :class:`one_of` - find more useful common expressions in the :class:`pyparsing_common` namespace class ) NamedTuplec\eZdZUeed<eed<eed<eed<eed<edZdZdZ y ) version_infomajorminormicro releaselevelserialc|jd|jd|j|jddk(rdnd|jd|jdf|jdk(zS)N.rcrfinal)rrrr r selfs X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pyparsing/__init__.py __version__zversion_info.__version__nszzl!DJJt?P?PQR?S>TUYU`U`Tab7*, , c:td|jdtS)N z / )__name__r__version_time__rs r__str__zversion_info.__str__xs"1T--.c2B1CDDrc tdt|jddjdt|j|DdS)Nr (z, c3:K|]}dj|yw)z{}={!r}N)format).0nvs r z(version_info.__repr__..|s)*)__diag__ __compat__)_builtin_exprs) unicode_setUnicodeRangeListpyparsing_unicode)pyparsing_test)pyparsing_commonr6r9r;r:)rr __author__r5r4And AtLineStart AtStringStartCaselessKeywordCaselessLiteral CharsNotIn CloseMatchCombine DelimitedListDictEachEmpty FollowedByForward GoToColumnGroup IndentedBlockKeywordLineEnd LineStartLiteralLocated PrecededBy MatchFirstNoMatchNotAny OneOrMoreOnlyOnceOpAssocOptOptionalOrParseBaseExceptionParseElementEnhanceParseExceptionParseExpressionParseFatalException ParseResultsParseSyntaxException ParserElement PositionToken QuotedStringRecursiveGrammarExceptionRegexSkipTo StringEnd StringStartSuppressTagTokenTokenConverterWhiteWordWordEnd WordStart ZeroOrMoreChar alphanumsalphas alphas8bit any_close_tag any_open_tagautoname_elementsc_style_commentcolcommon_html_entitycondition_as_parse_action counted_arraycpp_style_commentdbl_quoted_stringdbl_slash_commentdelimited_listdict_ofemptyhexnums html_comment identcharsidentbodycharsinfix_notationjava_style_commentlineline_end line_startlinenomake_html_tags make_xml_tagsmatch_only_at_colmatch_previous_exprmatch_previous_literal nested_exprnull_debug_actionnumsone_oforiginal_text_for printablespunc8bitr;r:r9python_style_comment quoted_string remove_quotes replace_withreplace_html_entity rest_of_linesgl_quoted_stringsrange string_end string_start token_maptrace_parse_actionungroupr7unicode_stringwith_attribute with_class__versionTime__ anyCloseTag anyOpenTag cStyleCommentcommonHTMLEntityconditionAsParseAction countedArraycppStyleCommentdblQuotedStringdblSlashComment delimitedListdictOf htmlComment indentedBlock infixNotationjavaStyleCommentlineEnd lineStart locatedExpr makeHTMLTags makeXMLTagsmatchOnlyAtColmatchPreviousExprmatchPreviousLiteral nestedExprnullDebugActiononeOfopAssocoriginalTextForpythonStyleComment quotedString removeQuotesreplaceHTMLEntity replaceWith restOfLinesglQuotedString stringEnd stringStarttokenMaptraceParseAction unicodeString withAttribute withClasscommonunicodetestingN)__doc__typingrr__version_info__rrrr<util exceptionsactionscorer4r5resultsr6core_builtin_exprshelpershelper_builtin_exprsrr7r8r9rr:rr;common_builtin_exprsglobals__all__r.rrrs2J Vy:y0 1a!4*** " : &6;PP. gi'WY&79$N*-AAAi r