Skip to content

Instantly share code, notes, and snippets.

@sergiolopes
Created September 30, 2009 08:05
Show Gist options
  • Save sergiolopes/197915 to your computer and use it in GitHub Desktop.
Save sergiolopes/197915 to your computer and use it in GitHub Desktop.
Tubaixa AFC lexer for Pygments
from pygments.lexers.compiled import JavaLexer
from pygments.lexers.web import XmlLexer
from pygments.lexers.agile import RubyLexer
class TubainaAFCLexer(RegexLexer):
"""
A lexer that highlights Tubaina AFC syntax.
"""
name = 'AFC'
aliases = ['afc']
filenames = ['*.afc']
flags = re.MULTILINE | re.IGNORECASE | re.DOTALL
tokens = {
'root': [
(r'::.+?::', Generic.Emph),
(r'\*\*.+?\*\*', Generic.Strong),
(r'__.+?__', Generic.Inserted),
(r'%%.+?%%', Keyword),
(r'\[chapter([^\]]*)\]', Generic.Heading),
(r'\[section([^\]]*)\]', Generic.Subheading),
(r'\[note\]', Name.Tag, 'note'),
(r'(\[TODO)([^\]]*)(\])', bygroups(Name.Tag, String.Doc, Name.Tag)),
(r'(\[todo)([^\]]*)(\])', bygroups(Name.Tag, String.Doc, Name.Tag)),
(r'\[java[^\]]*\]', Name.Tag, 'java'),
(r'\[ruby[^\]]*\]', Name.Tag, 'ruby'),
(r'\[xml[^\]]*\]', Name.Tag, 'xml'),
(r'\[code[^\]]*\]', Name.Tag, 'code'),
(r'(\[/?\w+)([^\]]*)(\])', bygroups(Name.Tag, Name.Builtin, Name.Tag)),
(r'[^\[\*\:%_]+|[\*:%_]', Text),
],
'note': [
(r'(.+?)(\[\/note\])', bygroups(String.Doc,Name.Tag), '#pop'),
],
'java': [
(r'(.+?)(\[\/java\])', bygroups(using(JavaLexer),Name.Tag), '#pop'),
],
'ruby': [
(r'(.+?)(\[\/ruby\])', bygroups(using(RubyLexer),Name.Tag), '#pop'),
],
'xml': [
(r'(.+?)(\[\/xml\])', bygroups(using(XmlLexer),Name.Tag), '#pop'),
],
'code': [
(r'(.+?)(\[\/code\])', bygroups(Text,Name.Tag), '#pop'),
],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment