diff options
author | Georg Brandl <georg@python.org> | 2011-07-09 11:31:20 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2011-07-09 11:31:20 +0200 |
commit | 84964d4f5cd65f832c9dcb9989fba0bbbb7ee94e (patch) | |
tree | 80843ace3817f00610ad8245888c0e47d4e5b0c7 /pygments/lexers/web.py | |
parent | f6119495ed8645b050b94cec9bdd0c6f66afcc68 (diff) | |
parent | a7646a32c3ae30b8ec46ba00ef3b1128e11fe209 (diff) | |
download | pygments-84964d4f5cd65f832c9dcb9989fba0bbbb7ee94e.tar.gz |
Merged in mher/pygments (pull request #4)
Diffstat (limited to 'pygments/lexers/web.py')
-rw-r--r-- | pygments/lexers/web.py | 86 |
1 files changed, 85 insertions, 1 deletions
diff --git a/pygments/lexers/web.py b/pygments/lexers/web.py index 4ff427a4..a601d0a4 100644 --- a/pygments/lexers/web.py +++ b/pygments/lexers/web.py @@ -26,7 +26,7 @@ __all__ = ['HtmlLexer', 'XmlLexer', 'JavascriptLexer', 'CssLexer', 'PhpLexer', 'ActionScriptLexer', 'XsltLexer', 'ActionScript3Lexer', 'MxmlLexer', 'HaxeLexer', 'HamlLexer', 'SassLexer', 'ScssLexer', 'ObjectiveJLexer', 'CoffeeScriptLexer', 'DuelLexer', 'ScamlLexer', - 'JadeLexer', 'XQueryLexer'] + 'JadeLexer', 'XQueryLexer', 'DtdLexer'] class JavascriptLexer(RegexLexer): @@ -826,6 +826,90 @@ class PhpLexer(RegexLexer): return rv +class DtdLexer(RegexLexer): + """ + a lexer for DTD (Document Type Definition). + """ + + flags = re.MULTILINE | re.DOTALL + + name = 'DTD' + aliases = ['dtd'] + filenames = ['*.dtd'] + mimetypes = ['application/xml-dtd'] + + tokens = { + 'root': [ + include('common'), + + (r'(<!ELEMENT)(\s+)([^\s]+)', + bygroups(Keyword, Text, Name.Tag), 'element'), + (r'(<!ATTLIST)(\s+)([^\s]+)', + bygroups(Keyword, Text, Name.Tag), 'attlist'), + (r'(<!ENTITY)(\s+)([^\s]+)', + bygroups(Keyword, Text, Name.Entity), 'entity'), + (r'(<!NOTATION)(\s+)([^\s]+)', + bygroups(Keyword, Text, Name.Tag), 'notation'), + (r'(<!\[)([^\[\s]+)(\s*)(\[)', # conditional sections + bygroups(Keyword, Name.Entity, Text, Keyword)), + + (r'(<!DOCTYPE)(\s+)([^>\s]+)', + bygroups(Keyword, Text, Name.Tag)), + (r'PUBLIC|SYSTEM', Keyword.Constant), + (r'[\[\]>]', Keyword), + ], + + 'common': [ + (r'\s+', Text), + (r'(%|&)[^;]*;', Name.Entity), + ('<!--', Comment, 'comment'), + (r'[(|)*,?+]', Operator), + (r'"[^"]*"', String.Double), + (r'\'[^\']*\'', String.Single), + ], + + 'comment': [ + ('[^-]+', Comment), + ('-->', Comment, '#pop'), + ('-', Comment), + ], + + 'element': [ + include('common'), + (r'EMPTY|ANY|#PCDATA', Keyword.Constant), + (r'[^>\s\|()?+*,]+', Name.Tag), + (r'>', Keyword, '#pop'), + ], + + 'attlist': [ + include('common'), + (r'CDATA|IDREFS|IDREF|ID|NMTOKENS|NMTOKEN|ENTITIES|ENTITY|NOTATION', Keyword.Constant), + (r'#REQUIRED|#IMPLIED|#FIXED', Keyword.Constant), + (r'xml:space|xml:lang', Keyword.Reserved), + (r'[^>\s\|()?+*,]+', Name.Attribute), + (r'>', Keyword, '#pop'), + ], + + 'entity': [ + include('common'), + (r'SYSTEM|PUBLIC|NDATA', Keyword.Constant), + (r'[^>\s\|()?+*,]+', Name.Entity), + (r'>', Keyword, '#pop'), + ], + + 'notation': [ + include('common'), + (r'SYSTEM|PUBLIC', Keyword.Constant), + (r'[^>\s\|()?+*,]+', Name.Attribute), + (r'>', Keyword, '#pop'), + ], + } + + def analyse_text(text): + if not looks_like_xml(text) and \ + ('<!ELEMENT' in text or '<!ATTLIST' in text or '<!ENTITY' in text): + return 0.8 + class XmlLexer(RegexLexer): """ Generic lexer for XML (eXtensible Markup Language). |