3
�Pf�k � @ s� d Z dZdZdZddlZddlmZ ddlZddl Z ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlmZ yddlmZ W n ek
r� ddlmZ Y nX ydd l
mZ W n> ek
r� ydd lmZ W n ek
r� dZY nX Y nX d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;dd?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrgiZee j�dds� Zed dskZe�r"e jZe Z!e"Z#e Z$e%e&e'e(e)ee*e+e,e-e.gZ/nbe j0Ze1Z2dtdu� Z$g Z/ddl3Z3xBdvj4� D ]6Z5ye/j6e7e3e5�� W n e8k
�r| �wJY nX �qJW e9dwdx� e2dy�D ��Z:dzd{� Z;G d|d}� d}e<�Z=ej>ej? Z@d~ZAeAd ZBe@eA ZCe"d��ZDd�jEd�dx� ejFD ��ZGG d�d!� d!eH�ZIG d�d#� d#eI�ZJG d�d%� d%eI�ZKG d�d'� d'eK�ZLG d�d*� d*eH�ZMG d�d�� d�e<�ZNG d�d&� d&e<�ZOe
jPjQeO� d�d=� ZRd�dN� ZSd�dK� ZTd�d�� ZUd�d�� ZVd�d�� ZWd�dU� ZX�d/d�d��ZYG d�d(� d(e<�ZZG d�d0� d0eZ�Z[G d�d� de[�Z\G d�d� de[�Z]G d�d� de[�Z^e^Z_e^eZ_`G d�d� de[�ZaG d�d� de^�ZbG d�d� dea�ZcG d�dp� dpe[�ZdG d�d3� d3e[�ZeG d�d+� d+e[�ZfG d�d)� d)e[�ZgG d�d
� d
e[�ZhG d�d2� d2e[�ZiG d�d�� d�e[�ZjG d�d� dej�ZkG d�d� dej�ZlG d�d� dej�ZmG d�d.� d.ej�ZnG d�d-� d-ej�ZoG d�d5� d5ej�ZpG d�d4� d4ej�ZqG d�d$� d$eZ�ZrG d�d
� d
er�ZsG d�d � d er�ZtG d�d� der�ZuG d�d� der�ZvG d�d"� d"eZ�ZwG d�d� dew�ZxG d�d� dew�ZyG d�d�� d�ew�ZzG d�d� dez�Z{G d�d6� d6ez�Z|G d�d�� d�e<�Z}e}� Z~G d�d� dew�ZG d�d,� d,ew�Z�G d�d� dew�Z�G d�d�� d�e��Z�G d�d1� d1ew�Z�G d�d� de��Z�G d�d� de��Z�G d�d� de��Z�G d�d/� d/e��Z�G d�d� de<�Z�d�df� Z��d0d�dD�Z��d1d�d@�Z�d�d΄ Z�d�dS� Z�d�dR� Z�d�d҄ Z��d2d�dW�Z�d�dE� Z��d3d�dk�Z�d�dl� Z�d�dn� Z�e\� j�dG�Z�el� j�dM�Z�em� j�dL�Z�en� j�de�Z�eo� j�dd�Z�eeeDd�d�d�j�d�d܄ �Z�efd݃j�d�d܄ �Z�efd߃j�d�d܄ �Z�e�e�B e�B eeeGd�dyd�B efd�ej��B Z�e�e�e�d� e� �Z�e^d�ed�j�d� e�e{e�e�B ��j�d� d� Z�d�dc� Z�d�dQ� Z�d�d`� Z�d�d^� Z�d�dq� Z�e�d�d܄ �Z�e�d�d܄ �Z�d�d� Z�d�dO� Z�d�dP� Z�d�di� Z�e<� e�_��d4d�do�Z�e=� Z�e<� e�_�e<� e�_�e�d��e�d��fd�dm�Z�e�Z�e�efd��d� �j�d��Z�e�efd��d� �j�d��Z�e�efd��d� efd��d� B �j��d �Z�e�e_�d�e�j� �j��d�Z�d�d�de�j� f�ddT�Z��d5�ddj�Z�e��d�Z�e��d�Z�e�eee@eC�d �j��d��\Z�Z�e�e��d j4� �d
��Z�ef�d�djEe�jà � �d
�j��d�Z�dd_� Z�e�ef�d��d �j��d�Z�ef�d�j��d�Z�ef�d�jȃ j��d�Z�ef�d�j��d�Z�e�ef�d��d e�B �j��d�Z�e�Z�ef�d�j��d�Z�e�e{eeeGd�d�eee�d�e^dɃ em� � ��j΃ j��d�Z�e�ee�j� e�B d��d��j�d>�Z�G �d dr� dr�Z�e�d!k�r�eb�d"�Z�eb�d#�Z�eee@eC�d$ �Z�e�e�d%d�d&�j�e��Z�e�e�eփ�j��d'�Z�d(e�B Z�e�e�d%d�d&�j�e��Z�e�e�eك�j��d)�Z�e�d*�e�d'� e� e�d)� Z�e�j�d+� e�j�j�d,� e�j�j�d,� e�j�j�d-� ddl�Z�e�j�j�e�e�j�� e�j�j�d.� dS (6 aS
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
C{", !"}), built up using L{Word}, L{Literal}, and L{And} elements
(L{'+'} operator gives L{And} expressions, strings are auto-converted to
L{Literal} expressions)::
from pyparsing import Word, alphas
# define grammar of a greeting
greet = Word(alphas) + "," + Word(alphas) + "!"
hello = "Hello, World!"
print (hello, "->", greet.parseString(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 '+', '|' and '^' operators.
The L{ParseResults} object returned from L{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
z2.1.10z07 Oct 2016 01:31 UTCz*Paul McGuire � N)�ref)�datetime)�RLock)�OrderedDict�And�CaselessKeyword�CaselessLiteral�
CharsNotIn�Combine�Dict�Each�Empty�
FollowedBy�Forward�
GoToColumn�Group�Keyword�LineEnd� LineStart�Literal�
MatchFirst�NoMatch�NotAny� OneOrMore�OnlyOnce�Optional�Or�ParseBaseException�ParseElementEnhance�ParseException�ParseExpression�ParseFatalException�ParseResults�ParseSyntaxException�
ParserElement�QuotedString�RecursiveGrammarException�Regex�SkipTo� StringEnd�StringStart�Suppress�Token�TokenConverter�White�Word�WordEnd� WordStart�
ZeroOrMore� alphanums�alphas�
alphas8bit�anyCloseTag�
anyOpenTag�
cStyleComment�col�commaSeparatedList�commonHTMLEntity�countedArray�cppStyleComment�dblQuotedString�dblSlashComment�
delimitedList�dictOf�downcaseTokens�empty�hexnums�htmlComment�javaStyleComment�line�lineEnd� lineStart�lineno�makeHTMLTags�makeXMLTags�matchOnlyAtCol�matchPreviousExpr�matchPreviousLiteral�
nestedExpr�nullDebugAction�nums�oneOf�opAssoc�operatorPrecedence�
printables�punc8bit�pythonStyleComment�quotedString�removeQuotes�replaceHTMLEntity�replaceWith�
restOfLine�sglQuotedString�srange� stringEnd�stringStart�traceParseAction�
unicodeString�upcaseTokens�
withAttribute�
indentedBlock�originalTextFor�ungroup�
infixNotation�locatedExpr� withClass�
CloseMatch�tokenMap�pyparsing_common� c C s` t | t�r| S yt| �S tk
rZ t| �jtj� d�}td�}|jdd� � |j |�S X dS )a Drop-in replacement for str(obj) that tries to be Unicode friendly. It first tries
str(obj). If that fails with a UnicodeEncodeError, then it tries unicode(obj). It
then < returns the unicode object | encodes it with the default encoding | ... >.
�xmlcharrefreplacez\d+;c S s$ dt t| d dd� ��dd � S )Nz\ur � � �����)�hex�int)�t� rw �/usr/lib/python3.6/pyparsing.py�� s z_ustr..N)
�
isinstanceZunicode�str�UnicodeEncodeError�encode�sys�getdefaultencodingr' �setParseAction�transformString)�obj�retZ
xmlcharrefrw rw rx �_ustr� s
r� z6sum len sorted reversed list tuple set any all min maxc c s | ]
}|V qd S )Nrw )�.0�yrw rw rx � � s r� rr c C s> d}dd� dj � D �}x"t||�D ]\}}| j||�} q"W | S )z/Escape &, <, >, ", ', etc. in a string of data.z&><"'c s s | ]}d | d V qdS )�&�;Nrw )r� �srw rw rx r� � s z_xml_escape..zamp gt lt quot apos)�split�zip�replace)�dataZfrom_symbolsZ
to_symbolsZfrom_Zto_rw rw rx �_xml_escape� s
r� c @ s e Zd ZdS )�
_ConstantsN)�__name__�
__module__�__qualname__rw rw rw rx r� � s r� �
0123456789ZABCDEFabcdef�\ � c c s | ]}|t jkr|V qd S )N)�stringZ
whitespace)r� �crw rw rx r� � s c @ sP e Zd ZdZddd�Zedd� �Zdd � Zd
d� Zdd
� Z ddd�Z
dd� ZdS )r z7base exception class for all parsing runtime exceptionsr Nc C s> || _ |d kr|| _d| _n|| _|| _|| _|||f| _d S )Nr� )�loc�msg�pstr�
parserElement�args)�selfr� r� r� �elemrw rw rx �__init__� s zParseBaseException.__init__c C s | |j |j|j|j�S )z�
internal factory method to simplify creating one type of ParseException
from another - avoids having __init__ signature conflicts among subclasses
)r� r� r� r� )�cls�perw rw rx �_from_exception� s z"ParseBaseException._from_exceptionc C sN |dkrt | j| j�S |dkr,t| j| j�S |dkrBt| j| j�S t|��dS )z�supported attributes by name are:
- lineno - returns the line number of the exception text
- col - returns the column number of the exception text
- line - returns the line containing the exception text
rJ r9 �columnrG N)r9 r� )rJ r� r� r9 rG �AttributeError)r� Zanamerw rw rx �__getattr__� s zParseBaseException.__getattr__c C s d| j | j| j| jf S )Nz"%s (at char %d), (line:%d, col:%d))r� r� rJ r� )r� rw rw rx �__str__� s zParseBaseException.__str__c C s t | �S )N)r� )r� rw rw rx �__repr__� s zParseBaseException.__repr__�>!