Back to index

moin  1.9.0~rc2
Public Member Functions | Static Public Attributes
MoinMoin.support.pygments.lexers.agile.RubyLexer Class Reference
Inheritance diagram for MoinMoin.support.pygments.lexers.agile.RubyLexer:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.support.pygments.lexers.agile.RubyLexer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def heredoc_callback
def gen_rubystrings_rules
def analyse_text

Static Public Attributes

string name = 'Ruby'
list aliases = ['rb', 'ruby']
list filenames = ['*.rb', '*.rbw', 'Rakefile', '*.rake', '*.gemspec', '*.rbx']
list mimetypes = ['text/x-ruby', 'application/x-ruby']
 flags = re.DOTALL|re.MULTILINE
dictionary tokens

Detailed Description

For `Ruby <http://www.ruby-lang.org>`_ source code.

Definition at line 427 of file agile.py.


Member Function Documentation

Definition at line 762 of file agile.py.

00762 
00763     def analyse_text(text):
00764         return shebang_matches(text, r'ruby(1\.\d)?')
00765 

Definition at line 485 of file agile.py.

00485 
00486     def gen_rubystrings_rules():
00487         def intp_regex_callback(self, match, ctx):
00488             yield match.start(1), String.Regex, match.group(1)    # begin
00489             nctx = LexerContext(match.group(3), 0, ['interpolated-regex'])
00490             for i, t, v in self.get_tokens_unprocessed(context=nctx):
00491                 yield match.start(3)+i, t, v
00492             yield match.start(4), String.Regex, match.group(4)    # end[mixounse]*
00493             ctx.pos = match.end()
00494 
00495         def intp_string_callback(self, match, ctx):
00496             yield match.start(1), String.Other, match.group(1)
00497             nctx = LexerContext(match.group(3), 0, ['interpolated-string'])
00498             for i, t, v in self.get_tokens_unprocessed(context=nctx):
00499                 yield match.start(3)+i, t, v
00500             yield match.start(4), String.Other, match.group(4)    # end
00501             ctx.pos = match.end()
00502 
00503         states = {}
00504         states['strings'] = [
00505             # easy ones
00506             (r'\:([a-zA-Z_][\w_]*[\!\?]?|\*\*?|[-+]@?|'
00507              r'[/%&|^`~]|\[\]=?|<<|>>|<=?>|>=?|===?)', String.Symbol),
00508             (r":'(\\\\|\\'|[^'])*'", String.Symbol),
00509             (r"'(\\\\|\\'|[^'])*'", String.Single),
00510             (r':"', String.Symbol, 'simple-sym'),
00511             (r'"', String.Double, 'simple-string'),
00512             (r'(?<!\.)`', String.Backtick, 'simple-backtick'),
00513         ]
00514 
00515         # double-quoted string and symbol
00516         for name, ttype, end in ('string', String.Double, '"'), \
00517                                 ('sym', String.Symbol, '"'), \
00518                                 ('backtick', String.Backtick, '`'):
00519             states['simple-'+name] = [
00520                 include('string-intp-escaped'),
00521                 (r'[^\\%s#]+' % end, ttype),
00522                 (r'[\\#]', ttype),
00523                 (end, ttype, '#pop'),
00524             ]
00525 
00526         # braced quoted strings
00527         for lbrace, rbrace, name in ('\\{', '\\}', 'cb'), \
00528                                     ('\\[', '\\]', 'sb'), \
00529                                     ('\\(', '\\)', 'pa'), \
00530                                     ('<', '>', 'ab'):
00531             states[name+'-intp-string'] = [
00532                 (r'\\[\\' + lbrace + rbrace + ']', String.Other),
00533                 (r'(?<!\\)' + lbrace, String.Other, '#push'),
00534                 (r'(?<!\\)' + rbrace, String.Other, '#pop'),
00535                 include('string-intp-escaped'),
00536                 (r'[\\#' + lbrace + rbrace + ']', String.Other),
00537                 (r'[^\\#' + lbrace + rbrace + ']+', String.Other),
00538             ]
00539             states['strings'].append((r'%[QWx]?' + lbrace, String.Other,
00540                                       name+'-intp-string'))
00541             states[name+'-string'] = [
00542                 (r'\\[\\' + lbrace + rbrace + ']', String.Other),
00543                 (r'(?<!\\)' + lbrace, String.Other, '#push'),
00544                 (r'(?<!\\)' + rbrace, String.Other, '#pop'),
00545                 (r'[\\#' + lbrace + rbrace + ']', String.Other),
00546                 (r'[^\\#' + lbrace + rbrace + ']+', String.Other),
00547             ]
00548             states['strings'].append((r'%[qsw]' + lbrace, String.Other,
00549                                       name+'-string'))
00550             states[name+'-regex'] = [
00551                 (r'\\[\\' + lbrace + rbrace + ']', String.Regex),
00552                 (r'(?<!\\)' + lbrace, String.Regex, '#push'),
00553                 (r'(?<!\\)' + rbrace + '[mixounse]*', String.Regex, '#pop'),
00554                 include('string-intp'),
00555                 (r'[\\#' + lbrace + rbrace + ']', String.Regex),
00556                 (r'[^\\#' + lbrace + rbrace + ']+', String.Regex),
00557             ]
00558             states['strings'].append((r'%r' + lbrace, String.Regex,
00559                                       name+'-regex'))
00560 
00561         # these must come after %<brace>!
00562         states['strings'] += [
00563             # %r regex
00564             (r'(%r([^a-zA-Z0-9]))([^\2\\]*(?:\\.[^\2\\]*)*)(\2[mixounse]*)',
00565              intp_regex_callback),
00566             # regular fancy strings with qsw
00567             (r'%[qsw]([^a-zA-Z0-9])([^\1\\]*(?:\\.[^\1\\]*)*)\1', String.Other),
00568             (r'(%[QWx]([^a-zA-Z0-9]))([^\2\\]*(?:\\.[^\2\\]*)*)(\2)',
00569              intp_string_callback),
00570             # special forms of fancy strings after operators or
00571             # in method calls with braces
00572             (r'(?<=[-+/*%=<>&!^|~,(])(\s*)(%([\t ])(?:[^\3\\]*(?:\\.[^\3\\]*)*)\3)',
00573              bygroups(Text, String.Other, None)),
00574             # and because of fixed width lookbehinds the whole thing a
00575             # second time for line startings...
00576             (r'^(\s*)(%([\t ])(?:[^\3\\]*(?:\\.[^\3\\]*)*)\3)',
00577              bygroups(Text, String.Other, None)),
00578             # all regular fancy strings without qsw
00579             (r'(%([^a-zA-Z0-9\s]))([^\2\\]*(?:\\.[^\2\\]*)*)(\2)',
00580              intp_string_callback),
00581         ]
00582 
00583         return states

Here is the call graph for this function:

Definition at line 439 of file agile.py.

00439 
00440     def heredoc_callback(self, match, ctx):
00441         # okay, this is the hardest part of parsing Ruby...
00442         # match: 1 = <<-?, 2 = quote? 3 = name 4 = quote? 5 = rest of line
00443 
00444         start = match.start(1)
00445         yield start, Operator, match.group(1)        # <<-?
00446         yield match.start(2), String.Heredoc, match.group(2)  # quote ", ', `
00447         yield match.start(3), Name.Constant, match.group(3)   # heredoc name
00448         yield match.start(4), String.Heredoc, match.group(4)  # quote again
00449 
00450         heredocstack = ctx.__dict__.setdefault('heredocstack', [])
00451         outermost = not bool(heredocstack)
00452         heredocstack.append((match.group(1) == '<<-', match.group(3)))
00453 
00454         ctx.pos = match.start(5)
00455         ctx.end = match.end(5)
00456         # this may find other heredocs
00457         for i, t, v in self.get_tokens_unprocessed(context=ctx):
00458             yield i, t, v
00459         ctx.pos = match.end()
00460 
00461         if outermost:
00462             # this is the outer heredoc again, now we can process them all
00463             for tolerant, hdname in heredocstack:
00464                 lines = []
00465                 for match in line_re.finditer(ctx.text, ctx.pos):
00466                     if tolerant:
00467                         check = match.group().strip()
00468                     else:
00469                         check = match.group().rstrip()
00470                     if check == hdname:
00471                         for amatch in lines:
00472                             yield amatch.start(), String.Heredoc, amatch.group()
00473                         yield match.start(), Name.Constant, match.group()
00474                         ctx.pos = match.end()
00475                         break
00476                     else:
00477                         lines.append(match)
00478                 else:
00479                     # end of heredoc not found -- error!
00480                     for amatch in lines:
00481                         yield amatch.start(), Error, amatch.group()
00482             ctx.end = len(ctx.text)
00483             del heredocstack[:]
00484 

Here is the call graph for this function:


Member Data Documentation

Definition at line 433 of file agile.py.

list MoinMoin.support.pygments.lexers.agile.RubyLexer.filenames = ['*.rb', '*.rbw', 'Rakefile', '*.rake', '*.gemspec', '*.rbx'] [static]

Definition at line 434 of file agile.py.

MoinMoin.support.pygments.lexers.agile.RubyLexer.flags = re.DOTALL|re.MULTILINE [static]

Definition at line 437 of file agile.py.

list MoinMoin.support.pygments.lexers.agile.RubyLexer.mimetypes = ['text/x-ruby', 'application/x-ruby'] [static]

Definition at line 435 of file agile.py.

Definition at line 432 of file agile.py.

Definition at line 584 of file agile.py.


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