| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Namespace List
- Namespace Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Functions | Variables
pyparsing Namespace Reference

## Classes
class | _Constants
class | ParseBaseException
class | ParseException
class | ParseFatalException
class | ParseSyntaxException
class | RecursiveGrammarException
class | _ParseResultsWithOffset
class | ParseResults
class | ParserElement
class | Token
class | Empty
class | NoMatch
class | Literal
class | Keyword
class | CaselessLiteral
class | CaselessKeyword
class | Word
class | Regex
class | QuotedString
class | CharsNotIn
class | White
class | _PositionToken
class | GoToColumn
class | LineStart
class | LineEnd
class | StringStart
class | StringEnd
class | WordStart
class | WordEnd
class | ParseExpression
class | And
class | Or
class | MatchFirst
class | Each
class | ParseElementEnhance
class | FollowedBy
class | NotAny
class | ZeroOrMore
class | OneOrMore
class | _NullToken
class | Optional
class | SkipTo
class | Forward
class | _ForwardNoRecurse
class | TokenConverter
class | Upcase
class | Combine
class | Group
class | Dict
class | Suppress
class | OnlyOnce

## Functions
def | _ustr
def | _str2dict
def | _xml_escape
def | col
def | lineno
def | line
def | _defaultStartDebugAction
def | _defaultSuccessDebugAction
def | _defaultExceptionDebugAction
def | nullDebugAction
def | traceParseAction
def | delimitedList
def | countedArray
def | _flatten
def | matchPreviousLiteral
def | matchPreviousExpr
def | _escapeRegexRangeChars
def | oneOf
def | dictOf
def | originalTextFor
def | srange
def | matchOnlyAtCol
def | replaceWith
def | removeQuotes
def | upcaseTokens
def | downcaseTokens
def | keepOriginalText
def | getTokensEndLoc
def | _makeTags
def | makeHTMLTags
def | makeXMLTags
def | withAttribute
def | operatorPrecedence

