diff options
author | Nathan Whetsell <nathan.whetsell@gmail.com> | 2015-11-11 21:29:17 -0500 |
---|---|---|
committer | Nathan Whetsell <nathan.whetsell@gmail.com> | 2015-11-11 21:29:17 -0500 |
commit | 7d9698ecce2fa3505ee4a3a3522428c414a3e4c4 (patch) | |
tree | 17b54f17808edac6e0c7f96519ffaf2adb9d115c | |
parent | 7fb4fea866cde563db8cdaa124798c2198ae20cd (diff) | |
download | pygments-7d9698ecce2fa3505ee4a3a3522428c414a3e4c4.tar.gz |
Make Csound Document lexer inherit from RegexLexer instead of XmlLexer
-rw-r--r-- | pygments/lexers/csound.py | 74 |
1 files changed, 40 insertions, 34 deletions
diff --git a/pygments/lexers/csound.py b/pygments/lexers/csound.py index f49cb409..cc1ee644 100644 --- a/pygments/lexers/csound.py +++ b/pygments/lexers/csound.py @@ -9,13 +9,13 @@ :license: BSD, see LICENSE for details. """ -import re +import copy, re from pygments.lexer import RegexLexer, bygroups, default, include, using, words from pygments.token import Comment, Keyword, Name, Number, Operator, Punctuation, \ String, Text from pygments.lexers._csound_builtins import OPCODES -from pygments.lexers.html import HtmlLexer, XmlLexer +from pygments.lexers.html import HtmlLexer from pygments.lexers.python import PythonLexer from pygments.lexers.scripting import LuaLexer @@ -311,7 +311,7 @@ class CsoundOrchestraLexer(CsoundLexer): } -class CsoundDocumentLexer(XmlLexer): +class CsoundDocumentLexer(RegexLexer): """ For `Csound <http://csound.github.io>`_ documents. @@ -321,34 +321,40 @@ class CsoundDocumentLexer(XmlLexer): name = 'Csound Document' aliases = ['csound-document', 'csound-csd'] filenames = ['*.csd'] - mimetypes = [] - - tokens = XmlLexer.tokens - for i, item in enumerate(tokens['root']): - if len(item) > 2 and item[2] == 'tag': - (tokens['root']).insert(i, (r'(<)(\s*)(CsInstruments)(\s*)', - bygroups(Name.Tag, Text, Name.Tag, Text), - ('orchestra content', 'tag'))) - (tokens['root']).insert(i, (r'(<)(\s*)(CsScore)(\s*)', - bygroups(Name.Tag, Text, Name.Tag, Text), - ('score content', 'tag'))) - (tokens['root']).insert(i, (r'(<)(\s*)(html)(\s*)', - bygroups(Name.Tag, Text, Name.Tag, Text), - ('HTML', 'tag'))) - break - - tokens['orchestra content'] = [ - (r'(<)(\s*)(/)(\s*)(CsInstruments)(\s*)(>)', - bygroups(Name.Tag, Text, Name.Tag, Text, Name.Tag, Text, Name.Tag), '#pop'), - (r'.+?(?=<\s*/\s*CsInstruments\s*>)', using(CsoundOrchestraLexer)) - ] - tokens['score content'] = [ - (r'(<)(\s*)(/)(\s*)(CsScore)(\s*)(>)', - bygroups(Name.Tag, Text, Name.Tag, Text, Name.Tag, Text, Name.Tag), '#pop'), - (r'.+?(?=<\s*/\s*CsScore\s*>)', using(CsoundScoreLexer)) - ] - tokens['HTML'] = [ - (r'(<)(\s*)(/)(\s*)(html)(\s*)(>)', - bygroups(Name.Tag, Text, Name.Tag, Text, Name.Tag, Text, Name.Tag), '#pop'), - (r'.+?(?=<\s*/\s*html\s*>)', using(HtmlLexer)) - ] + + # These tokens are based on those in XmlLexer in pygments/lexers/html.py + tokens = { + 'root': [ + newline, + (r'/[*](.|\n)*?[*]/', Comment.Multiline), + (r'[^<&;/]+', Text), + (r'<\s*CsInstruments', Name.Tag, ('orchestra', 'tag')), + (r'<\s*CsScore', Name.Tag, ('score', 'tag')), + (r'<\s*[hH][tT][mM][lL]', Name.Tag, ('HTML', 'tag')), + (r'<\s*[\w:.-]+', Name.Tag, 'tag'), + (r'<\s*/\s*[\w:.-]+\s*>', Name.Tag) + ], + 'orchestra': [ + (r'<\s*/\s*CsInstruments\s*>', Name.Tag, '#pop'), + (r'(.|\n)+?(?=<\s*/\s*CsInstruments\s*>)', using(CsoundOrchestraLexer)) + ], + 'score': [ + (r'<\s*/\s*CsScore\s*>', Name.Tag, '#pop'), + (r'(.|\n)+?(?=<\s*/\s*CsScore\s*>)', using(CsoundScoreLexer)) + ], + 'HTML': [ + (r'<\s*/\s*[hH][tT][mM][lL]\s*>', Name.Tag, '#pop'), + (r'(.|\n)+?(?=<\s*/\s*[hH][tT][mM][lL]\s*>)', using(HtmlLexer)) + ], + 'tag': [ + (r'\s+', Text), + (r'[\w.:-]+\s*=', Name.Attribute, 'attr'), + (r'/?\s*>', Name.Tag, '#pop') + ], + 'attr': [ + (r'\s+', Text), + (r'".*?"', String, '#pop'), + (r"'.*?'", String, '#pop'), + (r'[^\s>]+', String, '#pop') + ] + } |