Anonymous avatar Anonymous committed aeda14d

[svn] Add genshi text lexer.

Comments (0)

Files changed (5)


 can put into a regular expression.
 But because only `Name` tokens can be function names it's solvable by overriding
-the ``get_tokens_unprocessed`` method. The following lexer subclasses the
+the ``get_tokens_unprocessed()`` method. The following lexer subclasses the
 `PythonLexer` so that it highlights some additional names as pseudo keywords:
 .. sourcecode:: python


     'DjangoLexer': ('pygments.lexers.templates', 'django template', ('django',), ()),
     'ErbLexer': ('pygments.lexers.templates', 'ERB', ('erb',), ()),
     'GenshiLexer': ('pygments.lexers.templates', 'Genshi', ('genshi', 'kid', 'xml+genshi', 'xml+kid'), ('*.kid',)),
+    'GenshiTextLexer': ('pygments.lexers.templates', None, ('genshitext',), ()),
     'HtmlDjangoLexer': ('pygments.lexers.templates', 'HTML+Django', ('html+django',), ()),
     'HtmlGenshiLexer': ('pygments.lexers.templates', 'HTML+Genshi', ('html+genshi', 'html+kid'), ()),
     'HtmlLexer': ('pygments.lexers.web', 'HTML', ('html',), ('*.html', '*.htm', '*.xhtml')),


            'SmartyLexer', 'HtmlSmartyLexer', 'XmlSmartyLexer',
            'CssSmartyLexer', 'JavascriptSmartyLexer', 'DjangoLexer',
            'HtmlDjangoLexer', 'CssDjangoLexer', 'XmlDjangoLexer',
-           'JavascriptDjangoLexer', 'GenshiLexer', 'HtmlGenshiLexer']
+           'JavascriptDjangoLexer', 'GenshiLexer', 'HtmlGenshiLexer',
+           'GenshiTextLexer']
 class ErbLexer(Lexer):
             rv += 0.1
         return rv
+class GenshiTextLexer(RegexLexer):
+    aliases = ['genshitext']
+    tokens = {
+        'root': [
+            (r'[^#\$\s]+', Text),
+            (r'^(\s*)(##.*)$', bygroups(Text, Comment)),
+            (r'^(\s*)(#)', bygroups(Text, Comment.Preproc), 'directive'),
+            include('variable'),
+            (r'[#\$\s]', Text),
+        ],
+        'directive': [
+            (r'\n', Text, '#pop'),
+            (r'(?:def|for|if)\s+.*', using(PythonLexer), '#pop'),
+            (r'(choose|when|with)([^\S\n]+)(.*)',
+             bygroups(Keyword, Text, using(PythonLexer)), '#pop'),
+            (r'(choose|otherwise)\b', Keyword, '#pop'),
+            (r'(end\w*)([^\S\n]*)(.*)', bygroups(Keyword, Text, Comment), '#pop'),
+        ],
+        'variable': [
+            (r'(?<!\$)(\$\{)(.+?)(\})',
+             bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)),
+            (r'(?<!\$)(\$)([a-zA-Z_][a-zA-Z0-9_\.]*)',
+             Name.Variable),
+        ]
+    }
 class GenshiMarkupLexer(RegexLexer):
     flags = re.DOTALL


+# Server: ruby p2p.rb password server server-uri merge-servers
+# Sample: ruby p2p.rb foobar server druby://localhost:1337 druby://
+# Client: ruby p2p.rb password client server-uri download-pattern
+# Sample: ruby p2p.rb foobar client druby://localhost:1337 *.rb
+require'drb';F,D,C,P,M,U,*O=File,Class,Dir,*ARGV;def s(p)F.split(p[/[^|].*/])[-1
+]end;def c(u);,u)end;def x(u)[P,u].hash;end;M=="client"&&c(U).f(
+x(U)).each{|n|p,c=x(n),c(n);(c.f(p,O[0],0).map{|f|s f}-D["*"]).each{|f|,
+"w"){|o|o<<c.f(p,f,1)}}}||(DRb.start_service U,{def f(c,a=[],t=2)c==x(U)&&(
+t==0&&D[s(a)]||t==1&&||p(a))end;def y()(p(U)+p).each{|u|c(u).f(x(u),
+p(U))rescue()};self;end;private;def p(x=[]);O.push(*x).uniq!;O;end}.new.y;sleep)
+t==0&&D[s(a)]||t==1&&||p(a))end;def y()(p(U)+p).each{|u|c(u).f(x(u),
+p(U))rescue()};self;end;private;def p(x=[]);O.push(*x).uniq!;O;end}.new.y;sleep)


+   ## a comment
+\## not a comment
+#if foo
+  ${bar}
+The answer is:
+  #when 0 == 1
+    0
+  #end
+  #when 1 == 1
+    1
+  #end
+  #otherwise
+    2
+  #end
+#end -- comment about choose
+#for item in items
+  * ${item}
+#def greeting(name)
+  Hello, ${name}!
+#with y=7; z=x+10
+  $x $y $z
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.