Package Cheetah :: Module Parser :: Class _HighLevelParser
[show private | hide private]
[frames | no frames]

Class _HighLevelParser

SourceReader --+    
               |    
 _LowLevelParser --+
                   |
                  _HighLevelParser


This class is a StateMachine for parsing Cheetah source and sending state dependent code generation commands to Cheetah.Compiler.Compiler.
Method Summary
  __init__(self, src, filename, breakPoint, compiler)
  _applyExpressionFilters(self, expr, exprType, rawExpr, startPos)
Pipes cheetah expressions through a set of optional filter hooks.
  _eatDefOrBlock(self, directiveName)
  _eatMultiLineDef(self, directiveName, methodName, argsList, startPos, isLineClearToStartToken)
  _eatRestOfDirectiveTag(self, isLineClearToStartToken, endOfFirstLinePos)
  _eatSingleLineDef(self, directiveName, methodName, argsList, startPos, endPos)
  _eatToThisEndDirective(self, directiveName)
  _filterDisabledDirectives(self, directiveName)
  _initDirectives(self)
  assertEmptyOpenDirectivesStack(self)
  cleanup(self)
Cleanup to remove any possible reference cycles
  configureParser(self)
Is called by the Compiler instance after the parser has had a settingsManager assigned with self.setSettingsManager()
  eatAttr(self)
  eatBlock(self)
  eatBreakPoint(self)
Tells the parser to stop parsing at this point and completely ignore everything else.
  eatCache(self)
  eatCall(self)
  eatCallArg(self)
  eatCapture(self)
  eatClosure(self)
  eatComment(self)
  eatCompiler(self)
  eatCompilerSettings(self)
  eatDecorator(self)
  eatDef(self)
  eatDefMacro(self)
  eatDirective(self)
  eatEncoding(self)
  eatEndDirective(self)
  eatEOLSlurpToken(self)
  eatErrorCatcher(self)
  eatExtends(self)
  eatFilter(self)
  eatIf(self)
  eatImplements(self)
  eatInclude(self)
  eatMacroCall(self)
  eatMultiLineComment(self)
  eatPlaceholder(self)
  eatPlainText(self)
  eatPSP(self)
  eatRaw(self)
  eatSet(self)
  eatShbang(self)
  eatSimpleExprDirective(self, directiveName, includeDirectiveNameInExpr)
  eatSimpleIndentingDirective(self, directiveName, callback, includeDirectiveNameInExpr)
  eatSlurp(self)
  handleEndDef(self)
  parse(self, breakPoint, assertEmptyStack)
  popFromOpenDirectivesStack(self, directiveName)
  pushToOpenDirectivesStack(self, directiveName)
  setupState(self)
    Inherited from _LowLevelParser
  _initializeSettings(self)
  _makeCheetahVarREs(self)
Setup the regexs for Cheetah $var parsing.
  _makeCommentREs(self)
Construct the regex bits that are used in comment parsing.
  _makeDirectiveREs(self)
Construct the regexs that are used in directive parsing.
  _makePspREs(self)
Setup the regexs for PSP parsing.
  getAssignmentOperator(self)
  getCacheToken(self)
  getCallArgString(self, enclosures, useNameMapper)
Get a method/function call argument string.
  getCheetahVar(self, plain, skipStartToken)
This is called when parsing inside expressions.
  getCheetahVarBody(self, plain)
  getCheetahVarNameChunks(self)
[ (namemapperPart,autoCall,restOfName), ]
  getCheetahVarStartToken(self)
just the start token, not the enclosure or cache token
  getCommentStartToken(self)
  getDefArgList(self, exitPos, useNameMapper)
Get an argument list.
  getDirectiveEndToken(self)
  getDirectiveStartToken(self)
  getDottedName(self)
  getEOLSlurpToken(self)
  getExpression(self, enclosed, enclosures, pyTokensToBreakAt, useNameMapper)
Returns the output of self.getExpressionParts() as a concatenated string rather than as a list.
  getExpressionParts(self, enclosed, enclosures, pyTokensToBreakAt, useNameMapper)
Get a Cheetah expression that includes $CheetahVars and break at directive end tokens, the end of an enclosure, or at a specified pyToken.
  getIdentifier(self)
  getMultiLineCommentEndToken(self)
  getMultiLineCommentStartToken(self)
  getOperator(self)
  getPlaceholder(self, allowCacheTokens, plain, returnEverything)
  getPSPEndToken(self)
  getPSPStartToken(self)
  getPyToken(self)
  getSilentPlaceholderToken(self)
  getTargetVarsList(self)
  isLineClearToStartToken(self, pos)
  matchAssignmentOperator(self)
  matchCheetahVarStart(self)
includes the enclosure and cache token
  matchCheetahVarStartToken(self)
includes the enclosure and cache token
  matchColonForSingleLineShortFormDirective(self)
  matchCommentStartToken(self)
  matchDirective(self)
Returns False or the name of the directive matched.
  matchDirectiveEndToken(self)
  matchDirectiveName(self, directiveNameChars)
  matchDirectiveStartToken(self)
  matchEOLSlurpToken(self)
  matchExpressionPlaceholderStart(self)
includes the enclosure and cache token
  matchIdentifier(self)
  matchMultiLineCommentEndToken(self)
  matchMultiLineCommentStartToken(self)
  matchOperator(self)
  matchPSPEndToken(self)
  matchPSPStartToken(self)
  matchPyToken(self)
  matchTopLevelToken(self)
self.matchCommentStartToken self.matchMultiLineCommentStartToken self.matchVariablePlaceholderStart self.matchExpressionPlaceholderStart self.matchDirective self.matchPSPStartToken self.matchEOLSlurpToken
  matchVariablePlaceholderStart(self)
includes the enclosure and cache token
  setSetting(self, key, val)
  setSettingsManager(self, settingsManager)
  setting(self, key, default)
  settings(self)
  transformToken(self, token, beforeTokenPos)
Takes a token from the expression being parsed and performs and special transformations required by Cheetah.
  updateSettings(self, settings)
    Inherited from SourceReader
  __getitem__(self, i)
  __getslice__(self, i, j)
  __len__(self)
  advance(self, offset)
  atEnd(self)
  atStart(self)
  breakPoint(self)
  checkPos(self, pos)
  filename(self)
  find(self, it, pos)
  findBOL(self, pos)
  findEOL(self, pos, gobble)
  getc(self)
  getLine(self, pos)
  getNonWhiteSpace(self, WSchars)
  getRowCol(self, pos)
  getRowColLine(self, pos)
  getWhiteSpace(self, max, WSchars)
  gotoBookmark(self, name)
  hasBookmark(self, name)
  isLineClearToPos(self, pos)
  lineNum(self, pos)
  matches(self, strOrRE)
  matchNonWhiteSpace(self, WSchars)
  matchWhiteSpace(self, WSchars)
  peek(self, offset)
  pos(self)
  read(self, offset)
  readTo(self, to, start)
  readToEOL(self, start, gobble)
  rev(self, offset)
  rfind(self, it, pos)
  setBookmark(self, name)
  setBreakPoint(self, pos)
  setPos(self, pos)
  splitlines(self)
  src(self)
  startswith(self, it, pos)
  ungetc(self, c)
  validPos(self, pos)

Class Variable Summary
dict _directiveHandlerNames = {'import': 'addImportStatement'...
list _simpleExprDirectives = ['pass', 'continue', 'stop', 're...
list _simpleIndentingDirectives = ['else', 'elif', 'for', 'wh...
    Inherited from _LowLevelParser
NoneType _settingsManager = None                                                                  

Method Details

_applyExpressionFilters(self, expr, exprType, rawExpr=None, startPos=None)

Pipes cheetah expressions through a set of optional filter hooks.

The filters are functions which may modify the expressions or raise a ForbiddenExpression exception if the expression is not allowed. They are defined in the compiler setting 'expressionFilterHooks'.

Some intended use cases:

  • to implement 'restricted execution' safeguards in cases where you can't trust the author of the template.
  • to enforce style guidelines
filter call signature: (parser, expr, exprType, rawExpr=None, startPos=None)
  • parser is the Cheetah parser
  • expr is the expression to filter. In some cases the parser will have already modified it from the original source code form. For example, placeholders will have been translated into namemapper calls. If you need to work with the original source, see rawExpr.
  • exprType is the name of the directive, 'psp', or 'placeholder'. All lowercase. @@TR: These will eventually be replaced with a set of constants.
  • rawExpr is the original source string that Cheetah parsed. This might be None in some cases.
  • startPos is the character position in the source string/file where the parser started parsing the current expression.
@@TR: I realize this use of the term 'expression' is a bit wonky as many
of the 'expressions' are actually statements, but I haven't thought of a better name yet. Suggestions?

cleanup(self)

Cleanup to remove any possible reference cycles

configureParser(self)

Is called by the Compiler instance after the parser has had a settingsManager assigned with self.setSettingsManager()
Overrides:
Cheetah.Parser._LowLevelParser.configureParser (inherited documentation)

eatBreakPoint(self)

Tells the parser to stop parsing at this point and completely ignore everything else.

This is a debugging tool.


Class Variable Details

_directiveHandlerNames

Type:
dict
Value:
{'import': 'addImportStatement', 'from': 'addImportStatement'}         

_simpleExprDirectives

Type:
list
Value:
['pass',
 'continue',
 'stop',
 'return',
 'yield',
 'break',
 'del',
 'assert',
...                                                                    

_simpleIndentingDirectives

Type:
list
Value:
['else',
 'elif',
 'for',
 'while',
 'repeat',
 'unless',
 'try',
 'except',
...                                                                    

Generated by Epydoc 2.1 on Sat Mar 4 13:36:23 2006 http://epydoc.sf.net