Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes
MoinMoin.parser._ParserBase.ParserBase Class Reference
Collaboration diagram for MoinMoin.parser._ParserBase.ParserBase:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def setupRules
def addRule
def addRulePair
def addWords
def addReserved
def addConstant
def addRuleFormat
def format
def format_normal_text
def format_match

Public Attributes

 raw
 request
 rule_fmt
 def_format
 reserved_word_format
 constant_word_format
 ID_format
 text
 text_len
 lastpos

Static Public Attributes

string parsername = 'ParserBase'
int tabwidth = 4
 LINESEP = ENDL+STARTL

Private Member Functions

def _addRule

Private Attributes

 _ignore_case
 _formatting_rules
 _formatting_rules_n2r
 _formatting_rule_index
 _code_id

Detailed Description

DEPRECATED highlighting parser - please use/extend pygments library 

Definition at line 121 of file _ParserBase.py.


Constructor & Destructor Documentation

def MoinMoin.parser._ParserBase.ParserBase.__init__ (   self,
  raw,
  request,
  kw 
)

Definition at line 133 of file _ParserBase.py.

00133 
00134     def __init__(self, raw, request, **kw):
00135         self.raw = raw
00136         self.request = request
00137         self.show_nums, self.num_start, self.num_step, attrs = parse_start_step(request, kw.get('format_args', ''))
00138 
00139         self._ignore_case = False
00140         self._formatting_rules = []
00141         self._formatting_rules_n2r = {}
00142         self._formatting_rule_index = 0
00143         self.rule_fmt = {}
00144         #self.line_count = len(raw.split('\n')) + 1


Member Function Documentation

def MoinMoin.parser._ParserBase.ParserBase._addRule (   self,
  name,
  fmt 
) [private]

Definition at line 170 of file _ParserBase.py.

00170 
00171     def _addRule(self, name, fmt):
00172         self._formatting_rule_index += 1
00173         name = "%s_%s" % (name, self._formatting_rule_index) # create unique name
00174         self._formatting_rules.append((name, fmt))
00175         self._formatting_rules_n2r[name] = fmt

Here is the caller graph for this function:

Definition at line 191 of file _ParserBase.py.

00191 
00192     def addConstant(self, words):
00193         self.addWords(words, self.constant_word_format)

Here is the call graph for this function:

Definition at line 188 of file _ParserBase.py.

00188 
00189     def addReserved(self, words):
00190         self.addWords(words, self.reserved_word_format)

Here is the call graph for this function:

def MoinMoin.parser._ParserBase.ParserBase.addRule (   self,
  name,
  str_re 
)

Definition at line 176 of file _ParserBase.py.

00176 
00177     def addRule(self, name, str_re):
00178         self._addRule(name, FormattingRuleSingle(name, str_re, self._ignore_case))

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.parser._ParserBase.ParserBase.addRuleFormat (   self,
  name,
  fmt = None 
)

Definition at line 194 of file _ParserBase.py.

00194 
00195     def addRuleFormat(self, name, fmt=None):
00196         if fmt is None:
00197             fmt = FormatText(name)
00198         self.rule_fmt[name] = fmt

Here is the caller graph for this function:

def MoinMoin.parser._ParserBase.ParserBase.addRulePair (   self,
  name,
  start_re,
  end_re 
)

Definition at line 179 of file _ParserBase.py.

00179 
00180     def addRulePair(self, name, start_re, end_re):
00181         self._addRule(name, FormattingRulePair(name, start_re, end_re, self._ignore_case))

Here is the call graph for this function:

def MoinMoin.parser._ParserBase.ParserBase.addWords (   self,
  words,
  fmt 
)

Definition at line 182 of file _ParserBase.py.

00182 
00183     def addWords(self, words, fmt):
00184         if not isinstance(fmt, FormatTextBase):
00185             fmt = FormatText(fmt)
00186         for w in words:
00187             self.ID_format.addFormat(w, fmt)

Here is the caller graph for this function:

def MoinMoin.parser._ParserBase.ParserBase.format (   self,
  formatter,
  form = None 
)
Send the text.

Definition at line 199 of file _ParserBase.py.

00199 
00200     def format(self, formatter, form=None):
00201         """ Send the text.
00202         """
00203 
00204         self.setupRules()
00205 
00206         formatting_regexes = ["(?P<%s>%s)" % (n, f.getStartRe())
00207                               for n, f in self._formatting_rules]
00208         re_flags = re.M
00209         if self._ignore_case:
00210             re_flags |= re.I
00211         scan_re = re.compile("|".join(formatting_regexes), re_flags)
00212 
00213         self.text = self.raw
00214 
00215         # dirty little trick to work around re lib's limitations (it can't have
00216         # zero length matches at line beginning for ^ and at the same time match
00217         # something else at the beginning of the line):
00218         self.text = self.LINESEP.join([line.replace('\r', '') for line in self.text.splitlines()])
00219         self.text = self.STARTL + self.text + self.ENDL
00220         self.text_len = len(self.text)
00221 
00222         result = [] # collects output
00223 
00224         self._code_id = hash_new('sha1', self.raw.encode(config.charset)).hexdigest()
00225         result.append(formatter.code_area(1, self._code_id, self.parsername, self.show_nums, self.num_start, self.num_step))
00226 
00227         self.lastpos = 0
00228         match = scan_re.search(self.text)
00229         while match and self.lastpos < self.text_len:
00230             # add the rendering of the text left of the match we found
00231             text = self.text[self.lastpos:match.start()]
00232             if text:
00233                 result.extend(self.format_normal_text(formatter, text))
00234             self.lastpos = match.end() + (match.end() == self.lastpos)
00235 
00236             # add the rendering of the match we found
00237             result.extend(self.format_match(formatter, match))
00238 
00239             # search for the next one
00240             match = scan_re.search(self.text, self.lastpos)
00241 
00242         # add the rendering of the text right of the last match we found
00243         text = self.text[self.lastpos:]
00244         if text:
00245             result.extend(self.format_normal_text(formatter, text))
00246 
00247         result.append(formatter.code_area(0, self._code_id))
00248         self.request.write(''.join(result))

Here is the call graph for this function:

def MoinMoin.parser._ParserBase.ParserBase.format_match (   self,
  formatter,
  match 
)

Definition at line 252 of file _ParserBase.py.

00252 
00253     def format_match(self, formatter, match):
00254         result = []
00255         for n, hit in match.groupdict().items():
00256             if hit is None:
00257                 continue
00258             r = self._formatting_rules_n2r[n]
00259             s = r.getText(self, hit)
00260             c = self.rule_fmt.get(r.name, None)
00261             if not c:
00262                 c = self.def_format
00263             if s:
00264                 lines = s.expandtabs(self.tabwidth).split(self.LINESEP)
00265                 for line in lines[:-1]:
00266                     result.append(c.formatString(formatter, line))
00267                     result.append(FormatEndLine().formatString(formatter, ''))
00268                     result.append(FormatBeginLine().formatString(formatter, ''))
00269                 result.append(c.formatString(formatter, lines[-1]))
00270         return result
00271 
def MoinMoin.parser._ParserBase.ParserBase.format_normal_text (   self,
  formatter,
  text 
)

Definition at line 249 of file _ParserBase.py.

00249 
00250     def format_normal_text(self, formatter, text):
00251         return [formatter.text(text.expandtabs(self.tabwidth))]

Definition at line 145 of file _ParserBase.py.

00145 
00146     def setupRules(self):
00147         self.addRuleFormat("BEGINLINE", FormatBeginLine())
00148         self.addRuleFormat("ENDLINE", FormatEndLine())
00149         # we need a little dirty trick here, see comment in format():
00150         self.addRule("BEGINLINE", self.STARTL_RE)
00151         self.addRule("ENDLINE", self.ENDL_RE)
00152 
00153         self.def_format = FormatText('Default')
00154         self.reserved_word_format = FormatText('ResWord')
00155         self.constant_word_format = FormatText('ConsWord')
00156         self.ID_format = FormatTextID('ID', self._ignore_case)
00157         self.addRuleFormat("ID", self.ID_format)
00158         self.addRuleFormat("Operator")
00159         self.addRuleFormat("Char")
00160         self.addRuleFormat("Comment")
00161         self.addRuleFormat("Number")
00162         self.addRuleFormat("String")
00163         self.addRuleFormat("SPChar")
00164         self.addRuleFormat("ResWord")
00165         self.addRuleFormat("ResWord2")
00166         self.addRuleFormat("ConsWord")
00167         self.addRuleFormat("Special")
00168         self.addRuleFormat("Preprc")
00169         self.addRuleFormat("Error")

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 223 of file _ParserBase.py.

Definition at line 141 of file _ParserBase.py.

Definition at line 139 of file _ParserBase.py.

Definition at line 140 of file _ParserBase.py.

Definition at line 138 of file _ParserBase.py.

Definition at line 154 of file _ParserBase.py.

Definition at line 152 of file _ParserBase.py.

Definition at line 155 of file _ParserBase.py.

Definition at line 226 of file _ParserBase.py.

Definition at line 131 of file _ParserBase.py.

Definition at line 125 of file _ParserBase.py.

Definition at line 134 of file _ParserBase.py.

Definition at line 135 of file _ParserBase.py.

Definition at line 153 of file _ParserBase.py.

Definition at line 142 of file _ParserBase.py.

Definition at line 126 of file _ParserBase.py.

Definition at line 212 of file _ParserBase.py.

Definition at line 219 of file _ParserBase.py.


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