OpenQuizz
Une application de gestion des contenus pédagogiques
Keyword Class Reference
Inheritance diagram for Keyword:
Collaboration diagram for Keyword:

Public Member Functions

def __init__ (self, matchString, identChars=None, caseless=False)
 
def parseImpl (self, instring, loc, doActions=True)
 
def copy (self)
 
- Public Member Functions inherited from Token
def __init__ (self)
 
- Public Member Functions inherited from ParserElement
def __init__ (self, savelist=False)
 
def setName (self, name)
 
def setResultsName (self, name, listAllMatches=False)
 
def setBreak (self, breakFlag=True)
 
def setParseAction (self, *fns, **kwargs)
 
def addParseAction (self, *fns, **kwargs)
 
def addCondition (self, *fns, **kwargs)
 
def setFailAction (self, fn)
 
def preParse (self, instring, loc)
 
def postParse (self, instring, loc, tokenlist)
 
def tryParse (self, instring, loc)
 
def canParseNext (self, instring, loc)
 
def parseString (self, instring, parseAll=False)
 
def scanString (self, instring, maxMatches=_MAX_INT, overlap=False)
 
def transformString (self, instring)
 
def searchString (self, instring, maxMatches=_MAX_INT)
 
def split (self, instring, maxsplit=_MAX_INT, includeSeparators=False)
 
def __add__ (self, other)
 
def __radd__ (self, other)
 
def __sub__ (self, other)
 
def __rsub__ (self, other)
 
def __mul__ (self, other)
 
def __rmul__ (self, other)
 
def __or__ (self, other)
 
def __ror__ (self, other)
 
def __xor__ (self, other)
 
def __rxor__ (self, other)
 
def __and__ (self, other)
 
def __rand__ (self, other)
 
def __invert__ (self)
 
def __iter__ (self)
 
def __getitem__ (self, key)
 
def __call__ (self, name=None)
 
def suppress (self)
 
def leaveWhitespace (self)
 
def setWhitespaceChars (self, chars)
 
def parseWithTabs (self)
 
def ignore (self, other)
 
def setDebugActions (self, startAction, successAction, exceptionAction)
 
def setDebug (self, flag=True)
 
def __str__ (self)
 
def __repr__ (self)
 
def streamline (self)
 
def checkRecursion (self, parseElementList)
 
def validate (self, validateTrace=None)
 
def parseFile (self, file_or_filename, parseAll=False)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __hash__ (self)
 
def __req__ (self, other)
 
def __rne__ (self, other)
 
def matches (self, testString, parseAll=True)
 
def runTests (self, tests, parseAll=True, comment='#', fullDump=True, printResults=True, failureTests=False, postParse=None, file=None)
 

Static Public Member Functions

def setDefaultKeywordChars (chars)
 
- Static Public Member Functions inherited from ParserElement
def setDefaultWhitespaceChars (chars)
 
def inlineLiteralsUsing (cls)
 
def resetCache ()
 
def enablePackrat (cache_size_limit=128)
 

Data Fields

 match
 
 matchLen
 
 firstMatchChar
 
 name
 
 errmsg
 
 mayReturnEmpty
 
 mayIndexError
 
 caseless
 
 caselessmatch
 
 identChars
 
- Data Fields inherited from ParserElement
 parseAction
 
 failAction
 
 strRepr
 
 resultsName
 
 saveAsList
 
 skipWhitespace
 
 whiteChars
 
 copyDefaultWhiteChars
 
 mayReturnEmpty
 
 keepTabs
 
 ignoreExprs
 
 debug
 
 streamlined
 
 mayIndexError
 
 errmsg
 
 modalResults
 
 debugActions
 
 re
 
 callPreparse
 
 callDuringTry
 
 name
 

Static Public Attributes

 DEFAULT_KEYWORD_CHARS
 
- Static Public Attributes inherited from ParserElement
 DEFAULT_WHITE_CHARS
 
 verbose_stacktrace
 
 packrat_cache
 
 packrat_cache_lock
 
 packrat_cache_stats
 

Detailed Description

Token to exactly match a specified string as a keyword, that is,
it must be immediately followed by a non-keyword character.  Compare
with :class:`Literal`:

 - ``Literal("if")`` will match the leading ``'if'`` in
   ``'ifAndOnlyIf'``.
 - ``Keyword("if")`` will not; it will only match the leading
   ``'if'`` in ``'if x=1'``, or ``'if(y==2)'``

Accepts two optional constructor arguments in addition to the
keyword string:

 - ``identChars`` is a string of characters that would be valid
   identifier characters, defaulting to all alphanumerics + "_" and
   "$"
 - ``caseless`` allows case-insensitive matching, default is ``False``.

Example::

    Keyword("start").parseString("start")  # -> ['start']
    Keyword("start").parseString("starting")  # -> Exception

For case-insensitive matching, use :class:`CaselessKeyword`.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  matchString,
  identChars = None,
  caseless = False 
)

Member Function Documentation

◆ copy()

def copy (   self)
Make a copy of this :class:`ParserElement`.  Useful for defining
different parse actions for the same parsing pattern, using copies of
the original parse element.

Example::

    integer = Word(nums).setParseAction(lambda toks: int(toks[0]))
    integerK = integer.copy().addParseAction(lambda toks: toks[0] * 1024) + Suppress("K")
    integerM = integer.copy().addParseAction(lambda toks: toks[0] * 1024 * 1024) + Suppress("M")

    print(OneOrMore(integerK | integerM | integer).parseString("5K 100 640K 256M"))

prints::

    [5120, 100, 655360, 268435456]

Equivalent form of ``expr.copy()`` is just ``expr()``::

    integerM = integer().addParseAction(lambda toks: toks[0] * 1024 * 1024) + Suppress("M")

Reimplemented from ParserElement.

◆ parseImpl()

def parseImpl (   self,
  instring,
  loc,
  doActions = True 
)

Reimplemented from ParserElement.

◆ setDefaultKeywordChars()

def setDefaultKeywordChars (   chars)
static
Overrides the default Keyword chars

Field Documentation

◆ caseless

caseless

◆ caselessmatch

caselessmatch

◆ DEFAULT_KEYWORD_CHARS

DEFAULT_KEYWORD_CHARS
static

◆ errmsg

errmsg

◆ firstMatchChar

firstMatchChar

◆ identChars

identChars

◆ match

match

◆ matchLen

matchLen

◆ mayIndexError

mayIndexError

◆ mayReturnEmpty

mayReturnEmpty

◆ name

name

The documentation for this class was generated from the following file: