# module pyparsing.py
#
# Copyright (c) 2003-2018 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
C{"<salutation>, <addressee>!"}), built up using L{Word}, L{Literal}, and L{And} elements
(L{'+'<ParserElement.__add__>} 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<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 L{ParserElement} and L{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 L{Literal} and L{CaselessLiteral} classes
- construct character word-group expressions using the L{Word} class
- see how to create repetitive expressions using L{ZeroOrMore} and L{OneOrMore} classes
- use L{'+'<And>}, L{'|'<MatchFirst>}, L{'^'<Or>}, and L{'&'<Each>} operators to combine simple expressions into more complex ones
- associate names with your parsed results using L{ParserElement.setResultsName}
- find some helpful expression short-cuts like L{delimitedList} and L{oneOf}
- find more useful common expressions in the L{pyparsing_common} namespace class
"""
__version__ = "2.2.1"
__versionTime__ = "18 Sep 2018 00:49 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:
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
#~ 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',
'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',
]
system_version = tuple(sys.version_info)[:3]
PY_3 = system_version[0] == 3
if PY_3:
_MAX_INT = sys.maxsize
basestring = str
unichr = chr
_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 version, that can be used as parse actions
singleArgBuiltins = []
import __builtin__
for fname in "sum len sorted reversed list tuple set any all min max".split():
try:
singleArgBuiltins.append(getattr(__builtin__,fname))
except AttributeError:
continue
_generat
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Python版超市管理系统源代码,基于django+mysql,安装步骤 1、在mysql中创建名为demo_django_supermarket的数据库,修改config/setting.py中数据库用户及密码 2、pip install -r requirements 3、manage.py migrate
资源推荐
资源详情
资源评论
收起资源包目录
Python版超市管理系统源代码,基于django+mysql (2000个子文件)
python3.7 4.63MB
pip3.7 272B
Abidjan 148B
Accra 148B
Acre 628B
ACT 2KB
activate 2KB
Adak 2KB
Addis_Ababa 265B
Adelaide 2KB
Aden 165B
Alaska 2KB
Aleutian 2KB
Algiers 735B
Almaty 997B
Amman 2KB
Amsterdam 3KB
Anadyr 1KB
Anchorage 2KB
Andorra 2KB
Anguilla 246B
Antananarivo 265B
Antigua 246B
Apia 612B
Aqtau 983B
Aqtobe 1011B
Araguaina 884B
Arizona 328B
Aruba 246B
Ashgabat 619B
Ashkhabad 619B
Asmara 265B
Asmera 265B
styles.css 153KB
bootstrap.css 138KB
style.css 61KB
fontawesome-all.css 41KB
fontawesome.css 40KB
font-awesome.css 34KB
fontawesome-all.min.css 33KB
fontawesome.min.css 32KB
silder-style.css 26KB
responsive.css 18KB
select2.css 17KB
base.css 16KB
select2.min.css 15KB
simple-line-icons.css 13KB
widgets.css 10KB
owl.carousel.css 9KB
forms.css 8KB
autocomplete.css 8KB
changelists.css 6KB
skdslider.css 6KB
styles.css 5KB
rtl.css 4KB
responsive_rtl.css 2KB
jq22-demo.css 2KB
tooltip.css 1KB
css.css 1KB
login.css 1KB
fa-regular.css 703B
fa-solid.css 696B
fa-brands.css 684B
ol3.css 657B
fa-regular.min.css 648B
fa-solid.min.css 640B
fa-brands.min.css 630B
fonts.css 423B
dashboard.css 412B
b_css.css 257B
purchase.html 33KB
technical_500.html 17KB
default_urlconf.html 16KB
index.html 14KB
base.html 11KB
goods.html 10KB
sale.html 9KB
storage.html 8KB
all.html 7KB
dashboard.html 7KB
record.html 7KB
account_more.html 5KB
account_all.html 5KB
tabular.html 4KB
provider.html 4KB
login.html 4KB
detail.html 4KB
base.html 4KB
about.html 4KB
index.html 3KB
change_form.html 3KB
change_list.html 3KB
messages.html 3KB
technical_404.html 2KB
delete_confirmation.html 2KB
stacked.html 2KB
send_note.html 2KB
change_password.html 2KB
delete_selected_confirmation.html 2KB
profile.html 2KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
Python代码大全
- 粉丝: 2858
- 资源: 686
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 近2年双色球历史开奖号码合集(20230101~20241128)
- 基于小程序的校园外卖平台设计与实现源代码(java+小程序+mysql+LW).zip
- 基于GD32的CAN通信.zip
- 城市轨道交通装备产品认证实施规则-城市轨道交通车辆 CNCA CURC-02-2019
- 科研伦理与学术规范:保障科研诚信的关键
- QWT6.3.0更加适配QT程序
- 城市轨道交通装备产品认证实施规则-通用要求CNCA CURC-01-2019
- 基于AHP和层次马尔可夫决策的动态QoS感知服务组合框架的Python实现
- 基于GD32的RTC实时时钟.zip
- V90 EPOS FB284反馈的速度值怎么做标定转换.mp4
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页