#-*- coding: utf-8 -*-
# module pyparsing.py
#
# Copyright (c) 2003-2019 Paul T. McGuire
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
__doc__ = \
"""
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
``"<salutation>, <addressee>!"``), built up using :class:`Word`,
:class:`Literal`, and :class:`And` elements
(the :class:`'+'<ParserElement.__add__>` 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.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 :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:`'+'<And>`, :class:`'|'<MatchFirst>`, :class:`'^'<Or>`,
and :class:`'&'<Each>` operators to combine simple expressions into
more complex ones
- associate names with your parsed results using
:class:`ParserElement.setResultsName`
- find some helpful expression short-cuts like :class:`delimitedList`
and :class:`oneOf`
- find more useful common expressions in the :class:`pyparsing_common`
namespace class
"""
__version__ = "2.3.1"
__versionTime__ = "09 Jan 2019 23:26 UTC"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
from weakref import ref as wkref
import copy
import sys
import warnings
import re
import sre_constants
import collections
import pprint
import traceback
import types
from datetime import datetime
try:
# Python 3
from itertools import filterfalse
except ImportError:
from itertools import ifilterfalse as filterfalse
try:
from _thread import RLock
except ImportError:
from threading import RLock
try:
# Python 3
from collections.abc import Iterable
from collections.abc import MutableMapping
except ImportError:
# Python 2.7
from collections import Iterable
from collections import MutableMapping
try:
from collections import OrderedDict as _OrderedDict
except ImportError:
try:
from ordereddict import OrderedDict as _OrderedDict
except ImportError:
_OrderedDict = None
try:
from types import SimpleNamespace
except ImportError:
class SimpleNamespace: pass
#~ sys.stderr.write( "testing pyparsing module, version %s, %s\n" % (__version__,__versionTime__ ) )
__all__ = [
'And', 'CaselessKeyword', 'CaselessLiteral', 'CharsNotIn', 'Combine', 'Dict', 'Each', 'Empty',
'FollowedBy', 'Forward', 'GoToColumn', 'Group', 'Keyword', 'LineEnd', 'LineStart', 'Literal',
'PrecededBy', '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', 'Char',
'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', 'pyparsing_unicode', 'unicode_set',
]
system_version = tuple(sys.version_info)[:3]
PY_3 = system_version[0] == 3
if PY_3:
_MAX_INT = sys.maxsize
basestring = str
unichr = chr
unicode = str
_ustr = str
# build list of single arg builtins, that can be used as parse actions
singleArgBuiltins = [sum, len, sorted, reversed, list, tuple, set, any, all, min, max]
else:
_MAX_INT = sys.maxint
range = xrange
def _ustr(obj):
"""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 | ... >.
"""
if isinstance(obj,unicode):
return obj
try:
# If this works, then _ustr(obj) has the same behaviour as str(obj), so
# it won't break any existing code.
return str(obj)
except UnicodeEncodeError:
# Else encode it
ret = unicode(obj).encode(sys.getdefaultencoding(), 'xmlcharrefreplace')
xmlcharref = Regex(r'&#\d+;')
xmlcharref.setParseAction(lambda t: '\\u' + hex(int(t[0][2:-1]))[2:])
return xmlcharref.transformString(ret)
# build list of single arg builtins, tolerant of Python ver
天天501
- 粉丝: 626
- 资源: 5904
最新资源
- 基于滑模观测器的无位置传感器永磁同步电机驱动控制系统仿真研究,基于滑模观测器的无位置传感器PMSM驱动控制系统仿真 ,核心关键词:滑模观测器; 无位置传感器; PMSM驱动控制; 系统仿真;,无位置传
- 基于二阶锥规划的主动配电网动态重构研究:单时段与多时段重构策略,以网络损耗最低为目标,采用SOCP模型求解潮流,MATLAB YALMIP+CPLEX仿真实现,详实注释,助力学习理解 ,MATLAB代
- 大功率四轮电动车控制器源代码及原理图与PCB板设计:全面解析与应用指南,大功率四轮电动车控制器代码, 原理图和Pcb,完整可用 ,核心关键词:大功率四轮电动车控制器代码; 原理图; Pcb; 完
- Labview与西门子PLC Smart 200全套项目资料:包含OPC通讯、串口通讯、电气原理及元器件清单,labview+PLC程序+OPC完整项目程序Labview和西门子PLC smart20
- libldb-devel-1.5.4-2.el7.x64-86.rpm.tar.gz
- 昆仑通态MCGS与台达ASD-B2伺服通讯控制教程:触摸屏操作驱动器速度设置与扭矩限制功能实现,昆仑通态MCGS与台达伺服ASD-B2 通讯控制案例功能:通过昆仑通态MCGS触摸屏实现与台达ASD
- STM32F103系列离线下载器制作指南:源程序、电路图与PCB图全套详解,STM32F103系列离线下载器制作,包括源程序、电路图和PCB图都有全套 ,STM32F103系列; 离线下载器; 源程序
- Qt开发上位机:基于固高八轴运动控制卡与海康威视相机的喷码机源码,实现光学点定位与二维码读码等级评测功能的多语言多样化控制 ,Qt开发的上位机 源码 硬件:固高八轴运动控制卡,海康威视相机,喷码机 功
- BP神经网络在数据分类预测与故障信号诊断中的应用:Matlab代码实现及结果详解,BP神经网络的数据分类预测和故障信号诊断分类matlab代码 ,直接运行出数据分类结果和误差分布,注释详细易读懂
- 高性能Foc电机控制方案应用于电动两轮车领域:成熟方案、功能全面、基于国产芯片、直观调试与波形显示,量产大厂成熟Foc电机控制代于电动自行车,滑板 车,电机Foc控制等 大厂成熟方案,直接可用,,不
- "750W高PF值充电机电源方案:UCC28070等芯片组合,原理图与资料全解析",750W高PF值充电机用电源方案 ;输出50V 15A 釆用UCC28070+ST6599+PIC16F193X芯片
- Modbus RTU通讯在西门子S7 PLC主站实现方法:RS485总线下TIA博图SCL源码轻松读写30从站数据,Modbus RTU通讯S7-1200主站程序 RS4585总线通讯 TIA博图
- Allegro PCB封装库:类型齐全,命名规范,分类管理,经验验证,附3D模型,高效查找,Allegro PCB封装库(分类、命名很规范,已验证) 该PCB库特点一:类型齐全,包含有阻容感分立元器件
- COMSOL多场耦合分析原油脱水模型:探讨电-磁场影响双液滴聚结行为及关键因素分析,[COMSOL原油脱水模型]采用流体场和电-磁场相耦合的方法研究外加交流电场情况下原油乳化液中双液滴的聚结行为,分析
- 基于EKF滤波的Carsim与Simulink联合仿真:汽车横摆角速度、车速及质心侧偏角的滤波估计效果研究,carsim与Simulink联合仿真 基于EKF滤波对汽车横摆角速度,车速和质心侧偏角滤波
- 三菱FX系列模拟量与数字量FB函数块标准化设计:高效可重复调用的工程化编程实践,三菱FX3U模拟量FB函数块,使用结构化工程编写,FB块全部用ST语言编写,支持重复调用 现在测试FX3U4DA FB
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