## Variables
| __doc__ \
string | __version__ "1.5.2"
string | __versionTime__ "17 February 2009 19:45"
string | __author__ "Paul McGuire <ptmcg@users.sourceforge.net>"
list | __all__
| _PY3K True
| _MAX_INT sys.maxsize
| basestring str
| _ustr str
| unichr chr
| _str2dict set
| alphas string.lowercase+string.uppercase
| nums string.digits
string | hexnums "ABCDEFabcdef"
| alphanums alphas+nums
tuple | _bslash chr(92)
string | printables ""
| _L Literal
tuple | _optionalNotMatched _NullToken()
tuple | empty Empty()
tuple | lineStart LineStart()
tuple | lineEnd LineEnd()
tuple | stringStart StringStart()
tuple | stringEnd StringEnd()
tuple | _escapedPunc Word( _bslash, r"\[]-*.$+^?()~ ", exact=2 )
string | _printables_less_backslash ""
tuple | _escapedHexChar Combine( Suppress(_bslash + "0x") + Word(hexnums) )
tuple | _escapedOctChar Combine( Suppress(_bslash) + Word("0","01234567") )
tuple | _singleChar _escapedPunc|_escapedHexChar|_escapedOctChar|Word(_printables_less_backslash,exact=1)
tuple | _charRange Group(_singleChar + Suppress("-") + _singleChar)
tuple | _reBracketExpr Literal("[")
tuple | _expanded lambdap:(isinstance(p,ParseResults) and ''.join([ unichr(c) for c in range(ord(p[0]),ord(p[1])+1) ]) or p)
tuple | opAssoc _Constants()
tuple | dblQuotedString Regex(r'"(?:[^"\n\r\\]|(?:"")|(?:\\x[0-9a-fA-F]+)|(?:\\.))

## Function Documentation

def pyparsing._defaultExceptionDebugAction | ( |  | instring,
|  |  | loc,
|  |  | expr,
|  |  | exc
| ) |  |
| private

Definition at line 659 of file pyparsing.py.

659
660 def _defaultExceptionDebugAction( instring, loc, expr, exc ):
661 print ("Exception raised:" + _ustr(exc))

def pyparsing._defaultStartDebugAction | ( |  | instring,
|  |  | loc,
|  |  | expr
| ) |  |
| private

Definition at line 653 of file pyparsing.py.

653
654 def _defaultStartDebugAction( instring, loc, expr ):
655 print ("Match " + _ustr(expr) + " at loc " + _ustr(loc) + "(%d,%d)" % ( lineno(loc,instring), col(loc,instring) ))

def pyparsing._defaultSuccessDebugAction | ( |  | instring,
|  |  | startloc,
|  |  | endloc,
|  |  | expr,
|  |  | toks
| ) |  |
| private

Definition at line 656 of file pyparsing.py.

656
657 def _defaultSuccessDebugAction( instring, startloc, endloc, expr, toks ):
658 print ("Matched " + _ustr(expr) + " -> " + str(toks.asList()))

def pyparsing._escapeRegexRangeChars | ( |  | s | ) |
| private

Definition at line 3189 of file pyparsing.py.

3189
3190 def _escapeRegexRangeChars(s):
3191 #~ escape these chars: ^-]
3192 for c in r"\^-]":
3193 s = s.replace(c,_bslash+c)
3194 s = s.replace("\n",r"\n")
3195 s = s.replace("\t",r"\t")
3196 return _ustr(s)

def pyparsing._flatten | ( |  | L | ) |
| private

Definition at line 3132 of file pyparsing.py.

3132
3133 def _flatten(L):
3134 if type(L) is not list: return [L]
3135 if L == []: return L
3136 return _flatten(L[0]) + _flatten(L[1:])

def pyparsing._makeTags | ( |  | tagStr,
|  |  | xml
| ) |  |
| private

    Internal helper to construct opening and closing tag expressions, given a tag name

Definition at line 3390 of file pyparsing.py.

3390
3391 def _makeTags(tagStr, xml):
3392 """Internal helper to construct opening and closing tag expressions, given a tag name"""
3393 if isinstance(tagStr,basestring):
3394 resname = tagStr
3395 tagStr = Keyword(tagStr, caseless=not xml)
3396 else:
3397 resname = tagStr.name
3398
3399 tagAttrName = Word(alphas,alphanums+"_-:")
3400 if (xml):
3401 tagAttrValue = dblQuotedString.copy().setParseAction( removeQuotes )
3402 openTag = Suppress("<") + tagStr + \
3403 Dict(ZeroOrMore(Group( tagAttrName + Suppress("=") + tagAttrValue ))) + \
3404 Optional("/",default=[False]).setResultsName("empty").setParseAction(lambda s,l,t:t[0]=='/') + Suppress(">")
3405 else:
3406 printablesLessRAbrack = "".join( [ c for c in printables if c not in ">" ] )
3407 tagAttrValue = quotedString.copy().setParseAction( removeQuotes ) | Word(printablesLessRAbrack)
3408 openTag = Suppress("<") + tagStr + \
3409 Dict(ZeroOrMore(Group( tagAttrName.setParseAction(downcaseTokens) + \
3410 Optional( Suppress("=") + tagAttrValue ) ))) + \
3411 Optional("/",default=[False]).setResultsName("empty").setParseAction(lambda s,l,t:t[0]=='/') + Suppress(">")
3412 closeTag = Combine(_L("</") + tagStr + ">")
3413
3414 openTag = openTag.setResultsName("start"+"".join(resname.replace(":"," ").title().split())).setName("<%s>" % tagStr)
3415 closeTag = closeTag.setResultsName("end"+"".join(resname.replace(":"," ").title().split())).setName("</%s>" % tagStr)
3416
3417 return openTag, closeTag

def pyparsing._str2dict | ( |  | strg | ) |
| private

Definition at line 139 of file pyparsing.py.

139
140 def _str2dict(strg):
141 return dict( [(c,0) for c in strg] )
else:

def pyparsing._ustr | ( |  | obj | ) |
| private

    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 | ... >.

Definition at line 108 of file pyparsing.py.

108
109 def _ustr(obj):
110 """Drop-in replacement for str(obj) that tries to be Unicode friendly. It first tries
111 str(obj). If that fails with a UnicodeEncodeError, then it tries unicode(obj). It
112 then < returns the unicode object | encodes it with the default encoding | ... >.
113 """
114 if isinstance(obj,unicode):
115 return obj
116
117 try:
118 # If this works, then _ustr(obj) has the same behaviour as str(obj), so
119 # it won't break any existing code.
120 return str(obj)
121
122 except UnicodeEncodeError:
123 # The Python docs (http://docs.python.org/ref/customization.html#l2h-182)
124 # state that "The return value must be a string object". However, does a
125 # unicode object (being a subclass of basestring) count as a "string
126 # object"?
127 # If so, then return a unicode object:
128 return unicode(obj)
129 # Else encode it... but how? There are many choices... :)
130 # Replace unprintables with escape codes?
131 #return unicode(obj).encode(sys.getdefaultencoding(), 'backslashreplace_errors')
132 # Replace unprintables with question marks?
133 #return unicode(obj).encode(sys.getdefaultencoding(), 'replace')
134 # ...
else:

def pyparsing._xml_escape | ( |  | data | ) |
| private

    Escape &, <, >, ", ', etc. in a string of data.

Definition at line 144 of file pyparsing.py.

144
145 def _xml_escape(data):
146 """Escape &, <, >, ", ', etc. in a string of data."""
147
148 # ampersand must be replaced first
149 from_symbols = '&><"\''
150 to_symbols = ['&'+s+';' for s in "amp gt lt quot apos".split()]
151 for from_,to_ in zip(from_symbols, to_symbols):
152 data = data.replace(from_, to_)
153 return data

def pyparsing.col | ( |  | loc,
|  |  | strg
| ) |  |

    Returns current column within a string, counting newlines as line separators.
       The first column is number 1.

       Note: the default parsing behavior is to expand tabs in the input string
       before starting the parsing process.  See L{I{ParserElement.parseString}<ParserElement.parseString>} for more information
       on parsing strings containing <TAB>s, and suggested methods to maintain a
       consistent view of the parsed string, the parse location, and line and column
       positions within the parsed string.

Definition at line 619 of file pyparsing.py.

619
620 def col (loc,strg):
621 """Returns current column within a string, counting newlines as line separators.
622 The first column is number 1.
623
624 Note: the default parsing behavior is to expand tabs in the input string
625 before starting the parsing process. See L{I{ParserElement.parseString}<ParserElement.parseString>} for more information
626 on parsing strings containing <TAB>s, and suggested methods to maintain a
627 consistent view of the parsed string, the parse location, and line and column
628 positions within the parsed string.
629 """
630 return (loc<len(strg) and strg[loc] == '\n') and 1 or loc - strg.rfind("\n", 0, loc)

def pyparsing.countedArray | ( |  | expr | ) |

    Helper to define a counted list of expressions.
       This helper defines a pattern of the form::
           integer expr expr expr...
       where the leading integer tells how many expr expressions follow.
       The matched tokens returns the array of expr tokens as a list - the leading count token is suppressed.

Definition at line 3118 of file pyparsing.py.

3118
3119 def countedArray( expr ):
3120 """Helper to define a counted list of expressions.
3121 This helper defines a pattern of the form::
3122 integer expr expr expr...
3123 where the leading integer tells how many expr expressions follow.
3124 The matched tokens returns the array of expr tokens as a list - the leading count token is suppressed.
3125 """
3126 arrayExpr = Forward()
3127 def countFieldParseAction(s,l,t):
3128 n = int(t[0])
3129 arrayExpr << (n and Group(And([expr]*n)) or Group(empty))
3130 return []
3131 return ( Word(nums).setName("arrayLen").setParseAction(countFieldParseAction, callDuringTry=True) + arrayExpr )

def pyparsing.delimitedList | ( |  | expr,
|  |  | delim = `"`,
|  |  | combine = `False`
| ) |  |

    Helper to define a delimited list of expressions - the delimiter defaults to ','.
       By default, the list elements and delimiters can have intervening whitespace, and
       comments, but this can be overridden by passing 'combine=True' in the constructor.
       If combine is set to True, the matching tokens are returned as a single token
       string, with the delimiters included; otherwise, the matching tokens are returned
       as a list of tokens, with the delimiters suppressed.

Definition at line 3104 of file pyparsing.py.

3104
3105 def delimitedList( expr, delim=",", combine=False ):
3106 """Helper to define a delimited list of expressions - the delimiter defaults to ','.
3107 By default, the list elements and delimiters can have intervening whitespace, and
3108 comments, but this can be overridden by passing 'combine=True' in the constructor.
3109 If combine is set to True, the matching tokens are returned as a single token
3110 string, with the delimiters included; otherwise, the matching tokens are returned
3111 as a list of tokens, with the delimiters suppressed.
3112 """
3113 dlName = _ustr(expr)+" ["+_ustr(delim)+" "+_ustr(expr)+"]..."
3114 if combine:
3115 return Combine( expr + ZeroOrMore( delim + expr ) ).setName(dlName)
3116 else:
3117 return ( expr + ZeroOrMore( Suppress( delim ) + expr ) ).setName(dlName)

def pyparsing.dictOf | ( |  | key,
|  |  | value
| ) |  |

    Helper to easily and clearly define a dictionary by specifying the respective patterns
       for the key and value.  Takes care of defining the Dict, ZeroOrMore, and Group tokens
       in the proper order.  The key pattern can include delimiting markers or punctuation,
       as long as they are suppressed, thereby leaving the significant key text.  The value
       pattern can include named results, so that the Dict results can include named token
       fields.

Definition at line 3256 of file pyparsing.py.

3256
3257 def dictOf( key, value ):
3258 """Helper to easily and clearly define a dictionary by specifying the respective patterns
3259 for the key and value. Takes care of defining the Dict, ZeroOrMore, and Group tokens
3260 in the proper order. The key pattern can include delimiting markers or punctuation,
3261 as long as they are suppressed, thereby leaving the significant key text. The value
3262 pattern can include named results, so that the Dict results can include named token
3263 fields.
3264 """
3265 return Dict( ZeroOrMore( Group ( key + value ) ) )

def pyparsing.downcaseTokens | ( |  | s,
|  |  | l,
|  |  | t
| ) |  |

    Helper parse action to convert tokens to lower case.

Definition at line 3359 of file pyparsing.py.

3359
3360 def downcaseTokens(s,l,t):
3361 """Helper parse action to convert tokens to lower case."""
3362 return [ tt.lower() for tt in map(_ustr,t) ]

def pyparsing.getTokensEndLoc | ( |  | ) |

    Method to be called from within a parse action to determine the end
       location of the parsed tokens.

Definition at line 3374 of file pyparsing.py.

3374
3375 def getTokensEndLoc():
3376 """Method to be called from within a parse action to determine the end
3377 location of the parsed tokens."""
3378 import inspect
3379 fstack = inspect.stack()
3380 try:
3381 # search up the stack (through intervening argument normalizers) for correct calling routine
3382 for f in fstack[2:]:
3383 if f[3] == "_parseNoCache":
3384 endloc = f[0].f_locals["loc"]
3385 return endloc
3386 else:
3387 raise ParseFatalException("incorrect usage of getTokensEndLoc - may only be called from within a parse action")
3388 finally:
3389 del fstack

def pyparsing.keepOriginalText | ( |  | s,
|  |  | startLoc,
|  |  | t
| ) |  |

    Helper parse action to preserve original parsed text,
       overriding any nested parse actions.

Definition at line 3363 of file pyparsing.py.

3363
3364 def keepOriginalText(s,startLoc,t):
3365 """Helper parse action to preserve original parsed text,
3366 overriding any nested parse actions."""
3367 try:
3368 endloc = getTokensEndLoc()
3369 except ParseException:
3370 raise ParseFatalException("incorrect usage of keepOriginalText - may only be called as a parse action")
3371 del t[:]
3372 t += ParseResults(s[startLoc:endloc])
3373 return t

def pyparsing.line | ( |  | loc,
|  |  | strg
| ) |  |

    Returns the line of text containing loc within a string, counting newlines as line separators.

Definition at line 643 of file pyparsing.py.

643
644 def line( loc, strg ):
645 """Returns the line of text containing loc within a string, counting newlines as line separators.
646 """
647 lastCR = strg.rfind("\n", 0, loc)
648 nextCR = strg.find("\n", loc)
649 if nextCR > 0:
650 return strg[lastCR+1:nextCR]
651 else:
652 return strg[lastCR+1:]

def pyparsing.lineno | ( |  | loc,
|  |  | strg
| ) |  |

    Returns current line number within a string, counting newlines as line separators.
       The first line is number 1.

       Note: the default parsing behavior is to expand tabs in the input string
       before starting the parsing process.  See L{I{ParserElement.parseString}<ParserElement.parseString>} for more information
       on parsing strings containing <TAB>s, and suggested methods to maintain a
       consistent view of the parsed string, the parse location, and line and column
       positions within the parsed string.

Definition at line 631 of file pyparsing.py.

631
632 def lineno(loc,strg):
633 """Returns current line number within a string, counting newlines as line separators.
634 The first line is number 1.
635
636 Note: the default parsing behavior is to expand tabs in the input string
637 before starting the parsing process. See L{I{ParserElement.parseString}<ParserElement.parseString>} for more information
638 on parsing strings containing <TAB>s, and suggested methods to maintain a
639 consistent view of the parsed string, the parse location, and line and column
640 positions within the parsed string.
641 """
642 return strg.count("\n",0,loc) + 1

def pyparsing.makeHTMLTags | ( |  | tagStr | ) |

    Helper to construct opening and closing tag expressions for HTML, given a tag name

Definition at line 3418 of file pyparsing.py.

3418
3419 def makeHTMLTags(tagStr):
3420 """Helper to construct opening and closing tag expressions for HTML, given a tag name"""
3421 return _makeTags( tagStr, False )

def pyparsing.makeXMLTags | ( |  | tagStr | ) |

    Helper to construct opening and closing tag expressions for XML, given a tag name

Definition at line 3422 of file pyparsing.py.

3422
3423 def makeXMLTags(tagStr):
3424 """Helper to construct opening and closing tag expressions for XML, given a tag name"""
3425 return _makeTags( tagStr, True )

def pyparsing.matchOnlyAtCol | ( |  | n | ) |

    Helper method for defining parse actions that require matching at a specific
       column in the input text.

Definition at line 3331 of file pyparsing.py.

3331
3332 def matchOnlyAtCol(n):
3333 """Helper method for defining parse actions that require matching at a specific
3334 column in the input text.
3335 """
3336 def verifyCol(strg,locn,toks):
3337 if col(locn,strg) != n:
3338 raise ParseException(strg,locn,"matched token not at column %d" % n)
3339 return verifyCol

def pyparsing.matchPreviousExpr | ( |  | expr | ) |

    Helper to define an expression that is indirectly defined from
       the tokens matched in a previous expression, that is, it looks
       for a 'repeat' of a previous expression.  For example::
           first = Word(nums)
           second = matchPreviousExpr(first)
           matchExpr = first + ":" + second
       will match "1:1", but not "1:2".  Because this matches by
       expressions, will *not* match the leading "1:1" in "1:10";
       the expressions are evaluated first, and then compared, so
       "1" is compared with "10".
       Do *not* use with packrat parsing enabled.

Definition at line 3163 of file pyparsing.py.

3163
3164 def matchPreviousExpr(expr):
3165 """Helper to define an expression that is indirectly defined from
3166 the tokens matched in a previous expression, that is, it looks
3167 for a 'repeat' of a previous expression. For example::
3168 first = Word(nums)
3169 second = matchPreviousExpr(first)
3170 matchExpr = first + ":" + second
3171 will match "1:1", but not "1:2". Because this matches by
3172 expressions, will *not* match the leading "1:1" in "1:10";
3173 the expressions are evaluated first, and then compared, so
3174 "1" is compared with "10".
3175 Do *not* use with packrat parsing enabled.
3176 """
3177 rep = Forward()
3178 e2 = expr.copy()
3179 rep << e2
3180 def copyTokenToRepeater(s,l,t):
3181 matchTokens = _flatten(t.asList())
3182 def mustMatchTheseTokens(s,l,t):
3183 theseTokens = _flatten(t.asList())
3184 if theseTokens != matchTokens:
3185 raise ParseException("",0,"")
3186 rep.setParseAction( mustMatchTheseTokens, callDuringTry=True )
3187 expr.addParseAction(copyTokenToRepeater, callDuringTry=True)
3188 return rep

def pyparsing.matchPreviousLiteral | ( |  | expr | ) |

    Helper to define an expression that is indirectly defined from
       the tokens matched in a previous expression, that is, it looks
       for a 'repeat' of a previous expression.  For example::
           first = Word(nums)
           second = matchPreviousLiteral(first)
           matchExpr = first + ":" + second
       will match "1:1", but not "1:2".  Because this matches a
       previous literal, will also match the leading "1:1" in "1:10".
       If this is not desired, use matchPreviousExpr.
       Do *not* use with packrat parsing enabled.

Definition at line 3137 of file pyparsing.py.

3137
3138 def matchPreviousLiteral(expr):
3139 """Helper to define an expression that is indirectly defined from
3140 the tokens matched in a previous expression, that is, it looks
3141 for a 'repeat' of a previous expression. For example::
3142 first = Word(nums)
3143 second = matchPreviousLiteral(first)
3144 matchExpr = first + ":" + second
3145 will match "1:1", but not "1:2". Because this matches a
3146 previous literal, will also match the leading "1:1" in "1:10".
3147 If this is not desired, use matchPreviousExpr.
3148 Do *not* use with packrat parsing enabled.
3149 """
3150 rep = Forward()
3151 def copyTokenToRepeater(s,l,t):
3152 if t:
3153 if len(t) == 1:
3154 rep << t[0]
3155 else:
3156 # flatten t tokens
3157 tflat = _flatten(t.asList())
3158 rep << And( [ Literal(tt) for tt in tflat ] )
3159 else:
3160 rep << Empty()
3161 expr.addParseAction(copyTokenToRepeater, callDuringTry=True)
3162 return rep

def pyparsing.nullDebugAction | ( |  | args | ) |

    'Do-nothing' debug action, to suppress debugging output during parsing.

Definition at line 662 of file pyparsing.py.

662
663 def nullDebugAction(*args):
664 """'Do-nothing' debug action, to suppress debugging output during parsing."""
665 pass

def pyparsing.oneOf | ( |  | strs,
|  |  | caseless = `False`,
|  |  | useRegex = `True`
| ) |  |

    Helper to quickly define a set of alternative Literals, and makes sure to do
       longest-first testing when there is a conflict, regardless of the input order,
       but returns a MatchFirst for best performance.

       Parameters:
        - strs - a string of space-delimited literals, or a list of string literals
        - caseless - (default=False) - treat all literals as caseless
        - useRegex - (default=True) - as an optimization, will generate a Regex
          object; otherwise, will generate a MatchFirst object (if caseless=True, or
          if creating a Regex raises an exception)

Definition at line 3197 of file pyparsing.py.

3197
3198 def oneOf( strs, caseless=False, useRegex=True ):
3199 """Helper to quickly define a set of alternative Literals, and makes sure to do
3200 longest-first testing when there is a conflict, regardless of the input order,
3201 but returns a MatchFirst for best performance.
3202
3203 Parameters:
3204 - strs - a string of space-delimited literals, or a list of string literals
3205 - caseless - (default=False) - treat all literals as caseless
3206 - useRegex - (default=True) - as an optimization, will generate a Regex
3207 object; otherwise, will generate a MatchFirst object (if caseless=True, or
3208 if creating a Regex raises an exception)
3209 """
3210 if caseless:
3211 isequal = ( lambda a,b: a.upper() == b.upper() )
3212 masks = ( lambda a,b: b.upper().startswith(a.upper()) )
3213 parseElementClass = CaselessLiteral
3214 else:
3215 isequal = ( lambda a,b: a == b )
3216 masks = ( lambda a,b: b.startswith(a) )
3217 parseElementClass = Literal
3218
3219 if isinstance(strs,(list,tuple)):
3220 symbols = list(strs[:])
3221 elif isinstance(strs,basestring):
3222 symbols = strs.split()
3223 else:
3224 warnings.warn("Invalid argument to oneOf, expected string or list",
3225 SyntaxWarning, stacklevel=2)
3226
3227 i = 0
3228 while i < len(symbols)-1:
3229 cur = symbols[i]
3230 for j,other in enumerate(symbols[i+1:]):
3231 if ( isequal(other, cur) ):
3232 del symbols[i+j+1]
3233 break
3234 elif ( masks(cur, other) ):
3235 del symbols[i+j+1]
3236 symbols.insert(i,other)
3237 cur = other
3238 break
3239 else:
3240 i += 1
3241
3242 if not caseless and useRegex:
3243 #~ print (strs,"->", "|".join( [ _escapeRegexChars(sym) for sym in symbols] ))
3244 try:
3245 if len(symbols)==len("".join(symbols)):
3246 return Regex( "[%s]" % "".join( [ _escapeRegexRangeChars(sym) for sym in symbols] ) )
3247 else:
3248 return Regex( "|".join( [ re.escape(sym) for sym in symbols] ) )
3249 except:
3250 warnings.warn("Exception creating Regex for oneOf, building MatchFirst",
3251 SyntaxWarning, stacklevel=2)
3252
3253
3254 # last resort, just use MatchFirst
3255 return MatchFirst( [ parseElementClass(sym) for sym in symbols ] )

def pyparsing.operatorPrecedence | ( |  | baseExpr,
|  |  | opList
| ) |  |

    Helper method for constructing grammars of expressions made up of
       operators working in a precedence hierarchy.  Operators may be unary or
       binary, left- or right-associative.  Parse actions can also be attached
       to operator expressions.

       Parameters:
        - baseExpr - expression representing the most basic element for the nested
        - opList - list of tuples, one for each operator precedence level in the
          expression grammar; each tuple is of the form
          (opExpr, numTerms, rightLeftAssoc, parseAction), where:
           - opExpr is the pyparsing expression for the operator;
              may also be a string, which will be converted to a Literal;
              if numTerms is 3, opExpr is a tuple of two expressions, for the
              two operators separating the 3 terms
           - numTerms is the number of terms for this operator (must
              be 1, 2, or 3)
           - rightLeftAssoc is the indicator whether the operator is
              right or left associative, using the pyparsing-defined
              constants opAssoc.RIGHT and opAssoc.LEFT.
           - parseAction is the parse action to be associated with
              expressions matching this operator expression (the
              parse action tuple member may be omitted)

Definition at line 3461 of file pyparsing.py.

3461
3462 def operatorPrecedence( baseExpr, opList ):
3463 """Helper method for constructing grammars of expressions made up of
3464 operators working in a precedence hierarchy. Operators may be unary or
3465 binary, left- or right-associative. Parse actions can also be attached
3466 to operator expressions.
3467
3468 Parameters:
3469 - baseExpr - expression representing the most basic element for the nested
3470 - opList - list of tuples, one for each operator precedence level in the
3471 expression grammar; each tuple is of the form
3472 (opExpr, numTerms, rightLeftAssoc, parseAction), where:
3473 - opExpr is the pyparsing expression for the operator;
3474 may also be a string, which will be converted to a Literal;
3475 if numTerms is 3, opExpr is a tuple of two expressions, for the
3476 two operators separating the 3 terms
3477 - numTerms is the number of terms for this operator (must
3478 be 1, 2, or 3)
3479 - rightLeftAssoc is the indicator whether the operator is
3480 right or left associative, using the pyparsing-defined
3481 constants opAssoc.RIGHT and opAssoc.LEFT.
3482 - parseAction is the parse action to be associated with
3483 expressions matching this operator expression (the
3484 parse action tuple member may be omitted)
3485 """
3486 ret = Forward()
3487 lastExpr = baseExpr | ( Suppress('(') + ret + Suppress(')') )
3488 for i,operDef in enumerate(opList):
3489 opExpr,arity,rightLeftAssoc,pa = (operDef + (None,))[:4]
3490 if arity == 3:
3491 if opExpr is None or len(opExpr) != 2:
3492 raise ValueError("if numterms=3, opExpr must be a tuple or list of two expressions")
3493 opExpr1, opExpr2 = opExpr
3494 thisExpr = Forward()#.setName("expr%d" % i)
3495 if rightLeftAssoc == opAssoc.LEFT:
3496 if arity == 1:
3497 matchExpr = FollowedBy(lastExpr + opExpr) + Group( lastExpr + OneOrMore( opExpr ) )
3498 elif arity == 2:
3499 if opExpr is not None:
3500 matchExpr = FollowedBy(lastExpr + opExpr + lastExpr) + Group( lastExpr + OneOrMore( opExpr + lastExpr ) )
3501 else:
3502 matchExpr = FollowedBy(lastExpr+lastExpr) + Group( lastExpr + OneOrMore(lastExpr) )
3503 elif arity == 3:
3504 matchExpr = FollowedBy(lastExpr + opExpr1 + lastExpr + opExpr2 + lastExpr) + \
3505 Group( lastExpr + opExpr1 + lastExpr + opExpr2 + lastExpr )
3506 else:
3507 raise ValueError("operator must be unary (1), binary (2), or ternary (3)")
3508 elif rightLeftAssoc == opAssoc.RIGHT:
3509 if arity == 1:
3510 # try to avoid LR with this extra test
3511 if not isinstance(opExpr, Optional):
3512 opExpr = Optional(opExpr)
3513 matchExpr = FollowedBy(opExpr.expr + thisExpr) + Group( opExpr + thisExpr )
3514 elif arity == 2:
3515 if opExpr is not None:
3516 matchExpr = FollowedBy(lastExpr + opExpr + thisExpr) + Group( lastExpr + OneOrMore( opExpr + thisExpr ) )
3517 else:
3518 matchExpr = FollowedBy(lastExpr + thisExpr) + Group( lastExpr + OneOrMore( thisExpr ) )
3519 elif arity == 3:
3520 matchExpr = FollowedBy(lastExpr + opExpr1 + thisExpr + opExpr2 + thisExpr) + \
3521 Group( lastExpr + opExpr1 + thisExpr + opExpr2 + thisExpr )
3522 else:
3523 raise ValueError("operator must be unary (1), binary (2), or ternary (3)")
3524 else:
3525 raise ValueError("operator must indicate right or left associativity")
3526 if pa:
3527 matchExpr.setParseAction( pa )
3528 thisExpr << ( matchExpr | lastExpr )
3529 lastExpr = thisExpr
3530 ret << lastExpr
3531 return ret

def pyparsing.originalTextFor | ( |  | expr,
|  |  | asString = `True`
| ) |  |

    Helper to return the original, untokenized text for a given expression.  Useful to
       restore the parsed fields of an HTML start tag into the raw tag text itself, or to
       revert separate tokens with intervening whitespace back to the original matching
       input text. Simpler to use than the parse action keepOriginalText, and does not
       require the inspect module to chase up the call stack.  By default, returns a
       string containing the original parsed text.

       If the optional asString argument is passed as False, then the return value is a
       ParseResults containing any results names that were originally matched, and a
       single token containing the original matched text from the input string.  So if
       the expression passed to originalTextFor contains expressions with defined
       results names, you must set asString to False if you want to preserve those
       results name values.

Definition at line 3266 of file pyparsing.py.

3266
3267 def originalTextFor(expr, asString=True):
3268 """Helper to return the original, untokenized text for a given expression. Useful to
3269 restore the parsed fields of an HTML start tag into the raw tag text itself, or to
3270 revert separate tokens with intervening whitespace back to the original matching
3271 input text. Simpler to use than the parse action keepOriginalText, and does not
3272 require the inspect module to chase up the call stack. By default, returns a
3273 string containing the original parsed text.
3274
3275 If the optional asString argument is passed as False, then the return value is a
3276 ParseResults containing any results names that were originally matched, and a
3277 single token containing the original matched text from the input string. So if
3278 the expression passed to originalTextFor contains expressions with defined
3279 results names, you must set asString to False if you want to preserve those
3280 results name values."""
3281 locMarker = Empty().setParseAction(lambda s,loc,t: loc)
3282 matchExpr = locMarker("_original_start") + expr + locMarker("_original_end")
3283 if asString:
3284 extractText = lambda s,l,t: s[t._original_start:t._original_end]
3285 else:
3286 def extractText(s,l,t):
3287 del t[:]
3288 t.insert(0, s[t._original_start:t._original_end])
3289 del t["_original_start"]
3290 del t["_original_end"]
3291 matchExpr.setParseAction(extractText)
3292 return matchExpr
3293
# convenience constants for positional expressions

def pyparsing.removeQuotes | ( |  | s,
|  |  | l,
|  |  | t
| ) |  |

    Helper parse action for removing quotation marks from parsed quoted strings.
       To use, add this parse action to quoted string using::
         quotedString.setParseAction( removeQuotes )

Definition at line 3348 of file pyparsing.py.

3348
3349 def removeQuotes(s,l,t):
3350 """Helper parse action for removing quotation marks from parsed quoted strings.
3351 To use, add this parse action to quoted string using::
3352 quotedString.setParseAction( removeQuotes )
3353 """
3354 return t[0][1:-1]

def pyparsing.replaceWith | ( |  | replStr | ) |

    Helper method for common parse actions that simply return a literal value.  Especially
       useful when used with transformString().

Definition at line 3340 of file pyparsing.py.

3340
3341 def replaceWith(replStr):
3342 """Helper method for common parse actions that simply return a literal value. Especially
3343 useful when used with transformString().
3344 """
3345 def _replFunc(*args):
3346 return [replStr]
3347 return _replFunc

def pyparsing.srange | ( |  | s | ) |

Definition at line 3310 of file pyparsing.py.

3310
3311 def srange(s):
3312 r"""Helper to easily define string ranges for use in Word construction. Borrows
3313 syntax from regexp '[]' string range definitions::
3314 srange("[0-9]") -> "0123456789"
3315 srange("[a-z]") -> "abcdefghijklmnopqrstuvwxyz"
3316 srange("[a-z$_]") -> "abcdefghijklmnopqrstuvwxyz$_"
3317 The input string must be enclosed in []'s, and the returned string is the expanded
3318 character set joined into a single string.
3319 The values enclosed in the []'s may be::
3320 a single character
3321 an escaped character with a leading backslash (such as \- or \])
3322 an escaped hex character with a leading '\0x' (\0x21, which is a '!' character)
3323 an escaped octal character with a leading '\0' (\041, which is a '!' character)
3324 a range of any of the above, separated by a dash ('a-z', etc.)
3325 any combination of the above ('aeiouy', 'a-zA-Z0-9_$', etc.)
3326 """
3327 try:
3328 return "".join([_expanded(part) for part in _reBracketExpr.parseString(s).body])
3329 except:
3330 return ""

def pyparsing.traceParseAction | ( |  | f | ) |

    Decorator for debugging parse actions.

Definition at line 3079 of file pyparsing.py.

3079
3080 def traceParseAction(f):
3081 """Decorator for debugging parse actions."""
3082 f = ParserElement._normalizeParseActionArgs(f)
3083 def z(*paArgs):
3084 thisFunc = f.func_name
3085 s,l,t = paArgs[-3:]
3086 if len(paArgs)>3:
3087 thisFunc = paArgs[0].__class__.__name__ + '.' + thisFunc
3088 sys.stderr.write( ">>entering %s(line: '%s', %d, %s)\n" % (thisFunc,line(l,s),l,t) )
3089 try:
3090 ret = f(*paArgs)
3091 except Exception, exc:
3092 sys.stderr.write( "<<leaving %s (exception: %s)\n" % (thisFunc,exc) )
3093 raise
3094 sys.stderr.write( "<<leaving %s (ret: %s)\n" % (thisFunc,ret) )
3095 return ret
3096 try:
3097 z.__name__ = f.__name__
3098 except AttributeError:
3099 pass
3100 return z
3101
3102 #
3103 # global helpers
#

def pyparsing.upcaseTokens | ( |  | s,
|  |  | l,
|  |  | t
| ) |  |

    Helper parse action to convert tokens to upper case.

Definition at line 3355 of file pyparsing.py.

3355
3356 def upcaseTokens(s,l,t):
3357 """Helper parse action to convert tokens to upper case."""
3358 return [ tt.upper() for tt in map(_ustr,t) ]

def pyparsing.withAttribute | ( |  | args,
|  |  | attrDict
| ) |  |

    Helper to create a validating parse action to be used with start tags created
       with makeXMLTags or makeHTMLTags. Use withAttribute to qualify a starting tag
       with a required attribute value, to avoid false matches on common tags such as
       <TD> or <DIV>.

       Call withAttribute with a series of attribute names and values. Specify the list
       of filter attributes names and values as:
        - keyword arguments, as in (class="Customer",align="right"), or
        - a list of name-value tuples, as in ( ("ns1:class", "Customer"), ("ns2:align","right") )
       For attribute names with a namespace prefix, you must use the second form.  Attribute
       names are matched insensitive to upper/lower case.

       To verify that the attribute exists, but without specifying a value, pass
       withAttribute.ANY_VALUE as the value.

Definition at line 3426 of file pyparsing.py.

3426
3427 def withAttribute(*args,**attrDict):
3428 """Helper to create a validating parse action to be used with start tags created
3429 with makeXMLTags or makeHTMLTags. Use withAttribute to qualify a starting tag
3430 with a required attribute value, to avoid false matches on common tags such as
3431 <TD> or <DIV>.
3432
3433 Call withAttribute with a series of attribute names and values. Specify the list
3434 of filter attributes names and values as:
3435 - keyword arguments, as in (class="Customer",align="right"), or
3436 - a list of name-value tuples, as in ( ("ns1:class", "Customer"), ("ns2:align","right") )
3437 For attribute names with a namespace prefix, you must use the second form. Attribute
3438 names are matched insensitive to upper/lower case.
3439
3440 To verify that the attribute exists, but without specifying a value, pass
3441 withAttribute.ANY_VALUE as the value.
3442 """
3443 if args:
3444 attrs = args[:]
3445 else:
3446 attrs = attrDict.items()
3447 attrs = [(k,v) for k,v in attrs]
3448 def pa(s,l,tokens):
3449 for attrName,attrValue in attrs:
3450 if attrName not in tokens:
3451 raise ParseException(s,l,"no matching attribute " + attrName)
3452 if attrValue != withAttribute.ANY_VALUE and tokens[attrName] != attrValue:
3453 raise ParseException(s,l,"attribute '%s' has value '%s', must be '%s'" %
3454 (attrName, tokens[attrName], attrValue))
3455 return pa
3456 withAttribute.ANY_VALUE = object()

## Variable Documentation

list pyparsing.__all__

Initial value:
1 [
2 'And', 'CaselessKeyword', 'CaselessLiteral', 'CharsNotIn', 'Combine', 'Dict', 'Each', 'Empty',
3 'FollowedBy', 'Forward', 'GoToColumn', 'Group', 'Keyword', 'LineEnd', 'LineStart', 'Literal',
4 'MatchFirst', 'NoMatch', 'NotAny', 'OneOrMore', 'OnlyOnce', 'Optional', 'Or',
5 'ParseBaseException', 'ParseElementEnhance', 'ParseException', 'ParseExpression', 'ParseFatalException',
6 'ParseResults', 'ParseSyntaxException', 'ParserElement', 'QuotedString', 'RecursiveGrammarException',
7 'Regex', 'SkipTo', 'StringEnd', 'StringStart', 'Suppress', 'Token', 'TokenConverter', 'Upcase',
8 'White', 'Word', 'WordEnd', 'WordStart', 'ZeroOrMore',
9 'alphanums', 'alphas', 'alphas8bit', 'anyCloseTag', 'anyOpenTag', 'cStyleComment', 'col',
10 'commaSeparatedList', 'commonHTMLEntity', 'countedArray', 'cppStyleComment', 'dblQuotedString',
11 'dblSlashComment', 'delimitedList', 'dictOf', 'downcaseTokens', 'empty', 'getTokensEndLoc', 'hexnums',
12 'htmlComment', 'javaStyleComment', 'keepOriginalText', 'line', 'lineEnd', 'lineStart', 'lineno',
13 'makeHTMLTags', 'makeXMLTags', 'matchOnlyAtCol', 'matchPreviousExpr', 'matchPreviousLiteral',
14 'nestedExpr', 'nullDebugAction', 'nums', 'oneOf', 'opAssoc', 'operatorPrecedence', 'printables',
15 'punc8bit', 'pythonStyleComment', 'quotedString', 'removeQuotes', 'replaceHTMLEntity',
16 'replaceWith', 'restOfLine', 'sglQuotedString', 'srange', 'stringEnd',
17 'stringStart', 'traceParseAction', 'unicodeString', 'upcaseTokens', 'withAttribute',
18 'indentedBlock', 'originalTextFor',
19 ]

Definition at line 74 of file pyparsing.py.

string pyparsing.__author__ "Paul McGuire <ptmcg@users.sourceforge.net>"

Definition at line 63 of file pyparsing.py.

pyparsing.__doc__ \

Definition at line 26 of file pyparsing.py.

string pyparsing.__version__ "1.5.2"

Definition at line 61 of file pyparsing.py.

string pyparsing.__versionTime__ "17 February 2009 19:45"

Definition at line 62 of file pyparsing.py.

tuple pyparsing._bslash chr(92)

Definition at line 164 of file pyparsing.py.

tuple pyparsing._charRange Group(_singleChar + Suppress("-") + _singleChar)

Definition at line 3305 of file pyparsing.py.

tuple pyparsing._escapedHexChar Combine( Suppress(_bslash + "0x") + Word(hexnums) )

Definition at line 3302 of file pyparsing.py.

tuple pyparsing._escapedOctChar Combine( Suppress(_bslash) + Word("0","01234567") )

Definition at line 3303 of file pyparsing.py.

tuple pyparsing._escapedPunc Word( _bslash, r"\[]-*.$+^?()~ ", exact=2 )

Definition at line 3300 of file pyparsing.py.

tuple pyparsing._expanded lambdap:(isinstance(p,ParseResults) and ''.join([ unichr(c) for c in range(ord(p[0]),ord(p[1])+1) ]) or p)

Definition at line 3308 of file pyparsing.py.

pyparsing._L Literal

Definition at line 1515 of file pyparsing.py.

pyparsing._MAX_INT sys.maxsize

Definition at line 101 of file pyparsing.py.

tuple pyparsing._optionalNotMatched _NullToken()

Definition at line 2788 of file pyparsing.py.

string pyparsing._printables_less_backslash ""

Definition at line 3301 of file pyparsing.py.

pyparsing._PY3K True

Definition at line 100 of file pyparsing.py.

tuple pyparsing._reBracketExpr Literal("[")

Definition at line 3306 of file pyparsing.py.

tuple pyparsing._singleChar _escapedPunc|_escapedHexChar|_escapedOctChar|Word(_printables_less_backslash,exact=1)

Definition at line 3304 of file pyparsing.py.

pyparsing._str2dict set

Definition at line 142 of file pyparsing.py.

pyparsing._ustr str

Definition at line 135 of file pyparsing.py.

pyparsing.alphanums alphas+nums

Definition at line 163 of file pyparsing.py.

pyparsing.alphas string.lowercase+string.uppercase

Definition at line 158 of file pyparsing.py.

pyparsing.basestring str

Definition at line 102 of file pyparsing.py.

tuple pyparsing.dblQuotedString Regex(r'"(?:[^"\n\r\\]|(?:"")|(?:\\x[0-9a-fA-F]+)|(?:\\.))

Definition at line 3532 of file pyparsing.py.

tuple pyparsing.empty Empty()

Definition at line 3294 of file pyparsing.py.

string pyparsing.hexnums "ABCDEFabcdef"

Definition at line 162 of file pyparsing.py.

tuple pyparsing.lineEnd LineEnd()

Definition at line 3296 of file pyparsing.py.

tuple pyparsing.lineStart LineStart()

Definition at line 3295 of file pyparsing.py.

pyparsing.nums string.digits

Definition at line 161 of file pyparsing.py.

tuple pyparsing.opAssoc _Constants()

Definition at line 3457 of file pyparsing.py.

string pyparsing.printables ""

Definition at line 165 of file pyparsing.py.

tuple pyparsing.stringEnd StringEnd()

Definition at line 3298 of file pyparsing.py.

tuple pyparsing.stringStart StringStart()

Definition at line 3297 of file pyparsing.py.

pyparsing.unichr chr

Definition at line 136 of file pyparsing.py.