diff options
author | Georg Brandl <georg@python.org> | 2014-09-19 23:53:18 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-09-19 23:53:18 +0200 |
commit | 9d3184ead0ddafd2fe7278bd94eb815523773599 (patch) | |
tree | 69d23990fd57f4075a61b1f66cb8668a2725ab25 | |
parent | fc8d1304d47bf289b28c9aade4f7b222ede5205c (diff) | |
download | pygments-9d3184ead0ddafd2fe7278bd94eb815523773599.tar.gz |
split up web lexers
-rw-r--r-- | pygments/lexers/_mapping.py | 66 | ||||
-rw-r--r-- | pygments/lexers/actionscript.py | 238 | ||||
-rw-r--r-- | pygments/lexers/css.py | 496 | ||||
-rw-r--r-- | pygments/lexers/data.py | 86 | ||||
-rw-r--r-- | pygments/lexers/dotnet.py | 2 | ||||
-rw-r--r-- | pygments/lexers/dsls.py | 45 | ||||
-rw-r--r-- | pygments/lexers/haxe.py | 934 | ||||
-rw-r--r-- | pygments/lexers/html.py | 589 | ||||
-rw-r--r-- | pygments/lexers/installers.py | 3 | ||||
-rw-r--r-- | pygments/lexers/javascript.py | 1192 | ||||
-rw-r--r-- | pygments/lexers/markup.py | 2 | ||||
-rw-r--r-- | pygments/lexers/modeling.py | 2 | ||||
-rw-r--r-- | pygments/lexers/parsers.py | 2 | ||||
-rw-r--r-- | pygments/lexers/php.py | 246 | ||||
-rw-r--r-- | pygments/lexers/templates.py | 5 | ||||
-rw-r--r-- | pygments/lexers/text.py | 2 | ||||
-rw-r--r-- | pygments/lexers/web.py | 4515 | ||||
-rw-r--r-- | pygments/lexers/webmisc.py | 920 |
18 files changed, 4757 insertions, 4588 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index f0848dd4..2c387371 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -18,8 +18,8 @@ from __future__ import print_function LEXERS = { 'ABAPLexer': ('pygments.lexers.business', 'ABAP', ('abap',), ('*.abap',), ('text/x-abap',)), 'APLLexer': ('pygments.lexers.misc.apl', 'APL', ('apl',), ('*.apl',), ()), - 'ActionScript3Lexer': ('pygments.lexers.web', 'ActionScript 3', ('as3', 'actionscript3'), ('*.as',), ('application/x-actionscript3', 'text/x-actionscript3', 'text/actionscript3')), - 'ActionScriptLexer': ('pygments.lexers.web', 'ActionScript', ('as', 'actionscript'), ('*.as',), ('application/x-actionscript', 'text/x-actionscript', 'text/actionscript')), + 'ActionScript3Lexer': ('pygments.lexers.actionscript', 'ActionScript 3', ('as3', 'actionscript3'), ('*.as',), ('application/x-actionscript3', 'text/x-actionscript3', 'text/actionscript3')), + 'ActionScriptLexer': ('pygments.lexers.actionscript', 'ActionScript', ('as', 'actionscript'), ('*.as',), ('application/x-actionscript', 'text/x-actionscript', 'text/actionscript')), 'AdaLexer': ('pygments.lexers.pascal', 'Ada', ('ada', 'ada95', 'ada2005'), ('*.adb', '*.ads', '*.ada'), ('text/x-ada',)), 'AgdaLexer': ('pygments.lexers.haskell', 'Agda', ('agda',), ('*.agda',), ('text/x-agda',)), 'AlloyLexer': ('pygments.lexers.dsls', 'Alloy', ('alloy',), ('*.als',), ('text/x-alloy',)), @@ -67,13 +67,13 @@ LEXERS = { 'CheetahJavascriptLexer': ('pygments.lexers.templates', 'JavaScript+Cheetah', ('js+cheetah', 'javascript+cheetah', 'js+spitfire', 'javascript+spitfire'), (), ('application/x-javascript+cheetah', 'text/x-javascript+cheetah', 'text/javascript+cheetah', 'application/x-javascript+spitfire', 'text/x-javascript+spitfire', 'text/javascript+spitfire')), 'CheetahLexer': ('pygments.lexers.templates', 'Cheetah', ('cheetah', 'spitfire'), ('*.tmpl', '*.spt'), ('application/x-cheetah', 'application/x-spitfire')), 'CheetahXmlLexer': ('pygments.lexers.templates', 'XML+Cheetah', ('xml+cheetah', 'xml+spitfire'), (), ('application/xml+cheetah', 'application/xml+spitfire')), - 'CirruLexer': ('pygments.lexers.web', 'Cirru', ('cirru',), ('*.cirru', '*.cr'), ('text/x-cirru',)), + 'CirruLexer': ('pygments.lexers.webmisc', 'Cirru', ('cirru',), ('*.cirru', '*.cr'), ('text/x-cirru',)), 'ClayLexer': ('pygments.lexers.c_like.other', 'Clay', ('clay',), ('*.clay',), ('text/x-clay',)), 'ClojureLexer': ('pygments.lexers.jvm', 'Clojure', ('clojure', 'clj'), ('*.clj',), ('text/x-clojure', 'application/x-clojure')), 'ClojureScriptLexer': ('pygments.lexers.jvm', 'ClojureScript', ('clojurescript', 'cljs'), ('*.cljs',), ('text/x-clojurescript', 'application/x-clojurescript')), 'CobolFreeformatLexer': ('pygments.lexers.business', 'COBOLFree', ('cobolfree',), ('*.cbl', '*.CBL'), ()), 'CobolLexer': ('pygments.lexers.business', 'COBOL', ('cobol',), ('*.cob', '*.COB', '*.cpy', '*.CPY'), ('text/x-cobol',)), - 'CoffeeScriptLexer': ('pygments.lexers.web', 'CoffeeScript', ('coffee-script', 'coffeescript', 'coffee'), ('*.coffee',), ('text/coffeescript',)), + 'CoffeeScriptLexer': ('pygments.lexers.javascript', 'CoffeeScript', ('coffee-script', 'coffeescript', 'coffee'), ('*.coffee',), ('text/coffeescript',)), 'ColdfusionCFCLexer': ('pygments.lexers.templates', 'Coldfusion CFC', ('cfc',), ('*.cfc',), ()), 'ColdfusionHtmlLexer': ('pygments.lexers.templates', 'Coldfusion HTML', ('cfm',), ('*.cfm', '*.cfml'), ('application/x-coldfusion',)), 'ColdfusionLexer': ('pygments.lexers.templates', 'cfstatement', ('cfs',), (), ()), @@ -86,7 +86,7 @@ LEXERS = { 'CssDjangoLexer': ('pygments.lexers.templates', 'CSS+Django/Jinja', ('css+django', 'css+jinja'), (), ('text/css+django', 'text/css+jinja')), 'CssErbLexer': ('pygments.lexers.templates', 'CSS+Ruby', ('css+erb', 'css+ruby'), (), ('text/css+ruby',)), 'CssGenshiLexer': ('pygments.lexers.templates', 'CSS+Genshi Text', ('css+genshitext', 'css+genshi'), (), ('text/css+genshi',)), - 'CssLexer': ('pygments.lexers.web', 'CSS', ('css',), ('*.css',), ('text/css',)), + 'CssLexer': ('pygments.lexers.css', 'CSS', ('css',), ('*.css',), ('text/css',)), 'CssPhpLexer': ('pygments.lexers.templates', 'CSS+PHP', ('css+php',), (), ('text/css+php',)), 'CssSmartyLexer': ('pygments.lexers.templates', 'CSS+Smarty', ('css+smarty',), (), ('text/css+smarty',)), 'CudaLexer': ('pygments.lexers.c_like.other', 'CUDA', ('cuda', 'cu'), ('*.cu', '*.cuh'), ('text/x-cuda',)), @@ -95,14 +95,15 @@ LEXERS = { 'DLexer': ('pygments.lexers.c_like.d', 'D', ('d',), ('*.d', '*.di'), ('text/x-dsrc',)), 'DObjdumpLexer': ('pygments.lexers.asm', 'd-objdump', ('d-objdump',), ('*.d-objdump',), ('text/x-d-objdump',)), 'DarcsPatchLexer': ('pygments.lexers.diff', 'Darcs Patch', ('dpatch',), ('*.dpatch', '*.darcspatch'), ()), - 'DartLexer': ('pygments.lexers.web', 'Dart', ('dart',), ('*.dart',), ('text/x-dart',)), + 'DartLexer': ('pygments.lexers.javascript', 'Dart', ('dart',), ('*.dart',), ('text/x-dart',)), + 'DebianControlLexer': ('pygments.lexers.installers', 'Debian Control file', ('control', 'debcontrol'), ('control',), ()), 'DelphiLexer': ('pygments.lexers.pascal', 'Delphi', ('delphi', 'pas', 'pascal', 'objectpascal'), ('*.pas',), ('text/x-pascal',)), 'DgLexer': ('pygments.lexers.python', 'dg', ('dg',), ('*.dg',), ('text/x-dg',)), 'DiffLexer': ('pygments.lexers.diff', 'Diff', ('diff', 'udiff'), ('*.diff', '*.patch'), ('text/x-diff', 'text/x-patch')), 'DjangoLexer': ('pygments.lexers.templates', 'Django/Jinja', ('django', 'jinja'), (), ('application/x-django-templating', 'application/x-jinja')), 'DockerLexer': ('pygments.lexers.configs', 'Docker', ('docker', 'dockerfile'), ('Dockerfile', '*.docker'), ('text/x-dockerfile-config',)), - 'DtdLexer': ('pygments.lexers.web', 'DTD', ('dtd',), ('*.dtd',), ('application/xml-dtd',)), - 'DuelLexer': ('pygments.lexers.web', 'Duel', ('duel', 'jbst', 'jsonml+bst'), ('*.duel', '*.jbst'), ('text/x-duel', 'text/x-jbst')), + 'DtdLexer': ('pygments.lexers.html', 'DTD', ('dtd',), ('*.dtd',), ('application/xml-dtd',)), + 'DuelLexer': ('pygments.lexers.webmisc', 'Duel', ('duel', 'jbst', 'jsonml+bst'), ('*.duel', '*.jbst'), ('text/x-duel', 'text/x-jbst')), 'DylanConsoleLexer': ('pygments.lexers.misc.dylan', 'Dylan session', ('dylan-console', 'dylan-repl'), ('*.dylan-console',), ('text/x-dylan-console',)), 'DylanLexer': ('pygments.lexers.misc.dylan', 'Dylan', ('dylan',), ('*.dylan', '*.dyl', '*.intr'), ('text/x-dylan',)), 'DylanLidLexer': ('pygments.lexers.misc.dylan', 'DylanLID', ('dylan-lid', 'lid'), ('*.lid', '*.hdp'), ('text/x-dylan-lid',)), @@ -140,18 +141,18 @@ LEXERS = { 'GosuTemplateLexer': ('pygments.lexers.jvm', 'Gosu Template', ('gst',), ('*.gst',), ('text/x-gosu-template',)), 'GroffLexer': ('pygments.lexers.markup', 'Groff', ('groff', 'nroff', 'man'), ('*.[1234567]', '*.man'), ('application/x-troff', 'text/troff')), 'GroovyLexer': ('pygments.lexers.jvm', 'Groovy', ('groovy',), ('*.groovy',), ('text/x-groovy',)), - 'HamlLexer': ('pygments.lexers.web', 'Haml', ('haml',), ('*.haml',), ('text/x-haml',)), + 'HamlLexer': ('pygments.lexers.html', 'Haml', ('haml',), ('*.haml',), ('text/x-haml',)), 'HandlebarsHtmlLexer': ('pygments.lexers.templates', 'HTML+Handlebars', ('html+handlebars',), ('*.handlebars', '*.hbs'), ('text/html+handlebars', 'text/x-handlebars-template')), 'HandlebarsLexer': ('pygments.lexers.templates', 'Handlebars', ('handlebars',), (), ()), 'HaskellLexer': ('pygments.lexers.haskell', 'Haskell', ('haskell', 'hs'), ('*.hs',), ('text/x-haskell',)), - 'HaxeLexer': ('pygments.lexers.web', 'Haxe', ('hx', 'haxe', 'hxsl'), ('*.hx', '*.hxsl'), ('text/haxe', 'text/x-haxe', 'text/x-hx')), + 'HaxeLexer': ('pygments.lexers.haxe', 'Haxe', ('hx', 'haxe', 'hxsl'), ('*.hx', '*.hxsl'), ('text/haxe', 'text/x-haxe', 'text/x-hx')), 'HtmlDjangoLexer': ('pygments.lexers.templates', 'HTML+Django/Jinja', ('html+django', 'html+jinja', 'htmldjango'), (), ('text/html+django', 'text/html+jinja')), 'HtmlGenshiLexer': ('pygments.lexers.templates', 'HTML+Genshi', ('html+genshi', 'html+kid'), (), ('text/html+genshi',)), - 'HtmlLexer': ('pygments.lexers.web', 'HTML', ('html',), ('*.html', '*.htm', '*.xhtml', '*.xslt'), ('text/html', 'application/xhtml+xml')), + 'HtmlLexer': ('pygments.lexers.html', 'HTML', ('html',), ('*.html', '*.htm', '*.xhtml', '*.xslt'), ('text/html', 'application/xhtml+xml')), 'HtmlPhpLexer': ('pygments.lexers.templates', 'HTML+PHP', ('html+php',), ('*.phtml',), ('application/x-php', 'application/x-httpd-php', 'application/x-httpd-php3', 'application/x-httpd-php4', 'application/x-httpd-php5')), 'HtmlSmartyLexer': ('pygments.lexers.templates', 'HTML+Smarty', ('html+smarty',), (), ('text/html+smarty',)), 'HttpLexer': ('pygments.lexers.textfmts', 'HTTP', ('http',), (), ()), - 'HxmlLexer': ('pygments.lexers.dsls', 'Hxml', ('haxeml', 'hxml'), ('*.hxml',), ()), + 'HxmlLexer': ('pygments.lexers.haxe', 'Hxml', ('haxeml', 'hxml'), ('*.hxml',), ()), 'HyLexer': ('pygments.lexers.lisp', 'Hy', ('hylang',), ('*.hy',), ('text/x-hy', 'application/x-hy')), 'HybrisLexer': ('pygments.lexers.scripting', 'Hybris', ('hybris', 'hy'), ('*.hy', '*.hyb'), ('text/x-hybris', 'application/x-hybris')), 'IDLLexer': ('pygments.lexers.math', 'IDL', ('idl',), ('*.pro',), ('text/idl',)), @@ -164,21 +165,21 @@ LEXERS = { 'IoLexer': ('pygments.lexers.misc.iolang', 'Io', ('io',), ('*.io',), ('text/x-iosrc',)), 'IokeLexer': ('pygments.lexers.jvm', 'Ioke', ('ioke', 'ik'), ('*.ik',), ('text/x-iokesrc',)), 'IrcLogsLexer': ('pygments.lexers.textfmts', 'IRC logs', ('irc',), ('*.weechatlog',), ('text/x-irclog',)), - 'JadeLexer': ('pygments.lexers.web', 'Jade', ('jade',), ('*.jade',), ('text/x-jade',)), + 'JadeLexer': ('pygments.lexers.html', 'Jade', ('jade',), ('*.jade',), ('text/x-jade',)), 'JagsLexer': ('pygments.lexers.math', 'JAGS', ('jags',), ('*.jag', '*.bug'), ()), 'JasminLexer': ('pygments.lexers.jvm', 'Jasmin', ('jasmin', 'jasminxt'), ('*.j',), ()), 'JavaLexer': ('pygments.lexers.jvm', 'Java', ('java',), ('*.java',), ('text/x-java',)), 'JavascriptDjangoLexer': ('pygments.lexers.templates', 'JavaScript+Django/Jinja', ('js+django', 'javascript+django', 'js+jinja', 'javascript+jinja'), (), ('application/x-javascript+django', 'application/x-javascript+jinja', 'text/x-javascript+django', 'text/x-javascript+jinja', 'text/javascript+django', 'text/javascript+jinja')), 'JavascriptErbLexer': ('pygments.lexers.templates', 'JavaScript+Ruby', ('js+erb', 'javascript+erb', 'js+ruby', 'javascript+ruby'), (), ('application/x-javascript+ruby', 'text/x-javascript+ruby', 'text/javascript+ruby')), 'JavascriptGenshiLexer': ('pygments.lexers.templates', 'JavaScript+Genshi Text', ('js+genshitext', 'js+genshi', 'javascript+genshitext', 'javascript+genshi'), (), ('application/x-javascript+genshi', 'text/x-javascript+genshi', 'text/javascript+genshi')), - 'JavascriptLexer': ('pygments.lexers.web', 'JavaScript', ('js', 'javascript'), ('*.js',), ('application/javascript', 'application/x-javascript', 'text/x-javascript', 'text/javascript')), + 'JavascriptLexer': ('pygments.lexers.javascript', 'JavaScript', ('js', 'javascript'), ('*.js',), ('application/javascript', 'application/x-javascript', 'text/x-javascript', 'text/javascript')), 'JavascriptPhpLexer': ('pygments.lexers.templates', 'JavaScript+PHP', ('js+php', 'javascript+php'), (), ('application/x-javascript+php', 'text/x-javascript+php', 'text/javascript+php')), 'JavascriptSmartyLexer': ('pygments.lexers.templates', 'JavaScript+Smarty', ('js+smarty', 'javascript+smarty'), (), ('application/x-javascript+smarty', 'text/x-javascript+smarty', 'text/javascript+smarty')), - 'JsonLexer': ('pygments.lexers.web', 'JSON', ('json',), ('*.json',), ('application/json',)), + 'JsonLexer': ('pygments.lexers.data', 'JSON', ('json',), ('*.json',), ('application/json',)), 'JspLexer': ('pygments.lexers.templates', 'Java Server Page', ('jsp',), ('*.jsp',), ('application/x-jsp',)), 'JuliaConsoleLexer': ('pygments.lexers.math', 'Julia console', ('jlcon',), (), ()), 'JuliaLexer': ('pygments.lexers.math', 'Julia', ('julia', 'jl'), ('*.jl',), ('text/x-julia', 'application/x-julia')), - 'KalLexer': ('pygments.lexers.web', 'Kal', ('kal',), ('*.kal',), ('text/kal', 'application/kal')), + 'KalLexer': ('pygments.lexers.javascript', 'Kal', ('kal',), ('*.kal',), ('text/kal', 'application/kal')), 'KconfigLexer': ('pygments.lexers.configs', 'Kconfig', ('kconfig', 'menuconfig', 'linux-config', 'kernel-config'), ('Kconfig', '*Config.in*', 'external.in*', 'standard-modules.in'), ('text/x-kconfig',)), 'KokaLexer': ('pygments.lexers.haskell', 'Koka', ('koka',), ('*.kk', '*.kki'), ('text/x-koka',)), 'KotlinLexer': ('pygments.lexers.jvm', 'Kotlin', ('kotlin',), ('*.kt',), ('text/x-kotlin',)), @@ -186,7 +187,7 @@ LEXERS = { 'LassoCssLexer': ('pygments.lexers.templates', 'CSS+Lasso', ('css+lasso',), (), ('text/css+lasso',)), 'LassoHtmlLexer': ('pygments.lexers.templates', 'HTML+Lasso', ('html+lasso',), (), ('text/html+lasso', 'application/x-httpd-lasso', 'application/x-httpd-lasso[89]')), 'LassoJavascriptLexer': ('pygments.lexers.templates', 'JavaScript+Lasso', ('js+lasso', 'javascript+lasso'), (), ('application/x-javascript+lasso', 'text/x-javascript+lasso', 'text/javascript+lasso')), - 'LassoLexer': ('pygments.lexers.web', 'Lasso', ('lasso', 'lassoscript'), ('*.lasso', '*.lasso[89]'), ('text/x-lasso',)), + 'LassoLexer': ('pygments.lexers.javascript', 'Lasso', ('lasso', 'lassoscript'), ('*.lasso', '*.lasso[89]'), ('text/x-lasso',)), 'LassoXmlLexer': ('pygments.lexers.templates', 'XML+Lasso', ('xml+lasso',), (), ('application/xml+lasso',)), 'LighttpdConfLexer': ('pygments.lexers.configs', 'Lighttpd configuration file', ('lighty', 'lighttpd'), (), ('text/x-lighttpd-conf',)), 'LimboLexer': ('pygments.lexers.inferno', 'Limbo', ('limbo',), ('*.b',), ('text/limbo',)), @@ -195,7 +196,7 @@ LEXERS = { 'LiterateCryptolLexer': ('pygments.lexers.haskell', 'Literate Cryptol', ('lcry', 'literate-cryptol', 'lcryptol'), ('*.lcry',), ('text/x-literate-cryptol',)), 'LiterateHaskellLexer': ('pygments.lexers.haskell', 'Literate Haskell', ('lhs', 'literate-haskell', 'lhaskell'), ('*.lhs',), ('text/x-literate-haskell',)), 'LiterateIdrisLexer': ('pygments.lexers.haskell', 'Literate Idris', ('lidr', 'literate-idris', 'lidris'), ('*.lidr',), ('text/x-literate-idris',)), - 'LiveScriptLexer': ('pygments.lexers.web', 'LiveScript', ('live-script', 'livescript'), ('*.ls',), ('text/livescript',)), + 'LiveScriptLexer': ('pygments.lexers.javascript', 'LiveScript', ('live-script', 'livescript'), ('*.ls',), ('text/livescript',)), 'LlvmLexer': ('pygments.lexers.asm', 'LLVM', ('llvm',), ('*.ll',), ('text/x-llvm',)), 'LogosLexer': ('pygments.lexers.c_like.objective', 'Logos', ('logos',), ('*.x', '*.xi', '*.xm', '*.xmi'), ('text/x-logos',)), 'LogtalkLexer': ('pygments.lexers.prolog', 'Logtalk', ('logtalk',), ('*.lgt', '*.logtalk'), ('text/x-logtalk',)), @@ -208,7 +209,7 @@ LEXERS = { 'MakoLexer': ('pygments.lexers.templates', 'Mako', ('mako',), ('*.mao',), ('application/x-mako',)), 'MakoXmlLexer': ('pygments.lexers.templates', 'XML+Mako', ('xml+mako',), (), ('application/xml+mako',)), 'MaqlLexer': ('pygments.lexers.business', 'MAQL', ('maql',), ('*.maql',), ('text/x-gooddata-maql', 'application/x-gooddata-maql')), - 'MaskLexer': ('pygments.lexers.web', 'Mask', ('mask',), ('*.mask',), ('text/x-mask',)), + 'MaskLexer': ('pygments.lexers.javascript', 'Mask', ('mask',), ('*.mask',), ('text/x-mask',)), 'MasonLexer': ('pygments.lexers.templates', 'Mason', ('mason',), ('*.m', '*.mhtml', '*.mc', '*.mi', 'autohandler', 'dhandler'), ('application/x-mason',)), 'MathematicaLexer': ('pygments.lexers.math', 'Mathematica', ('mathematica', 'mma', 'nb'), ('*.nb', '*.cdf', '*.nbp', '*.ma'), ('application/mathematica', 'application/vnd.wolfram.mathematica', 'application/vnd.wolfram.mathematica.package', 'application/vnd.wolfram.cdf')), 'MatlabLexer': ('pygments.lexers.math', 'Matlab', ('matlab',), ('*.m',), ('text/matlab',)), @@ -222,7 +223,7 @@ LEXERS = { 'MqlLexer': ('pygments.lexers.c_like.other', 'MQL', ('mql', 'mq4', 'mq5', 'mql4', 'mql5'), ('*.mq4', '*.mq5', '*.mqh'), ('text/x-mql',)), 'MscgenLexer': ('pygments.lexers.dsls', 'Mscgen', ('mscgen', 'msc'), ('*.msc',), ()), 'MuPADLexer': ('pygments.lexers.math', 'MuPAD', ('mupad',), ('*.mu',), ()), - 'MxmlLexer': ('pygments.lexers.web', 'MXML', ('mxml',), ('*.mxml',), ()), + 'MxmlLexer': ('pygments.lexers.actionscript', 'MXML', ('mxml',), ('*.mxml',), ()), 'MySqlLexer': ('pygments.lexers.sql', 'MySQL', ('mysql',), (), ('text/x-mysql',)), 'MyghtyCssLexer': ('pygments.lexers.templates', 'CSS+Myghty', ('css+myghty',), (), ('text/css+myghty',)), 'MyghtyHtmlLexer': ('pygments.lexers.templates', 'HTML+Myghty', ('html+myghty',), (), ('text/html+myghty',)), @@ -244,7 +245,7 @@ LEXERS = { 'ObjdumpLexer': ('pygments.lexers.asm', 'objdump', ('objdump',), ('*.objdump',), ('text/x-objdump',)), 'ObjectiveCLexer': ('pygments.lexers.c_like.objective', 'Objective-C', ('objective-c', 'objectivec', 'obj-c', 'objc'), ('*.m', '*.h'), ('text/x-objective-c',)), 'ObjectiveCppLexer': ('pygments.lexers.c_like.objective', 'Objective-C++', ('objective-c++', 'objectivec++', 'obj-c++', 'objc++'), ('*.mm', '*.hh'), ('text/x-objective-c++',)), - 'ObjectiveJLexer': ('pygments.lexers.web', 'Objective-J', ('objective-j', 'objectivej', 'obj-j', 'objj'), ('*.j',), ('text/x-objective-j',)), + 'ObjectiveJLexer': ('pygments.lexers.javascript', 'Objective-J', ('objective-j', 'objectivej', 'obj-j', 'objj'), ('*.j',), ('text/x-objective-j',)), 'OcamlLexer': ('pygments.lexers.misc.ml', 'OCaml', ('ocaml',), ('*.ml', '*.mli', '*.mll', '*.mly'), ('text/x-ocaml',)), 'OctaveLexer': ('pygments.lexers.math', 'Octave', ('octave',), ('*.m',), ('text/octave',)), 'OocLexer': ('pygments.lexers.misc.ooc', 'Ooc', ('ooc',), ('*.ooc',), ('text/x-ooc',)), @@ -254,7 +255,7 @@ LEXERS = { 'PawnLexer': ('pygments.lexers.misc.pawn', 'Pawn', ('pawn',), ('*.p', '*.pwn', '*.inc'), ('text/x-pawn',)), 'Perl6Lexer': ('pygments.lexers.perl', 'Perl6', ('perl6', 'pl6'), ('*.pl', '*.pm', '*.nqp', '*.p6', '*.6pl', '*.p6l', '*.pl6', '*.6pm', '*.p6m', '*.pm6', '*.t'), ('text/x-perl6', 'application/x-perl6')), 'PerlLexer': ('pygments.lexers.perl', 'Perl', ('perl', 'pl'), ('*.pl', '*.pm', '*.t'), ('text/x-perl', 'application/x-perl')), - 'PhpLexer': ('pygments.lexers.web', 'PHP', ('php', 'php3', 'php4', 'php5'), ('*.php', '*.php[345]', '*.inc'), ('text/x-php',)), + 'PhpLexer': ('pygments.lexers.php', 'PHP', ('php', 'php3', 'php4', 'php5'), ('*.php', '*.php[345]', '*.inc'), ('text/x-php',)), 'PigLexer': ('pygments.lexers.jvm', 'Pig', ('pig',), ('*.pig',), ('text/x-pig',)), 'PikeLexer': ('pygments.lexers.c_like.other', 'Pike', ('pike',), ('*.pike', '*.pmod'), ('text/x-pike',)), 'PlPgsqlLexer': ('pygments.lexers.sql', 'PL/pgSQL', ('plpgsql',), (), ('text/x-plpgsql',)), @@ -274,7 +275,7 @@ LEXERS = { 'PythonLexer': ('pygments.lexers.python', 'Python', ('python', 'py', 'sage'), ('*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript', '*.tac', '*.sage'), ('text/x-python', 'application/x-python')), 'PythonTracebackLexer': ('pygments.lexers.python', 'Python Traceback', ('pytb',), ('*.pytb',), ('text/x-python-traceback',)), 'QBasicLexer': ('pygments.lexers.misc.basic', 'QBasic', ('qbasic', 'basic'), ('*.BAS', '*.bas'), ('text/basic',)), - 'QmlLexer': ('pygments.lexers.web', 'QML', ('qml',), ('*.qml',), ('application/x-qml',)), + 'QmlLexer': ('pygments.lexers.webmisc', 'QML', ('qml',), ('*.qml',), ('application/x-qml',)), 'RConsoleLexer': ('pygments.lexers.math', 'RConsole', ('rconsole', 'rout'), ('*.Rout',), ()), 'RPMSpecLexer': ('pygments.lexers.installers', 'RPMSpec', ('spec',), ('*.spec',), ('text/x-rpm-spec',)), 'RacketLexer': ('pygments.lexers.lisp', 'Racket', ('racket', 'rkt'), ('*.rkt', '*.rktd', '*.rktl'), ('text/x-racket', 'application/x-racket')), @@ -303,19 +304,20 @@ LEXERS = { 'RustLexer': ('pygments.lexers.c_like.rust', 'Rust', ('rust',), ('*.rs',), ('text/x-rustsrc',)), 'SLexer': ('pygments.lexers.math', 'S', ('splus', 's', 'r'), ('*.S', '*.R', '.Rhistory', '.Rprofile', '.Renviron'), ('text/S-plus', 'text/S', 'text/x-r-source', 'text/x-r', 'text/x-R', 'text/x-r-history', 'text/x-r-profile')), 'SMLLexer': ('pygments.lexers.misc.ml', 'Standard ML', ('sml',), ('*.sml', '*.sig', '*.fun'), ('text/x-standardml', 'application/x-standardml')), - 'SassLexer': ('pygments.lexers.web', 'Sass', ('sass',), ('*.sass',), ('text/x-sass',)), + 'SassLexer': ('pygments.lexers.css', 'Sass', ('sass',), ('*.sass',), ('text/x-sass',)), 'ScalaLexer': ('pygments.lexers.jvm', 'Scala', ('scala',), ('*.scala',), ('text/x-scala',)), - 'ScamlLexer': ('pygments.lexers.web', 'Scaml', ('scaml',), ('*.scaml',), ('text/x-scaml',)), + 'ScamlLexer': ('pygments.lexers.html', 'Scaml', ('scaml',), ('*.scaml',), ('text/x-scaml',)), 'SchemeLexer': ('pygments.lexers.lisp', 'Scheme', ('scheme', 'scm'), ('*.scm', '*.ss'), ('text/x-scheme', 'application/x-scheme')), 'ScilabLexer': ('pygments.lexers.math', 'Scilab', ('scilab',), ('*.sci', '*.sce', '*.tst'), ('text/scilab',)), - 'ScssLexer': ('pygments.lexers.web', 'SCSS', ('scss',), ('*.scss',), ('text/x-scss',)), + 'ScssLexer': ('pygments.lexers.css', 'SCSS', ('scss',), ('*.scss',), ('text/x-scss',)), 'ShellSessionLexer': ('pygments.lexers.shell', 'Shell Session', ('shell-session',), ('*.shell-session',), ('application/x-sh-session',)), - 'SlimLexer': ('pygments.lexers.web', 'Slim', ('slim',), ('*.slim',), ('text/x-slim',)), + 'SlimLexer': ('pygments.lexers.webmisc', 'Slim', ('slim',), ('*.slim',), ('text/x-slim',)), 'SmaliLexer': ('pygments.lexers.dalvik', 'Smali', ('smali',), ('*.smali',), ('text/smali',)), 'SmalltalkLexer': ('pygments.lexers.misc.smalltalk', 'Smalltalk', ('smalltalk', 'squeak', 'st'), ('*.st',), ('text/x-smalltalk',)), 'SmartyLexer': ('pygments.lexers.templates', 'Smarty', ('smarty',), ('*.tpl',), ('application/x-smarty',)), 'SnobolLexer': ('pygments.lexers.misc.snobol', 'Snobol', ('snobol',), ('*.snobol',), ('text/x-snobol',)), 'SourcePawnLexer': ('pygments.lexers.misc.pawn', 'SourcePawn', ('sp',), ('*.sp',), ('text/x-sourcepawn',)), + 'SourcesListLexer': ('pygments.lexers.installers', 'Debian Sourcelist', ('sourceslist', 'sources.list', 'debsources'), ('sources.list',), ()), 'SparqlLexer': ('pygments.lexers.rdf', 'SPARQL', ('sparql',), ('*.rq', '*.sparql'), ('application/sparql-query',)), 'SqlLexer': ('pygments.lexers.sql', 'SQL', ('sql',), ('*.sql',), ('text/x-sql',)), 'SqliteConsoleLexer': ('pygments.lexers.sql', 'sqlite3con', ('sqlite3',), ('*.sqlite3-console',), ('text/x-sqlite3-console',)), @@ -332,7 +334,7 @@ LEXERS = { 'TextLexer': ('pygments.lexers.special', 'Text only', ('text',), ('*.txt',), ('text/plain',)), 'TodotxtLexer': ('pygments.lexers.textfmts', 'Todotxt', ('todotxt',), ('todo.txt', '*.todotxt'), ('text/x-todo',)), 'TreetopLexer': ('pygments.lexers.parsers', 'Treetop', ('treetop',), ('*.treetop', '*.tt'), ()), - 'TypeScriptLexer': ('pygments.lexers.web', 'TypeScript', ('ts',), ('*.ts',), ('text/x-typescript',)), + 'TypeScriptLexer': ('pygments.lexers.javascript', 'TypeScript', ('ts',), ('*.ts',), ('text/x-typescript',)), 'UrbiscriptLexer': ('pygments.lexers.misc.urbi', 'UrbiScript', ('urbiscript',), ('*.u',), ('application/x-urbiscript',)), 'VCTreeStatusLexer': ('pygments.lexers.console', 'VCTreeStatus', ('vctreestatus',), (), ()), 'VGLLexer': ('pygments.lexers.dsls', 'VGL', ('vgl',), ('*.rpf',), ()), @@ -345,17 +347,17 @@ LEXERS = { 'VerilogLexer': ('pygments.lexers.hdl', 'verilog', ('verilog', 'v'), ('*.v',), ('text/x-verilog',)), 'VhdlLexer': ('pygments.lexers.hdl', 'vhdl', ('vhdl',), ('*.vhdl', '*.vhd'), ('text/x-vhdl',)), 'VimLexer': ('pygments.lexers.textedit', 'VimL', ('vim',), ('*.vim', '.vimrc', '.exrc', '.gvimrc', '_vimrc', '_exrc', '_gvimrc', 'vimrc', 'gvimrc'), ('text/x-vim',)), - 'XQueryLexer': ('pygments.lexers.web', 'XQuery', ('xquery', 'xqy', 'xq', 'xql', 'xqm'), ('*.xqy', '*.xquery', '*.xq', '*.xql', '*.xqm'), ('text/xquery', 'application/xquery')), + 'XQueryLexer': ('pygments.lexers.webmisc', 'XQuery', ('xquery', 'xqy', 'xq', 'xql', 'xqm'), ('*.xqy', '*.xquery', '*.xq', '*.xql', '*.xqm'), ('text/xquery', 'application/xquery')), 'XmlDjangoLexer': ('pygments.lexers.templates', 'XML+Django/Jinja', ('xml+django', 'xml+jinja'), (), ('application/xml+django', 'application/xml+jinja')), 'XmlErbLexer': ('pygments.lexers.templates', 'XML+Ruby', ('xml+erb', 'xml+ruby'), (), ('application/xml+ruby',)), - 'XmlLexer': ('pygments.lexers.web', 'XML', ('xml',), ('*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', '*.wsdl', '*.wsf'), ('text/xml', 'application/xml', 'image/svg+xml', 'application/rss+xml', 'application/atom+xml')), + 'XmlLexer': ('pygments.lexers.html', 'XML', ('xml',), ('*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', '*.wsdl', '*.wsf'), ('text/xml', 'application/xml', 'image/svg+xml', 'application/rss+xml', 'application/atom+xml')), 'XmlPhpLexer': ('pygments.lexers.templates', 'XML+PHP', ('xml+php',), (), ('application/xml+php',)), 'XmlSmartyLexer': ('pygments.lexers.templates', 'XML+Smarty', ('xml+smarty',), (), ('application/xml+smarty',)), - 'XsltLexer': ('pygments.lexers.web', 'XSLT', ('xslt',), ('*.xsl', '*.xslt', '*.xpl'), ('application/xsl+xml', 'application/xslt+xml')), + 'XsltLexer': ('pygments.lexers.html', 'XSLT', ('xslt',), ('*.xsl', '*.xslt', '*.xpl'), ('application/xsl+xml', 'application/xslt+xml')), 'XtendLexer': ('pygments.lexers.jvm', 'Xtend', ('xtend',), ('*.xtend',), ('text/x-xtend',)), 'YamlJinjaLexer': ('pygments.lexers.templates', 'YAML+Jinja', ('yaml+jinja', 'salt', 'sls'), ('*.sls',), ('text/x-yaml+jinja', 'text/x-sls')), 'YamlLexer': ('pygments.lexers.data', 'YAML', ('yaml',), ('*.yaml', '*.yml'), ('text/x-yaml',)), - 'ZephirLexer': ('pygments.lexers.web', 'Zephir', ('zephir',), ('*.zep',), ()), + 'ZephirLexer': ('pygments.lexers.php', 'Zephir', ('zephir',), ('*.zep',), ()), } if __name__ == '__main__': diff --git a/pygments/lexers/actionscript.py b/pygments/lexers/actionscript.py new file mode 100644 index 00000000..7b866865 --- /dev/null +++ b/pygments/lexers/actionscript.py @@ -0,0 +1,238 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.actionscript + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Lexers for ActionScript and MXML. + + :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import RegexLexer, bygroups, using, this, words +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Punctuation + +__all__ = ['ActionScriptLexer', 'ActionScript3Lexer', 'MxmlLexer'] + + +class ActionScriptLexer(RegexLexer): + """ + For ActionScript source code. + + .. versionadded:: 0.9 + """ + + name = 'ActionScript' + aliases = ['as', 'actionscript'] + filenames = ['*.as'] + mimetypes = ['application/x-actionscript', 'text/x-actionscript', + 'text/actionscript'] + + flags = re.DOTALL + tokens = { + 'root': [ + (r'\s+', Text), + (r'//.*?\n', Comment.Single), + (r'/\*.*?\*/', Comment.Multiline), + (r'/(\\\\|\\/|[^/\n])*/[gim]*', String.Regex), + (r'[~\^\*!%&<>\|+=:;,/?\\-]+', Operator), + (r'[{}\[\]();.]+', Punctuation), + (words(( + 'case', 'default', 'for', 'each', 'in', 'while', 'do', 'break', + 'return', 'continue', 'if', 'else', 'throw', 'try', 'catch', + 'var', 'with', 'new', 'typeof', 'arguments', 'instanceof', 'this', + 'switch'), suffix=r'\b'), + Keyword), + (words(( + 'class', 'public', 'final', 'internal', 'native', 'override', 'private', + 'protected', 'static', 'import', 'extends', 'implements', 'interface', + 'intrinsic', 'return', 'super', 'dynamic', 'function', 'const', 'get', + 'namespace', 'package', 'set'), suffix=r'\b'), + Keyword.Declaration), + (r'(true|false|null|NaN|Infinity|-Infinity|undefined|Void)\b', + Keyword.Constant), + (words(( + 'Accessibility', 'AccessibilityProperties', 'ActionScriptVersion', + 'ActivityEvent', 'AntiAliasType', 'ApplicationDomain', 'AsBroadcaster', 'Array', + 'AsyncErrorEvent', 'AVM1Movie', 'BevelFilter', 'Bitmap', 'BitmapData', + 'BitmapDataChannel', 'BitmapFilter', 'BitmapFilterQuality', 'BitmapFilterType', + 'BlendMode', 'BlurFilter', 'Boolean', 'ByteArray', 'Camera', 'Capabilities', 'CapsStyle', + 'Class', 'Color', 'ColorMatrixFilter', 'ColorTransform', 'ContextMenu', + 'ContextMenuBuiltInItems', 'ContextMenuEvent', 'ContextMenuItem', + 'ConvultionFilter', 'CSMSettings', 'DataEvent', 'Date', 'DefinitionError', + 'DeleteObjectSample', 'Dictionary', 'DisplacmentMapFilter', 'DisplayObject', + 'DisplacmentMapFilterMode', 'DisplayObjectContainer', 'DropShadowFilter', + 'Endian', 'EOFError', 'Error', 'ErrorEvent', 'EvalError', 'Event', 'EventDispatcher', + 'EventPhase', 'ExternalInterface', 'FileFilter', 'FileReference', + 'FileReferenceList', 'FocusDirection', 'FocusEvent', 'Font', 'FontStyle', 'FontType', + 'FrameLabel', 'FullScreenEvent', 'Function', 'GlowFilter', 'GradientBevelFilter', + 'GradientGlowFilter', 'GradientType', 'Graphics', 'GridFitType', 'HTTPStatusEvent', + 'IBitmapDrawable', 'ID3Info', 'IDataInput', 'IDataOutput', 'IDynamicPropertyOutput' + 'IDynamicPropertyWriter', 'IEventDispatcher', 'IExternalizable', + 'IllegalOperationError', 'IME', 'IMEConversionMode', 'IMEEvent', 'int', + 'InteractiveObject', 'InterpolationMethod', 'InvalidSWFError', 'InvokeEvent', + 'IOError', 'IOErrorEvent', 'JointStyle', 'Key', 'Keyboard', 'KeyboardEvent', 'KeyLocation', + 'LineScaleMode', 'Loader', 'LoaderContext', 'LoaderInfo', 'LoadVars', 'LocalConnection', + 'Locale', 'Math', 'Matrix', 'MemoryError', 'Microphone', 'MorphShape', 'Mouse', 'MouseEvent', + 'MovieClip', 'MovieClipLoader', 'Namespace', 'NetConnection', 'NetStatusEvent', + 'NetStream', 'NewObjectSample', 'Number', 'Object', 'ObjectEncoding', 'PixelSnapping', + 'Point', 'PrintJob', 'PrintJobOptions', 'PrintJobOrientation', 'ProgressEvent', 'Proxy', + 'QName', 'RangeError', 'Rectangle', 'ReferenceError', 'RegExp', 'Responder', 'Sample', 'Scene', + 'ScriptTimeoutError', 'Security', 'SecurityDomain', 'SecurityError', + 'SecurityErrorEvent', 'SecurityPanel', 'Selection', 'Shape', 'SharedObject', + 'SharedObjectFlushStatus', 'SimpleButton', 'Socket', 'Sound', 'SoundChannel', + 'SoundLoaderContext', 'SoundMixer', 'SoundTransform', 'SpreadMethod', 'Sprite', + 'StackFrame', 'StackOverflowError', 'Stage', 'StageAlign', 'StageDisplayState', + 'StageQuality', 'StageScaleMode', 'StaticText', 'StatusEvent', 'String', 'StyleSheet', + 'SWFVersion', 'SyncEvent', 'SyntaxError', 'System', 'TextColorType', 'TextField', + 'TextFieldAutoSize', 'TextFieldType', 'TextFormat', 'TextFormatAlign', + 'TextLineMetrics', 'TextRenderer', 'TextSnapshot', 'Timer', 'TimerEvent', 'Transform', + 'TypeError', 'uint', 'URIError', 'URLLoader', 'URLLoaderDataFormat', 'URLRequest', + 'URLRequestHeader', 'URLRequestMethod', 'URLStream', 'URLVariabeles', 'VerifyError', + 'Video', 'XML', 'XMLDocument', 'XMLList', 'XMLNode', 'XMLNodeType', 'XMLSocket', + 'XMLUI'), suffix=r'\b'), + Name.Builtin), + (words(( + 'decodeURI', 'decodeURIComponent', 'encodeURI', 'escape', 'eval', 'isFinite', 'isNaN', + 'isXMLName', 'clearInterval', 'fscommand', 'getTimer', 'getURL', 'getVersion', + 'isFinite', 'parseFloat', 'parseInt', 'setInterval', 'trace', 'updateAfterEvent', + 'unescape'), suffix=r'\b'), + Name.Function), + (r'[$a-zA-Z_]\w*', Name.Other), + (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), + (r'0x[0-9a-f]+', Number.Hex), + (r'[0-9]+', Number.Integer), + (r'"(\\\\|\\"|[^"])*"', String.Double), + (r"'(\\\\|\\'|[^'])*'", String.Single), + ] + } + + +class ActionScript3Lexer(RegexLexer): + """ + For ActionScript 3 source code. + + .. versionadded:: 0.11 + """ + + name = 'ActionScript 3' + aliases = ['as3', 'actionscript3'] + filenames = ['*.as'] + mimetypes = ['application/x-actionscript3', 'text/x-actionscript3', + 'text/actionscript3'] + + identifier = r'[$a-zA-Z_]\w*' + typeidentifier = identifier + '(?:\.<\w+>)?' + + flags = re.DOTALL | re.MULTILINE + tokens = { + 'root': [ + (r'\s+', Text), + (r'(function\s+)(' + identifier + r')(\s*)(\()', + bygroups(Keyword.Declaration, Name.Function, Text, Operator), + 'funcparams'), + (r'(var|const)(\s+)(' + identifier + r')(\s*)(:)(\s*)(' + + typeidentifier + r')', + bygroups(Keyword.Declaration, Text, Name, Text, Punctuation, Text, + Keyword.Type)), + (r'(import|package)(\s+)((?:' + identifier + r'|\.)+)(\s*)', + bygroups(Keyword, Text, Name.Namespace, Text)), + (r'(new)(\s+)(' + typeidentifier + r')(\s*)(\()', + bygroups(Keyword, Text, Keyword.Type, Text, Operator)), + (r'//.*?\n', Comment.Single), + (r'/\*.*?\*/', Comment.Multiline), + (r'/(\\\\|\\/|[^\n])*/[gisx]*', String.Regex), + (r'(\.)(' + identifier + r')', bygroups(Operator, Name.Attribute)), + (r'(case|default|for|each|in|while|do|break|return|continue|if|else|' + r'throw|try|catch|with|new|typeof|arguments|instanceof|this|' + r'switch|import|include|as|is)\b', + Keyword), + (r'(class|public|final|internal|native|override|private|protected|' + r'static|import|extends|implements|interface|intrinsic|return|super|' + r'dynamic|function|const|get|namespace|package|set)\b', + Keyword.Declaration), + (r'(true|false|null|NaN|Infinity|-Infinity|undefined|void)\b', + Keyword.Constant), + (r'(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|' + r'isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|' + r'isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|' + r'unescape)\b', Name.Function), + (identifier, Name), + (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), + (r'0x[0-9a-f]+', Number.Hex), + (r'[0-9]+', Number.Integer), + (r'"(\\\\|\\"|[^"])*"', String.Double), + (r"'(\\\\|\\'|[^'])*'", String.Single), + (r'[~\^\*!%&<>\|+=:;,/?\\{}\[\]().-]+', Operator), + ], + 'funcparams': [ + (r'\s+', Text), + (r'(\s*)(\.\.\.)?(' + identifier + r')(\s*)(:)(\s*)(' + + typeidentifier + r'|\*)(\s*)', + bygroups(Text, Punctuation, Name, Text, Operator, Text, + Keyword.Type, Text), 'defval'), + (r'\)', Operator, 'type') + ], + 'type': [ + (r'(\s*)(:)(\s*)(' + typeidentifier + r'|\*)', + bygroups(Text, Operator, Text, Keyword.Type), '#pop:2'), + (r'\s*', Text, '#pop:2') + ], + 'defval': [ + (r'(=)(\s*)([^(),]+)(\s*)(,?)', + bygroups(Operator, Text, using(this), Text, Operator), '#pop'), + (r',?', Operator, '#pop') + ] + } + + def analyse_text(text): + if re.match(r'\w+\s*:\s*\w', text): + return 0.3 + return 0 + + +class MxmlLexer(RegexLexer): + """ + For MXML markup. + Nested AS3 in <script> tags is highlighted by the appropriate lexer. + + .. versionadded:: 1.1 + """ + flags = re.MULTILINE | re.DOTALL + name = 'MXML' + aliases = ['mxml'] + filenames = ['*.mxml'] + mimetimes = ['text/xml', 'application/xml'] + + tokens = { + 'root': [ + ('[^<&]+', Text), + (r'&\S*?;', Name.Entity), + (r'(\<\!\[CDATA\[)(.*?)(\]\]\>)', + bygroups(String, using(ActionScript3Lexer), String)), + ('<!--', Comment, 'comment'), + (r'<\?.*?\?>', Comment.Preproc), + ('<![^>]*>', Comment.Preproc), + (r'<\s*[\w:.-]+', Name.Tag, 'tag'), + (r'<\s*/\s*[\w:.-]+\s*>', Name.Tag), + ], + 'comment': [ + ('[^-]+', Comment), + ('-->', Comment, '#pop'), + ('-', Comment), + ], + 'tag': [ + (r'\s+', Text), + (r'[\w.:-]+\s*=', Name.Attribute, 'attr'), + (r'/?\s*>', Name.Tag, '#pop'), + ], + 'attr': [ + ('\s+', Text), + ('".*?"', String, '#pop'), + ("'.*?'", String, '#pop'), + (r'[^\s>]+', String, '#pop'), + ], + } diff --git a/pygments/lexers/css.py b/pygments/lexers/css.py new file mode 100644 index 00000000..33c1ad53 --- /dev/null +++ b/pygments/lexers/css.py @@ -0,0 +1,496 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.css + ~~~~~~~~~~~~~~~~~~~ + + Lexers for CSS and related stylesheet formats. + + :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re +import copy + +from pygments.lexer import ExtendedRegexLexer, RegexLexer, include, bygroups, \ + default, words +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Punctuation +from pygments.util import iteritems + +__all__ = ['CssLexer', 'SassLexer', 'ScssLexer'] + + +class CssLexer(RegexLexer): + """ + For CSS (Cascading Style Sheets). + """ + + name = 'CSS' + aliases = ['css'] + filenames = ['*.css'] + mimetypes = ['text/css'] + + tokens = { + 'root': [ + include('basics'), + ], + 'basics': [ + (r'\s+', Text), + (r'/\*(?:.|\n)*?\*/', Comment), + (r'{', Punctuation, 'content'), + (r'\:[\w-]+', Name.Decorator), + (r'\.[\w-]+', Name.Class), + (r'\#[\w-]+', Name.Function), + (r'@[\w-]+', Keyword, 'atrule'), + (r'[\w-]+', Name.Tag), + (r'[~\^\*!%&$\[\]\(\)<>\|+=@:;,./?-]', Operator), + (r'"(\\\\|\\"|[^"])*"', String.Double), + (r"'(\\\\|\\'|[^'])*'", String.Single) + ], + 'atrule': [ + (r'{', Punctuation, 'atcontent'), + (r';', Punctuation, '#pop'), + include('basics'), + ], + 'atcontent': [ + include('basics'), + (r'}', Punctuation, '#pop:2'), + ], + 'content': [ + (r'\s+', Text), + (r'}', Punctuation, '#pop'), + (r'url\(.*?\)', String.Other), + (r'^@.*?$', Comment.Preproc), + (words(( + 'azimuth', 'background-attachment', 'background-color', + 'background-image', 'background-position', 'background-repeat', + 'background', 'border-bottom-color', 'border-bottom-style', + 'border-bottom-width', 'border-left-color', 'border-left-style', + 'border-left-width', 'border-right', 'border-right-color', + 'border-right-style', 'border-right-width', 'border-top-color', + 'border-top-style', 'border-top-width', 'border-bottom', + 'border-collapse', 'border-left', 'border-width', 'border-color', + 'border-spacing', 'border-style', 'border-top', 'border', 'caption-side', + 'clear', 'clip', 'color', 'content', 'counter-increment', 'counter-reset', + 'cue-after', 'cue-before', 'cue', 'cursor', 'direction', 'display', + 'elevation', 'empty-cells', 'float', 'font-family', 'font-size', + 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', + 'font-weight', 'font', 'height', 'letter-spacing', 'line-height', + 'list-style-type', 'list-style-image', 'list-style-position', + 'list-style', 'margin-bottom', 'margin-left', 'margin-right', + 'margin-top', 'margin', 'marker-offset', 'marks', 'max-height', 'max-width', + 'min-height', 'min-width', 'opacity', 'orphans', 'outline-color', + 'outline-style', 'outline-width', 'outline', 'overflow', 'overflow-x', 'overflow-y', 'padding-bottom', + 'padding-left', 'padding-right', 'padding-top', 'padding', 'page', + 'page-break-after', 'page-break-before', 'page-break-inside', + 'pause-after', 'pause-before', 'pause', 'pitch-range', 'pitch', + 'play-during', 'position', 'quotes', 'richness', 'right', 'size', + 'speak-header', 'speak-numeral', 'speak-punctuation', 'speak', + 'speech-rate', 'stress', 'table-layout', 'text-align', 'text-decoration', + 'text-indent', 'text-shadow', 'text-transform', 'top', 'unicode-bidi', + 'vertical-align', 'visibility', 'voice-family', 'volume', 'white-space', + 'widows', 'width', 'word-spacing', 'z-index', 'bottom', + 'above', 'absolute', 'always', 'armenian', 'aural', 'auto', 'avoid', 'baseline', + 'behind', 'below', 'bidi-override', 'blink', 'block', 'bolder', 'bold', 'both', + 'capitalize', 'center-left', 'center-right', 'center', 'circle', + 'cjk-ideographic', 'close-quote', 'collapse', 'condensed', 'continuous', + 'crop', 'crosshair', 'cross', 'cursive', 'dashed', 'decimal-leading-zero', + 'decimal', 'default', 'digits', 'disc', 'dotted', 'double', 'e-resize', 'embed', + 'extra-condensed', 'extra-expanded', 'expanded', 'fantasy', 'far-left', + 'far-right', 'faster', 'fast', 'fixed', 'georgian', 'groove', 'hebrew', 'help', + 'hidden', 'hide', 'higher', 'high', 'hiragana-iroha', 'hiragana', 'icon', + 'inherit', 'inline-table', 'inline', 'inset', 'inside', 'invert', 'italic', + 'justify', 'katakana-iroha', 'katakana', 'landscape', 'larger', 'large', + 'left-side', 'leftwards', 'left', 'level', 'lighter', 'line-through', 'list-item', + 'loud', 'lower-alpha', 'lower-greek', 'lower-roman', 'lowercase', 'ltr', + 'lower', 'low', 'medium', 'message-box', 'middle', 'mix', 'monospace', + 'n-resize', 'narrower', 'ne-resize', 'no-close-quote', 'no-open-quote', + 'no-repeat', 'none', 'normal', 'nowrap', 'nw-resize', 'oblique', 'once', + 'open-quote', 'outset', 'outside', 'overline', 'pointer', 'portrait', 'px', + 'relative', 'repeat-x', 'repeat-y', 'repeat', 'rgb', 'ridge', 'right-side', + 'rightwards', 's-resize', 'sans-serif', 'scroll', 'se-resize', + 'semi-condensed', 'semi-expanded', 'separate', 'serif', 'show', 'silent', + 'slower', 'slow', 'small-caps', 'small-caption', 'smaller', 'soft', 'solid', + 'spell-out', 'square', 'static', 'status-bar', 'super', 'sw-resize', + 'table-caption', 'table-cell', 'table-column', 'table-column-group', + 'table-footer-group', 'table-header-group', 'table-row', + 'table-row-group', 'text-bottom', 'text-top', 'text', 'thick', 'thin', + 'transparent', 'ultra-condensed', 'ultra-expanded', 'underline', + 'upper-alpha', 'upper-latin', 'upper-roman', 'uppercase', 'url', + 'visible', 'w-resize', 'wait', 'wider', 'x-fast', 'x-high', 'x-large', 'x-loud', + 'x-low', 'x-small', 'x-soft', 'xx-large', 'xx-small', 'yes'), suffix=r'\b'), + Keyword), + (words(( + 'indigo', 'gold', 'firebrick', 'indianred', 'yellow', 'darkolivegreen', + 'darkseagreen', 'mediumvioletred', 'mediumorchid', 'chartreuse', + 'mediumslateblue', 'black', 'springgreen', 'crimson', 'lightsalmon', 'brown', + 'turquoise', 'olivedrab', 'cyan', 'silver', 'skyblue', 'gray', 'darkturquoise', + 'goldenrod', 'darkgreen', 'darkviolet', 'darkgray', 'lightpink', 'teal', + 'darkmagenta', 'lightgoldenrodyellow', 'lavender', 'yellowgreen', 'thistle', + 'violet', 'navy', 'orchid', 'blue', 'ghostwhite', 'honeydew', 'cornflowerblue', + 'darkblue', 'darkkhaki', 'mediumpurple', 'cornsilk', 'red', 'bisque', 'slategray', + 'darkcyan', 'khaki', 'wheat', 'deepskyblue', 'darkred', 'steelblue', 'aliceblue', + 'gainsboro', 'mediumturquoise', 'floralwhite', 'coral', 'purple', 'lightgrey', + 'lightcyan', 'darksalmon', 'beige', 'azure', 'lightsteelblue', 'oldlace', + 'greenyellow', 'royalblue', 'lightseagreen', 'mistyrose', 'sienna', + 'lightcoral', 'orangered', 'navajowhite', 'lime', 'palegreen', 'burlywood', + 'seashell', 'mediumspringgreen', 'fuchsia', 'papayawhip', 'blanchedalmond', + 'peru', 'aquamarine', 'white', 'darkslategray', 'ivory', 'dodgerblue', + 'lemonchiffon', 'chocolate', 'orange', 'forestgreen', 'slateblue', 'olive', + 'mintcream', 'antiquewhite', 'darkorange', 'cadetblue', 'moccasin', + 'limegreen', 'saddlebrown', 'darkslateblue', 'lightskyblue', 'deeppink', + 'plum', 'aqua', 'darkgoldenrod', 'maroon', 'sandybrown', 'magenta', 'tan', + 'rosybrown', 'pink', 'lightblue', 'palevioletred', 'mediumseagreen', + 'dimgray', 'powderblue', 'seagreen', 'snow', 'mediumblue', 'midnightblue', + 'paleturquoise', 'palegoldenrod', 'whitesmoke', 'darkorchid', 'salmon', + 'lightslategray', 'lawngreen', 'lightgreen', 'tomato', 'hotpink', + 'lightyellow', 'lavenderblush', 'linen', 'mediumaquamarine', 'green', + 'blueviolet', 'peachpuff'), suffix=r'\b'), + Name.Builtin), + (r'\!important', Comment.Preproc), + (r'/\*(?:.|\n)*?\*/', Comment), + (r'\#[a-zA-Z0-9]{1,6}', Number), + (r'[\.-]?[0-9]*[\.]?[0-9]+(em|px|pt|pc|in|mm|cm|ex|s)\b', Number), + # Separate regex for percentages, as can't do word boundaries with % + (r'[\.-]?[0-9]*[\.]?[0-9]+%', Number), + (r'-?[0-9]+', Number), + (r'[~\^\*!%&<>\|+=@:,./?-]+', Operator), + (r'[\[\]();]+', Punctuation), + (r'"(\\\\|\\"|[^"])*"', String.Double), + (r"'(\\\\|\\'|[^'])*'", String.Single), + (r'[a-zA-Z_]\w*', Name) + ] + } + + +common_sass_tokens = { + 'value': [ + (r'[ \t]+', Text), + (r'[!$][\w-]+', Name.Variable), + (r'url\(', String.Other, 'string-url'), + (r'[a-z_-][\w-]*(?=\()', Name.Function), + (words(( + 'azimuth', 'background-attachment', 'background-color', + 'background-image', 'background-position', 'background-repeat', + 'background', 'border-bottom-color', 'border-bottom-style', + 'border-bottom-width', 'border-left-color', 'border-left-style', + 'border-left-width', 'border-right', 'border-right-color', + 'border-right-style', 'border-right-width', 'border-top-color', + 'border-top-style', 'border-top-width', 'border-bottom', + 'border-collapse', 'border-left', 'border-width', 'border-color', + 'border-spacing', 'border-style', 'border-top', 'border', 'caption-side', + 'clear', 'clip', 'color', 'content', 'counter-increment', 'counter-reset', + 'cue-after', 'cue-before', 'cue', 'cursor', 'direction', 'display', + 'elevation', 'empty-cells', 'float', 'font-family', 'font-size', + 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', + 'font-weight', 'font', 'height', 'letter-spacing', 'line-height', + 'list-style-type', 'list-style-image', 'list-style-position', + 'list-style', 'margin-bottom', 'margin-left', 'margin-right', + 'margin-top', 'margin', 'marker-offset', 'marks', 'max-height', 'max-width', + 'min-height', 'min-width', 'opacity', 'orphans', 'outline', 'outline-color', + 'outline-style', 'outline-width', 'overflow', 'padding-bottom', + 'padding-left', 'padding-right', 'padding-top', 'padding', 'page', + 'page-break-after', 'page-break-before', 'page-break-inside', + 'pause-after', 'pause-before', 'pause', 'pitch', 'pitch-range', + 'play-during', 'position', 'quotes', 'richness', 'right', 'size', + 'speak-header', 'speak-numeral', 'speak-punctuation', 'speak', + 'speech-rate', 'stress', 'table-layout', 'text-align', 'text-decoration', + 'text-indent', 'text-shadow', 'text-transform', 'top', 'unicode-bidi', + 'vertical-align', 'visibility', 'voice-family', 'volume', 'white-space', + 'widows', 'width', 'word-spacing', 'z-index', 'bottom', 'left', + 'above', 'absolute', 'always', 'armenian', 'aural', 'auto', 'avoid', 'baseline', + 'behind', 'below', 'bidi-override', 'blink', 'block', 'bold', 'bolder', 'both', + 'capitalize', 'center-left', 'center-right', 'center', 'circle', + 'cjk-ideographic', 'close-quote', 'collapse', 'condensed', 'continuous', + 'crop', 'crosshair', 'cross', 'cursive', 'dashed', 'decimal-leading-zero', + 'decimal', 'default', 'digits', 'disc', 'dotted', 'double', 'e-resize', 'embed', + 'extra-condensed', 'extra-expanded', 'expanded', 'fantasy', 'far-left', + 'far-right', 'faster', 'fast', 'fixed', 'georgian', 'groove', 'hebrew', 'help', + 'hidden', 'hide', 'higher', 'high', 'hiragana-iroha', 'hiragana', 'icon', + 'inherit', 'inline-table', 'inline', 'inset', 'inside', 'invert', 'italic', + 'justify', 'katakana-iroha', 'katakana', 'landscape', 'larger', 'large', + 'left-side', 'leftwards', 'level', 'lighter', 'line-through', 'list-item', + 'loud', 'lower-alpha', 'lower-greek', 'lower-roman', 'lowercase', 'ltr', + 'lower', 'low', 'medium', 'message-box', 'middle', 'mix', 'monospace', + 'n-resize', 'narrower', 'ne-resize', 'no-close-quote', 'no-open-quote', + 'no-repeat', 'none', 'normal', 'nowrap', 'nw-resize', 'oblique', 'once', + 'open-quote', 'outset', 'outside', 'overline', 'pointer', 'portrait', 'px', + 'relative', 'repeat-x', 'repeat-y', 'repeat', 'rgb', 'ridge', 'right-side', + 'rightwards', 's-resize', 'sans-serif', 'scroll', 'se-resize', + 'semi-condensed', 'semi-expanded', 'separate', 'serif', 'show', 'silent', + 'slow', 'slower', 'small-caps', 'small-caption', 'smaller', 'soft', 'solid', + 'spell-out', 'square', 'static', 'status-bar', 'super', 'sw-resize', + 'table-caption', 'table-cell', 'table-column', 'table-column-group', + 'table-footer-group', 'table-header-group', 'table-row', + 'table-row-group', 'text', 'text-bottom', 'text-top', 'thick', 'thin', + 'transparent', 'ultra-condensed', 'ultra-expanded', 'underline', + 'upper-alpha', 'upper-latin', 'upper-roman', 'uppercase', 'url', + 'visible', 'w-resize', 'wait', 'wider', 'x-fast', 'x-high', 'x-large', 'x-loud', + 'x-low', 'x-small', 'x-soft', 'xx-large', 'xx-small', 'yes'), suffix=r'\b'), + Name.Constant), + (words(( + 'indigo', 'gold', 'firebrick', 'indianred', 'darkolivegreen', + 'darkseagreen', 'mediumvioletred', 'mediumorchid', 'chartreuse', + 'mediumslateblue', 'springgreen', 'crimson', 'lightsalmon', 'brown', + 'turquoise', 'olivedrab', 'cyan', 'skyblue', 'darkturquoise', + 'goldenrod', 'darkgreen', 'darkviolet', 'darkgray', 'lightpink', + 'darkmagenta', 'lightgoldenrodyellow', 'lavender', 'yellowgreen', 'thistle', + 'violet', 'orchid', 'ghostwhite', 'honeydew', 'cornflowerblue', + 'darkblue', 'darkkhaki', 'mediumpurple', 'cornsilk', 'bisque', 'slategray', + 'darkcyan', 'khaki', 'wheat', 'deepskyblue', 'darkred', 'steelblue', 'aliceblue', + 'gainsboro', 'mediumturquoise', 'floralwhite', 'coral', 'lightgrey', + 'lightcyan', 'darksalmon', 'beige', 'azure', 'lightsteelblue', 'oldlace', + 'greenyellow', 'royalblue', 'lightseagreen', 'mistyrose', 'sienna', + 'lightcoral', 'orangered', 'navajowhite', 'palegreen', 'burlywood', + 'seashell', 'mediumspringgreen', 'papayawhip', 'blanchedalmond', + 'peru', 'aquamarine', 'darkslategray', 'ivory', 'dodgerblue', + 'lemonchiffon', 'chocolate', 'orange', 'forestgreen', 'slateblue', + 'mintcream', 'antiquewhite', 'darkorange', 'cadetblue', 'moccasin', + 'limegreen', 'saddlebrown', 'darkslateblue', 'lightskyblue', 'deeppink', + 'plum', 'darkgoldenrod', 'sandybrown', 'magenta', 'tan', + 'rosybrown', 'pink', 'lightblue', 'palevioletred', 'mediumseagreen', + 'dimgray', 'powderblue', 'seagreen', 'snow', 'mediumblue', 'midnightblue', + 'paleturquoise', 'palegoldenrod', 'whitesmoke', 'darkorchid', 'salmon', + 'lightslategray', 'lawngreen', 'lightgreen', 'tomato', 'hotpink', + 'lightyellow', 'lavenderblush', 'linen', 'mediumaquamarine', + 'blueviolet', 'peachpuff'), suffix=r'\b'), + Name.Entity), + (words(( + 'black', 'silver', 'gray', 'white', 'maroon', 'red', 'purple', 'fuchsia', 'green', + 'lime', 'olive', 'yellow', 'navy', 'blue', 'teal', 'aqua'), suffix=r'\b'), + Name.Builtin), + (r'\!(important|default)', Name.Exception), + (r'(true|false)', Name.Pseudo), + (r'(and|or|not)', Operator.Word), + (r'/\*', Comment.Multiline, 'inline-comment'), + (r'//[^\n]*', Comment.Single), + (r'\#[a-z0-9]{1,6}', Number.Hex), + (r'(-?\d+)(\%|[a-z]+)?', bygroups(Number.Integer, Keyword.Type)), + (r'(-?\d*\.\d+)(\%|[a-z]+)?', bygroups(Number.Float, Keyword.Type)), + (r'#{', String.Interpol, 'interpolation'), + (r'[~\^\*!&%<>\|+=@:,./?-]+', Operator), + (r'[\[\]()]+', Punctuation), + (r'"', String.Double, 'string-double'), + (r"'", String.Single, 'string-single'), + (r'[a-z_-][\w-]*', Name), + ], + + 'interpolation': [ + (r'\}', String.Interpol, '#pop'), + include('value'), + ], + + 'selector': [ + (r'[ \t]+', Text), + (r'\:', Name.Decorator, 'pseudo-class'), + (r'\.', Name.Class, 'class'), + (r'\#', Name.Namespace, 'id'), + (r'[\w-]+', Name.Tag), + (r'#\{', String.Interpol, 'interpolation'), + (r'&', Keyword), + (r'[~\^\*!&\[\]\(\)<>\|+=@:;,./?-]', Operator), + (r'"', String.Double, 'string-double'), + (r"'", String.Single, 'string-single'), + ], + + 'string-double': [ + (r'(\\.|#(?=[^\n{])|[^\n"#])+', String.Double), + (r'#\{', String.Interpol, 'interpolation'), + (r'"', String.Double, '#pop'), + ], + + 'string-single': [ + (r"(\\.|#(?=[^\n{])|[^\n'#])+", String.Double), + (r'#\{', String.Interpol, 'interpolation'), + (r"'", String.Double, '#pop'), + ], + + 'string-url': [ + (r'(\\#|#(?=[^\n{])|[^\n#)])+', String.Other), + (r'#\{', String.Interpol, 'interpolation'), + (r'\)', String.Other, '#pop'), + ], + + 'pseudo-class': [ + (r'[\w-]+', Name.Decorator), + (r'#\{', String.Interpol, 'interpolation'), + default('#pop'), + ], + + 'class': [ + (r'[\w-]+', Name.Class), + (r'#\{', String.Interpol, 'interpolation'), + default('#pop'), + ], + + 'id': [ + (r'[\w-]+', Name.Namespace), + (r'#\{', String.Interpol, 'interpolation'), + default('#pop'), + ], + + 'for': [ + (r'(from|to|through)', Operator.Word), + include('value'), + ], +} + + +def _indentation(lexer, match, ctx): + indentation = match.group(0) + yield match.start(), Text, indentation + ctx.last_indentation = indentation + ctx.pos = match.end() + + if hasattr(ctx, 'block_state') and ctx.block_state and \ + indentation.startswith(ctx.block_indentation) and \ + indentation != ctx.block_indentation: + ctx.stack.append(ctx.block_state) + else: + ctx.block_state = None + ctx.block_indentation = None + ctx.stack.append('content') + + +def _starts_block(token, state): + def callback(lexer, match, ctx): + yield match.start(), token, match.group(0) + + if hasattr(ctx, 'last_indentation'): + ctx.block_indentation = ctx.last_indentation + else: + ctx.block_indentation = '' + + ctx.block_state = state + ctx.pos = match.end() + + return callback + + +class SassLexer(ExtendedRegexLexer): + """ + For Sass stylesheets. + + .. versionadded:: 1.3 + """ + + name = 'Sass' + aliases = ['sass'] + filenames = ['*.sass'] + mimetypes = ['text/x-sass'] + + flags = re.IGNORECASE + tokens = { + 'root': [ + (r'[ \t]*\n', Text), + (r'[ \t]*', _indentation), + ], + + 'content': [ + (r'//[^\n]*', _starts_block(Comment.Single, 'single-comment'), + 'root'), + (r'/\*[^\n]*', _starts_block(Comment.Multiline, 'multi-comment'), + 'root'), + (r'@import', Keyword, 'import'), + (r'@for', Keyword, 'for'), + (r'@(debug|warn|if|while)', Keyword, 'value'), + (r'(@mixin)( [\w-]+)', bygroups(Keyword, Name.Function), 'value'), + (r'(@include)( [\w-]+)', bygroups(Keyword, Name.Decorator), 'value'), + (r'@extend', Keyword, 'selector'), + (r'@[\w-]+', Keyword, 'selector'), + (r'=[\w-]+', Name.Function, 'value'), + (r'\+[\w-]+', Name.Decorator, 'value'), + (r'([!$][\w-]\w*)([ \t]*(?:(?:\|\|)?=|:))', + bygroups(Name.Variable, Operator), 'value'), + (r':', Name.Attribute, 'old-style-attr'), + (r'(?=.+?[=:]([^a-z]|$))', Name.Attribute, 'new-style-attr'), + default('selector'), + ], + + 'single-comment': [ + (r'.+', Comment.Single), + (r'\n', Text, 'root'), + ], + + 'multi-comment': [ + (r'.+', Comment.Multiline), + (r'\n', Text, 'root'), + ], + + 'import': [ + (r'[ \t]+', Text), + (r'\S+', String), + (r'\n', Text, 'root'), + ], + + 'old-style-attr': [ + (r'[^\s:="\[]+', Name.Attribute), + (r'#{', String.Interpol, 'interpolation'), + (r'[ \t]*=', Operator, 'value'), + default('value'), + ], + + 'new-style-attr': [ + (r'[^\s:="\[]+', Name.Attribute), + (r'#{', String.Interpol, 'interpolation'), + (r'[ \t]*[=:]', Operator, 'value'), + ], + + 'inline-comment': [ + (r"(\\#|#(?=[^\n{])|\*(?=[^\n/])|[^\n#*])+", Comment.Multiline), + (r'#\{', String.Interpol, 'interpolation'), + (r"\*/", Comment, '#pop'), + ], + } + for group, common in iteritems(common_sass_tokens): + tokens[group] = copy.copy(common) + tokens['value'].append((r'\n', Text, 'root')) + tokens['selector'].append((r'\n', Text, 'root')) + + +class ScssLexer(RegexLexer): + """ + For SCSS stylesheets. + """ + + name = 'SCSS' + aliases = ['scss'] + filenames = ['*.scss'] + mimetypes = ['text/x-scss'] + + flags = re.IGNORECASE | re.DOTALL + tokens = { + 'root': [ + (r'\s+', Text), + (r'//.*?\n', Comment.Single), + (r'/\*.*?\*/', Comment.Multiline), + (r'@import', Keyword, 'value'), + (r'@for', Keyword, 'for'), + (r'@(debug|warn|if|while)', Keyword, 'value'), + (r'(@mixin)( [\w-]+)', bygroups(Keyword, Name.Function), 'value'), + (r'(@include)( [\w-]+)', bygroups(Keyword, Name.Decorator), 'value'), + (r'@extend', Keyword, 'selector'), + (r'@[\w-]+', Keyword, 'selector'), + (r'(\$[\w-]*\w)([ \t]*:)', bygroups(Name.Variable, Operator), 'value'), + (r'(?=[^;{}][;}])', Name.Attribute, 'attr'), + (r'(?=[^;{}:]+:[^a-z])', Name.Attribute, 'attr'), + default('selector'), + ], + + 'attr': [ + (r'[^\s:="\[]+', Name.Attribute), + (r'#{', String.Interpol, 'interpolation'), + (r'[ \t]*:', Operator, 'value'), + ], + + 'inline-comment': [ + (r"(\\#|#(?=[^{])|\*(?=[^/])|[^#*])+", Comment.Multiline), + (r'#\{', String.Interpol, 'interpolation'), + (r"\*/", Comment, '#pop'), + ], + } + for group, common in iteritems(common_sass_tokens): + tokens[group] = copy.copy(common) + tokens['value'].extend([(r'\n', Text), (r'[;{}]', Punctuation, 'root')]) + tokens['selector'].extend([(r'\n', Text), (r'[;{}]', Punctuation, 'root')]) diff --git a/pygments/lexers/data.py b/pygments/lexers/data.py index d1d33a1e..6b7cc107 100644 --- a/pygments/lexers/data.py +++ b/pygments/lexers/data.py @@ -9,11 +9,14 @@ :license: BSD, see LICENSE for details. """ -from pygments.lexer import ExtendedRegexLexer, LexerContext, include, bygroups +import re + +from pygments.lexer import RegexLexer, ExtendedRegexLexer, LexerContext, \ + include, bygroups from pygments.token import Text, Comment, Keyword, Name, String, Number, \ Punctuation, Literal -__all__ = ['YamlLexer'] +__all__ = ['YamlLexer', 'JsonLexer'] class YamlLexerContext(LexerContext): @@ -425,3 +428,82 @@ class YamlLexer(ExtendedRegexLexer): if context is None: context = YamlLexerContext(text, 0) return super(YamlLexer, self).get_tokens_unprocessed(text, context) + + +class JsonLexer(RegexLexer): + """ + For JSON data structures. + + .. versionadded:: 1.5 + """ + + name = 'JSON' + aliases = ['json'] + filenames = ['*.json'] + mimetypes = ['application/json'] + + flags = re.DOTALL + + # integer part of a number + int_part = r'-?(0|[1-9]\d*)' + + # fractional part of a number + frac_part = r'\.\d+' + + # exponential part of a number + exp_part = r'[eE](\+|-)?\d+' + + tokens = { + 'whitespace': [ + (r'\s+', Text), + ], + + # represents a simple terminal value + 'simplevalue': [ + (r'(true|false|null)\b', Keyword.Constant), + (('%(int_part)s(%(frac_part)s%(exp_part)s|' + '%(exp_part)s|%(frac_part)s)') % vars(), + Number.Float), + (int_part, Number.Integer), + (r'"(\\\\|\\"|[^"])*"', String.Double), + ], + + + # the right hand side of an object, after the attribute name + 'objectattribute': [ + include('value'), + (r':', Punctuation), + # comma terminates the attribute but expects more + (r',', Punctuation, '#pop'), + # a closing bracket terminates the entire object, so pop twice + (r'}', Punctuation, ('#pop', '#pop')), + ], + + # a json object - { attr, attr, ... } + 'objectvalue': [ + include('whitespace'), + (r'"(\\\\|\\"|[^"])*"', Name.Tag, 'objectattribute'), + (r'}', Punctuation, '#pop'), + ], + + # json array - [ value, value, ... } + 'arrayvalue': [ + include('whitespace'), + include('value'), + (r',', Punctuation), + (r']', Punctuation, '#pop'), + ], + + # a json value - either a simple value or a complex value (object or array) + 'value': [ + include('whitespace'), + include('simplevalue'), + (r'{', Punctuation, 'objectvalue'), + (r'\[', Punctuation, 'arrayvalue'), + ], + + # the root of a json document whould be a value + 'root': [ + include('value'), + ], + } diff --git a/pygments/lexers/dotnet.py b/pygments/lexers/dotnet.py index b6313197..2ccff167 100644 --- a/pygments/lexers/dotnet.py +++ b/pygments/lexers/dotnet.py @@ -17,7 +17,7 @@ from pygments.token import Punctuation, \ from pygments.util import get_choice_opt, iteritems from pygments import unistring as uni -from pygments.lexers.web import XmlLexer +from pygments.lexers.html import XmlLexer __all__ = ['CSharpLexer', 'NemerleLexer', 'BooLexer', 'VbNetLexer', 'CSharpAspxLexer', 'VbNetAspxLexer', 'FSharpLexer'] diff --git a/pygments/lexers/dsls.py b/pygments/lexers/dsls.py index db3badea..bfbc860e 100644 --- a/pygments/lexers/dsls.py +++ b/pygments/lexers/dsls.py @@ -13,10 +13,10 @@ import re from pygments.lexer import RegexLexer, bygroups, words, include from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ - Number, Punctuation, Literal, Generic, Whitespace + Number, Punctuation, Literal __all__ = ['ProtoBufLexer', 'BroLexer', 'PuppetLexer', 'RslLexer', - 'MscgenLexer', 'VGLLexer', 'AlloyLexer', 'PanLexer', 'HxmlLexer'] + 'MscgenLexer', 'VGLLexer', 'AlloyLexer', 'PanLexer'] class ProtoBufLexer(RegexLexer): @@ -504,44 +504,3 @@ class PanLexer(RegexLexer): include('root'), ], } - - -class HxmlLexer(RegexLexer): - """ - Lexer for `haXe build <http://haxe.org/doc/compiler>`_ files. - - .. versionadded:: 1.6 - """ - name = 'Hxml' - aliases = ['haxeml', 'hxml'] - filenames = ['*.hxml'] - - tokens = { - 'root': [ - # Seperator - (r'(--)(next)', bygroups(Punctuation, Generic.Heading)), - # Compiler switches with one dash - (r'(-)(prompt|debug|v)', bygroups(Punctuation, Keyword.Keyword)), - # Compilerswitches with two dashes - (r'(--)(neko-source|flash-strict|flash-use-stage|no-opt|no-traces|' - r'no-inline|times|no-output)', bygroups(Punctuation, Keyword)), - # Targets and other options that take an argument - (r'(-)(cpp|js|neko|x|as3|swf9?|swf-lib|php|xml|main|lib|D|resource|' - r'cp|cmd)( +)(.+)', - bygroups(Punctuation, Keyword, Whitespace, String)), - # Options that take only numerical arguments - (r'(-)(swf-version)( +)(\d+)', - bygroups(Punctuation, Keyword, Number.Integer)), - # An Option that defines the size, the fps and the background - # color of an flash movie - (r'(-)(swf-header)( +)(\d+)(:)(\d+)(:)(\d+)(:)([A-Fa-f0-9]{6})', - bygroups(Punctuation, Keyword, Whitespace, Number.Integer, - Punctuation, Number.Integer, Punctuation, Number.Integer, - Punctuation, Number.Hex)), - # options with two dashes that takes arguments - (r'(--)(js-namespace|php-front|php-lib|remap|gen-hx-classes)( +)' - r'(.+)', bygroups(Punctuation, Keyword, Whitespace, String)), - # Single line comment, multiline ones are not allowed. - (r'#.*', Comment.Single) - ] - } diff --git a/pygments/lexers/haxe.py b/pygments/lexers/haxe.py new file mode 100644 index 00000000..a0758ac6 --- /dev/null +++ b/pygments/lexers/haxe.py @@ -0,0 +1,934 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.haxe + ~~~~~~~~~~~~~~~~~~~~ + + Lexers for Haxe and related stuff. + + :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import ExtendedRegexLexer, RegexLexer, include, bygroups, \ + default +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Punctuation, Generic, Whitespace + +__all__ = ['HaxeLexer', 'HxmlLexer'] + + +class HaxeLexer(ExtendedRegexLexer): + """ + For Haxe source code (http://haxe.org/). + + .. versionadded:: 1.3 + """ + + name = 'Haxe' + aliases = ['hx', 'haxe', 'hxsl'] + filenames = ['*.hx', '*.hxsl'] + mimetypes = ['text/haxe', 'text/x-haxe', 'text/x-hx'] + + # keywords extracted from lexer.mll in the haxe compiler source + keyword = (r'(?:function|class|static|var|if|else|while|do|for|' + r'break|return|continue|extends|implements|import|' + r'switch|case|default|public|private|try|untyped|' + r'catch|new|this|throw|extern|enum|in|interface|' + r'cast|override|dynamic|typedef|package|' + r'inline|using|null|true|false|abstract)\b') + + # idtype in lexer.mll + typeid = r'_*[A-Z]\w*' + + # combined ident and dollar and idtype + ident = r'(?:_*[a-z]\w*|_+[0-9]\w*|' + typeid + '|_+|\$\w+)' + + binop = (r'(?:%=|&=|\|=|\^=|\+=|\-=|\*=|/=|<<=|>\s*>\s*=|>\s*>\s*>\s*=|==|' + r'!=|<=|>\s*=|&&|\|\||<<|>>>|>\s*>|\.\.\.|<|>|%|&|\||\^|\+|\*|' + r'/|\-|=>|=)') + + # ident except keywords + ident_no_keyword = r'(?!' + keyword + ')' + ident + + flags = re.DOTALL | re.MULTILINE + + preproc_stack = [] + + def preproc_callback(self, match, ctx): + proc = match.group(2) + + if proc == 'if': + # store the current stack + self.preproc_stack.append(ctx.stack[:]) + elif proc in ['else', 'elseif']: + # restore the stack back to right before #if + if self.preproc_stack: + ctx.stack = self.preproc_stack[-1][:] + elif proc == 'end': + # remove the saved stack of previous #if + if self.preproc_stack: + self.preproc_stack.pop() + + # #if and #elseif should follow by an expr + if proc in ['if', 'elseif']: + ctx.stack.append('preproc-expr') + + # #error can be optionally follow by the error msg + if proc in ['error']: + ctx.stack.append('preproc-error') + + yield match.start(), Comment.Preproc, '#' + proc + ctx.pos = match.end() + + tokens = { + 'root': [ + include('spaces'), + include('meta'), + (r'(?:package)\b', Keyword.Namespace, ('semicolon', 'package')), + (r'(?:import)\b', Keyword.Namespace, ('semicolon', 'import')), + (r'(?:using)\b', Keyword.Namespace, ('semicolon', 'using')), + (r'(?:extern|private)\b', Keyword.Declaration), + (r'(?:abstract)\b', Keyword.Declaration, 'abstract'), + (r'(?:class|interface)\b', Keyword.Declaration, 'class'), + (r'(?:enum)\b', Keyword.Declaration, 'enum'), + (r'(?:typedef)\b', Keyword.Declaration, 'typedef'), + + # top-level expression + # although it is not supported in haxe, but it is common to write + # expression in web pages the positive lookahead here is to prevent + # an infinite loop at the EOF + (r'(?=.)', Text, 'expr-statement'), + ], + + # space/tab/comment/preproc + 'spaces': [ + (r'\s+', Text), + (r'//[^\n\r]*', Comment.Single), + (r'/\*.*?\*/', Comment.Multiline), + (r'(#)(if|elseif|else|end|error)\b', preproc_callback), + ], + + 'string-single-interpol': [ + (r'\$\{', String.Interpol, ('string-interpol-close', 'expr')), + (r'\$\$', String.Escape), + (r'\$(?=' + ident + ')', String.Interpol, 'ident'), + include('string-single'), + ], + + 'string-single': [ + (r"'", String.Single, '#pop'), + (r'\\.', String.Escape), + (r'.', String.Single), + ], + + 'string-double': [ + (r'"', String.Double, '#pop'), + (r'\\.', String.Escape), + (r'.', String.Double), + ], + + 'string-interpol-close': [ + (r'\$'+ident, String.Interpol), + (r'\}', String.Interpol, '#pop'), + ], + + 'package': [ + include('spaces'), + (ident, Name.Namespace), + (r'\.', Punctuation, 'import-ident'), + default('#pop'), + ], + + 'import': [ + include('spaces'), + (ident, Name.Namespace), + (r'\*', Keyword), # wildcard import + (r'\.', Punctuation, 'import-ident'), + (r'in', Keyword.Namespace, 'ident'), + default('#pop'), + ], + + 'import-ident': [ + include('spaces'), + (r'\*', Keyword, '#pop'), # wildcard import + (ident, Name.Namespace, '#pop'), + ], + + 'using': [ + include('spaces'), + (ident, Name.Namespace), + (r'\.', Punctuation, 'import-ident'), + default('#pop'), + ], + + 'preproc-error': [ + (r'\s+', Comment.Preproc), + (r"'", String.Single, ('#pop', 'string-single')), + (r'"', String.Double, ('#pop', 'string-double')), + default('#pop'), + ], + + 'preproc-expr': [ + (r'\s+', Comment.Preproc), + (r'\!', Comment.Preproc), + (r'\(', Comment.Preproc, ('#pop', 'preproc-parenthesis')), + + (ident, Comment.Preproc, '#pop'), + + # Float + (r'\.[0-9]+', Number.Float), + (r'[0-9]+[eE][\+\-]?[0-9]+', Number.Float), + (r'[0-9]+\.[0-9]*[eE][\+\-]?[0-9]+', Number.Float), + (r'[0-9]+\.[0-9]+', Number.Float), + (r'[0-9]+\.(?!' + ident + '|\.\.)', Number.Float), + + # Int + (r'0x[0-9a-fA-F]+', Number.Hex), + (r'[0-9]+', Number.Integer), + + # String + (r"'", String.Single, ('#pop', 'string-single')), + (r'"', String.Double, ('#pop', 'string-double')), + ], + + 'preproc-parenthesis': [ + (r'\s+', Comment.Preproc), + (r'\)', Comment.Preproc, '#pop'), + ('', Text, 'preproc-expr-in-parenthesis'), + ], + + 'preproc-expr-chain': [ + (r'\s+', Comment.Preproc), + (binop, Comment.Preproc, ('#pop', 'preproc-expr-in-parenthesis')), + default('#pop'), + ], + + # same as 'preproc-expr' but able to chain 'preproc-expr-chain' + 'preproc-expr-in-parenthesis': [ + (r'\s+', Comment.Preproc), + (r'\!', Comment.Preproc), + (r'\(', Comment.Preproc, + ('#pop', 'preproc-expr-chain', 'preproc-parenthesis')), + + (ident, Comment.Preproc, ('#pop', 'preproc-expr-chain')), + + # Float + (r'\.[0-9]+', Number.Float, ('#pop', 'preproc-expr-chain')), + (r'[0-9]+[eE][\+\-]?[0-9]+', Number.Float, ('#pop', 'preproc-expr-chain')), + (r'[0-9]+\.[0-9]*[eE][\+\-]?[0-9]+', Number.Float, ('#pop', 'preproc-expr-chain')), + (r'[0-9]+\.[0-9]+', Number.Float, ('#pop', 'preproc-expr-chain')), + (r'[0-9]+\.(?!' + ident + '|\.\.)', Number.Float, ('#pop', 'preproc-expr-chain')), + + # Int + (r'0x[0-9a-fA-F]+', Number.Hex, ('#pop', 'preproc-expr-chain')), + (r'[0-9]+', Number.Integer, ('#pop', 'preproc-expr-chain')), + + # String + (r"'", String.Single, + ('#pop', 'preproc-expr-chain', 'string-single')), + (r'"', String.Double, + ('#pop', 'preproc-expr-chain', 'string-double')), + ], + + 'abstract': [ + include('spaces'), + default(('#pop', 'abstract-body', 'abstract-relation', + 'abstract-opaque', 'type-param-constraint', 'type-name')), + ], + + 'abstract-body': [ + include('spaces'), + (r'\{', Punctuation, ('#pop', 'class-body')), + ], + + 'abstract-opaque': [ + include('spaces'), + (r'\(', Punctuation, ('#pop', 'parenthesis-close', 'type')), + default('#pop'), + ], + + 'abstract-relation': [ + include('spaces'), + (r'(?:to|from)', Keyword.Declaration, 'type'), + (r',', Punctuation), + default('#pop'), + ], + + 'meta': [ + include('spaces'), + (r'@', Name.Decorator, ('meta-body', 'meta-ident', 'meta-colon')), + ], + + # optional colon + 'meta-colon': [ + include('spaces'), + (r':', Name.Decorator, '#pop'), + default('#pop'), + ], + + # same as 'ident' but set token as Name.Decorator instead of Name + 'meta-ident': [ + include('spaces'), + (ident, Name.Decorator, '#pop'), + ], + + 'meta-body': [ + include('spaces'), + (r'\(', Name.Decorator, ('#pop', 'meta-call')), + default('#pop'), + ], + + 'meta-call': [ + include('spaces'), + (r'\)', Name.Decorator, '#pop'), + default(('#pop', 'meta-call-sep', 'expr')), + ], + + 'meta-call-sep': [ + include('spaces'), + (r'\)', Name.Decorator, '#pop'), + (r',', Punctuation, ('#pop', 'meta-call')), + ], + + 'typedef': [ + include('spaces'), + default(('#pop', 'typedef-body', 'type-param-constraint', + 'type-name')), + ], + + 'typedef-body': [ + include('spaces'), + (r'=', Operator, ('#pop', 'optional-semicolon', 'type')), + ], + + 'enum': [ + include('spaces'), + default(('#pop', 'enum-body', 'bracket-open', + 'type-param-constraint', 'type-name')), + ], + + 'enum-body': [ + include('spaces'), + include('meta'), + (r'\}', Punctuation, '#pop'), + (ident_no_keyword, Name, ('enum-member', 'type-param-constraint')), + ], + + 'enum-member': [ + include('spaces'), + (r'\(', Punctuation, + ('#pop', 'semicolon', 'flag', 'function-param')), + default(('#pop', 'semicolon', 'flag')), + ], + + 'class': [ + include('spaces'), + default(('#pop', 'class-body', 'bracket-open', 'extends', + 'type-param-constraint', 'type-name')), + ], + + 'extends': [ + include('spaces'), + (r'(?:extends|implements)\b', Keyword.Declaration, 'type'), + (r',', Punctuation), # the comma is made optional here, since haxe2 + # requires the comma but haxe3 does not allow it + default('#pop'), + ], + + 'bracket-open': [ + include('spaces'), + (r'\{', Punctuation, '#pop'), + ], + + 'bracket-close': [ + include('spaces'), + (r'\}', Punctuation, '#pop'), + ], + + 'class-body': [ + include('spaces'), + include('meta'), + (r'\}', Punctuation, '#pop'), + (r'(?:static|public|private|override|dynamic|inline|macro)\b', + Keyword.Declaration), + default('class-member'), + ], + + 'class-member': [ + include('spaces'), + (r'(var)\b', Keyword.Declaration, + ('#pop', 'optional-semicolon', 'var')), + (r'(function)\b', Keyword.Declaration, + ('#pop', 'optional-semicolon', 'class-method')), + ], + + # local function, anonymous or not + 'function-local': [ + include('spaces'), + (r'(' + ident_no_keyword + ')?', Name.Function, + ('#pop', 'optional-expr', 'flag', 'function-param', + 'parenthesis-open', 'type-param-constraint')), + ], + + 'optional-expr': [ + include('spaces'), + include('expr'), + default('#pop'), + ], + + 'class-method': [ + include('spaces'), + (ident, Name.Function, ('#pop', 'optional-expr', 'flag', + 'function-param', 'parenthesis-open', + 'type-param-constraint')), + ], + + # function arguments + 'function-param': [ + include('spaces'), + (r'\)', Punctuation, '#pop'), + (r'\?', Punctuation), + (ident_no_keyword, Name, + ('#pop', 'function-param-sep', 'assign', 'flag')), + ], + + 'function-param-sep': [ + include('spaces'), + (r'\)', Punctuation, '#pop'), + (r',', Punctuation, ('#pop', 'function-param')), + ], + + 'prop-get-set': [ + include('spaces'), + (r'\(', Punctuation, ('#pop', 'parenthesis-close', + 'prop-get-set-opt', 'comma', 'prop-get-set-opt')), + default('#pop'), + ], + + 'prop-get-set-opt': [ + include('spaces'), + (r'(?:default|null|never|dynamic|get|set)\b', Keyword, '#pop'), + (ident_no_keyword, Text, '#pop'), # custom getter/setter + ], + + 'expr-statement': [ + include('spaces'), + # makes semicolon optional here, just to avoid checking the last + # one is bracket or not. + default(('#pop', 'optional-semicolon', 'expr')), + ], + + 'expr': [ + include('spaces'), + (r'@', Name.Decorator, ('#pop', 'optional-expr', 'meta-body', + 'meta-ident', 'meta-colon')), + (r'(?:\+\+|\-\-|~(?!/)|!|\-)', Operator), + (r'\(', Punctuation, ('#pop', 'expr-chain', 'parenthesis')), + (r'(?:static|public|private|override|dynamic|inline)\b', + Keyword.Declaration), + (r'(?:function)\b', Keyword.Declaration, ('#pop', 'expr-chain', + 'function-local')), + (r'\{', Punctuation, ('#pop', 'expr-chain', 'bracket')), + (r'(?:true|false|null)\b', Keyword.Constant, ('#pop', 'expr-chain')), + (r'(?:this)\b', Keyword, ('#pop', 'expr-chain')), + (r'(?:cast)\b', Keyword, ('#pop', 'expr-chain', 'cast')), + (r'(?:try)\b', Keyword, ('#pop', 'catch', 'expr')), + (r'(?:var)\b', Keyword.Declaration, ('#pop', 'var')), + (r'(?:new)\b', Keyword, ('#pop', 'expr-chain', 'new')), + (r'(?:switch)\b', Keyword, ('#pop', 'switch')), + (r'(?:if)\b', Keyword, ('#pop', 'if')), + (r'(?:do)\b', Keyword, ('#pop', 'do')), + (r'(?:while)\b', Keyword, ('#pop', 'while')), + (r'(?:for)\b', Keyword, ('#pop', 'for')), + (r'(?:untyped|throw)\b', Keyword), + (r'(?:return)\b', Keyword, ('#pop', 'optional-expr')), + (r'(?:macro)\b', Keyword, ('#pop', 'macro')), + (r'(?:continue|break)\b', Keyword, '#pop'), + (r'(?:\$\s*[a-z]\b|\$(?!'+ident+'))', Name, ('#pop', 'dollar')), + (ident_no_keyword, Name, ('#pop', 'expr-chain')), + + # Float + (r'\.[0-9]+', Number.Float, ('#pop', 'expr-chain')), + (r'[0-9]+[eE][\+\-]?[0-9]+', Number.Float, ('#pop', 'expr-chain')), + (r'[0-9]+\.[0-9]*[eE][\+\-]?[0-9]+', Number.Float, ('#pop', 'expr-chain')), + (r'[0-9]+\.[0-9]+', Number.Float, ('#pop', 'expr-chain')), + (r'[0-9]+\.(?!' + ident + '|\.\.)', Number.Float, ('#pop', 'expr-chain')), + + # Int + (r'0x[0-9a-fA-F]+', Number.Hex, ('#pop', 'expr-chain')), + (r'[0-9]+', Number.Integer, ('#pop', 'expr-chain')), + + # String + (r"'", String.Single, ('#pop', 'expr-chain', 'string-single-interpol')), + (r'"', String.Double, ('#pop', 'expr-chain', 'string-double')), + + # EReg + (r'~/(\\\\|\\/|[^/\n])*/[gimsu]*', String.Regex, ('#pop', 'expr-chain')), + + # Array + (r'\[', Punctuation, ('#pop', 'expr-chain', 'array-decl')), + ], + + 'expr-chain': [ + include('spaces'), + (r'(?:\+\+|\-\-)', Operator), + (binop, Operator, ('#pop', 'expr')), + (r'(?:in)\b', Keyword, ('#pop', 'expr')), + (r'\?', Operator, ('#pop', 'expr', 'ternary', 'expr')), + (r'(\.)(' + ident_no_keyword + ')', bygroups(Punctuation, Name)), + (r'\[', Punctuation, 'array-access'), + (r'\(', Punctuation, 'call'), + default('#pop'), + ], + + # macro reification + 'macro': [ + include('spaces'), + include('meta'), + (r':', Punctuation, ('#pop', 'type')), + + (r'(?:extern|private)\b', Keyword.Declaration), + (r'(?:abstract)\b', Keyword.Declaration, ('#pop', 'optional-semicolon', 'abstract')), + (r'(?:class|interface)\b', Keyword.Declaration, ('#pop', 'optional-semicolon', 'macro-class')), + (r'(?:enum)\b', Keyword.Declaration, ('#pop', 'optional-semicolon', 'enum')), + (r'(?:typedef)\b', Keyword.Declaration, ('#pop', 'optional-semicolon', 'typedef')), + + default(('#pop', 'expr')), + ], + + 'macro-class': [ + (r'\{', Punctuation, ('#pop', 'class-body')), + include('class') + ], + + # cast can be written as "cast expr" or "cast(expr, type)" + 'cast': [ + include('spaces'), + (r'\(', Punctuation, ('#pop', 'parenthesis-close', + 'cast-type', 'expr')), + default(('#pop', 'expr')), + ], + + # optionally give a type as the 2nd argument of cast() + 'cast-type': [ + include('spaces'), + (r',', Punctuation, ('#pop', 'type')), + default('#pop'), + ], + + 'catch': [ + include('spaces'), + (r'(?:catch)\b', Keyword, ('expr', 'function-param', + 'parenthesis-open')), + default('#pop'), + ], + + # do-while loop + 'do': [ + include('spaces'), + default(('#pop', 'do-while', 'expr')), + ], + + # the while after do + 'do-while': [ + include('spaces'), + (r'(?:while)\b', Keyword, ('#pop', 'parenthesis', + 'parenthesis-open')), + ], + + 'while': [ + include('spaces'), + (r'\(', Punctuation, ('#pop', 'expr', 'parenthesis')), + ], + + 'for': [ + include('spaces'), + (r'\(', Punctuation, ('#pop', 'expr', 'parenthesis')), + ], + + 'if': [ + include('spaces'), + (r'\(', Punctuation, ('#pop', 'else', 'optional-semicolon', 'expr', + 'parenthesis')), + ], + + 'else': [ + include('spaces'), + (r'(?:else)\b', Keyword, ('#pop', 'expr')), + default('#pop'), + ], + + 'switch': [ + include('spaces'), + default(('#pop', 'switch-body', 'bracket-open', 'expr')), + ], + + 'switch-body': [ + include('spaces'), + (r'(?:case|default)\b', Keyword, ('case-block', 'case')), + (r'\}', Punctuation, '#pop'), + ], + + 'case': [ + include('spaces'), + (r':', Punctuation, '#pop'), + default(('#pop', 'case-sep', 'case-guard', 'expr')), + ], + + 'case-sep': [ + include('spaces'), + (r':', Punctuation, '#pop'), + (r',', Punctuation, ('#pop', 'case')), + ], + + 'case-guard': [ + include('spaces'), + (r'(?:if)\b', Keyword, ('#pop', 'parenthesis', 'parenthesis-open')), + default('#pop'), + ], + + # optional multiple expr under a case + 'case-block': [ + include('spaces'), + (r'(?!(?:case|default)\b|\})', Keyword, 'expr-statement'), + default('#pop'), + ], + + 'new': [ + include('spaces'), + default(('#pop', 'call', 'parenthesis-open', 'type')), + ], + + 'array-decl': [ + include('spaces'), + (r'\]', Punctuation, '#pop'), + default(('#pop', 'array-decl-sep', 'expr')), + ], + + 'array-decl-sep': [ + include('spaces'), + (r'\]', Punctuation, '#pop'), + (r',', Punctuation, ('#pop', 'array-decl')), + ], + + 'array-access': [ + include('spaces'), + default(('#pop', 'array-access-close', 'expr')), + ], + + 'array-access-close': [ + include('spaces'), + (r'\]', Punctuation, '#pop'), + ], + + 'comma': [ + include('spaces'), + (r',', Punctuation, '#pop'), + ], + + 'colon': [ + include('spaces'), + (r':', Punctuation, '#pop'), + ], + + 'semicolon': [ + include('spaces'), + (r';', Punctuation, '#pop'), + ], + + 'optional-semicolon': [ + include('spaces'), + (r';', Punctuation, '#pop'), + default('#pop'), + ], + + # identity that CAN be a Haxe keyword + 'ident': [ + include('spaces'), + (ident, Name, '#pop'), + ], + + 'dollar': [ + include('spaces'), + (r'\{', Punctuation, ('#pop', 'expr-chain', 'bracket-close', 'expr')), + default(('#pop', 'expr-chain')), + ], + + 'type-name': [ + include('spaces'), + (typeid, Name, '#pop'), + ], + + 'type-full-name': [ + include('spaces'), + (r'\.', Punctuation, 'ident'), + default('#pop'), + ], + + 'type': [ + include('spaces'), + (r'\?', Punctuation), + (ident, Name, ('#pop', 'type-check', 'type-full-name')), + (r'\{', Punctuation, ('#pop', 'type-check', 'type-struct')), + (r'\(', Punctuation, ('#pop', 'type-check', 'type-parenthesis')), + ], + + 'type-parenthesis': [ + include('spaces'), + default(('#pop', 'parenthesis-close', 'type')), + ], + + 'type-check': [ + include('spaces'), + (r'->', Punctuation, ('#pop', 'type')), + (r'<(?!=)', Punctuation, 'type-param'), + default('#pop'), + ], + + 'type-struct': [ + include('spaces'), + (r'\}', Punctuation, '#pop'), + (r'\?', Punctuation), + (r'>', Punctuation, ('comma', 'type')), + (ident_no_keyword, Name, ('#pop', 'type-struct-sep', 'type', 'colon')), + include('class-body'), + ], + + 'type-struct-sep': [ + include('spaces'), + (r'\}', Punctuation, '#pop'), + (r',', Punctuation, ('#pop', 'type-struct')), + ], + + # type-param can be a normal type or a constant literal... + 'type-param-type': [ + # Float + (r'\.[0-9]+', Number.Float, '#pop'), + (r'[0-9]+[eE][\+\-]?[0-9]+', Number.Float, '#pop'), + (r'[0-9]+\.[0-9]*[eE][\+\-]?[0-9]+', Number.Float, '#pop'), + (r'[0-9]+\.[0-9]+', Number.Float, '#pop'), + (r'[0-9]+\.(?!' + ident + '|\.\.)', Number.Float, '#pop'), + + # Int + (r'0x[0-9a-fA-F]+', Number.Hex, '#pop'), + (r'[0-9]+', Number.Integer, '#pop'), + + # String + (r"'", String.Single, ('#pop', 'string-single')), + (r'"', String.Double, ('#pop', 'string-double')), + + # EReg + (r'~/(\\\\|\\/|[^/\n])*/[gim]*', String.Regex, '#pop'), + + # Array + (r'\[', Operator, ('#pop', 'array-decl')), + + include('type'), + ], + + # type-param part of a type + # ie. the <A,B> path in Map<A,B> + 'type-param': [ + include('spaces'), + default(('#pop', 'type-param-sep', 'type-param-type')), + ], + + 'type-param-sep': [ + include('spaces'), + (r'>', Punctuation, '#pop'), + (r',', Punctuation, ('#pop', 'type-param')), + ], + + # optional type-param that may include constraint + # ie. <T:Constraint, T2:(ConstraintA,ConstraintB)> + 'type-param-constraint': [ + include('spaces'), + (r'<(?!=)', Punctuation, ('#pop', 'type-param-constraint-sep', + 'type-param-constraint-flag', 'type-name')), + default('#pop'), + ], + + 'type-param-constraint-sep': [ + include('spaces'), + (r'>', Punctuation, '#pop'), + (r',', Punctuation, ('#pop', 'type-param-constraint-sep', + 'type-param-constraint-flag', 'type-name')), + ], + + # the optional constraint inside type-param + 'type-param-constraint-flag': [ + include('spaces'), + (r':', Punctuation, ('#pop', 'type-param-constraint-flag-type')), + default('#pop'), + ], + + 'type-param-constraint-flag-type': [ + include('spaces'), + (r'\(', Punctuation, ('#pop', 'type-param-constraint-flag-type-sep', + 'type')), + default(('#pop', 'type')), + ], + + 'type-param-constraint-flag-type-sep': [ + include('spaces'), + (r'\)', Punctuation, '#pop'), + (r',', Punctuation, 'type'), + ], + + # a parenthesis expr that contain exactly one expr + 'parenthesis': [ + include('spaces'), + default(('#pop', 'parenthesis-close', 'flag', 'expr')), + ], + + 'parenthesis-open': [ + include('spaces'), + (r'\(', Punctuation, '#pop'), + ], + + 'parenthesis-close': [ + include('spaces'), + (r'\)', Punctuation, '#pop'), + ], + + 'var': [ + include('spaces'), + (ident_no_keyword, Text, ('#pop', 'var-sep', 'assign', 'flag', 'prop-get-set')), + ], + + # optional more var decl. + 'var-sep': [ + include('spaces'), + (r',', Punctuation, ('#pop', 'var')), + default('#pop'), + ], + + # optional assignment + 'assign': [ + include('spaces'), + (r'=', Operator, ('#pop', 'expr')), + default('#pop'), + ], + + # optional type flag + 'flag': [ + include('spaces'), + (r':', Punctuation, ('#pop', 'type')), + default('#pop'), + ], + + # colon as part of a ternary operator (?:) + 'ternary': [ + include('spaces'), + (r':', Operator, '#pop'), + ], + + # function call + 'call': [ + include('spaces'), + (r'\)', Punctuation, '#pop'), + default(('#pop', 'call-sep', 'expr')), + ], + + # after a call param + 'call-sep': [ + include('spaces'), + (r'\)', Punctuation, '#pop'), + (r',', Punctuation, ('#pop', 'call')), + ], + + # bracket can be block or object + 'bracket': [ + include('spaces'), + (r'(?!(?:\$\s*[a-z]\b|\$(?!'+ident+')))' + ident_no_keyword, Name, + ('#pop', 'bracket-check')), + (r"'", String.Single, ('#pop', 'bracket-check', 'string-single')), + (r'"', String.Double, ('#pop', 'bracket-check', 'string-double')), + default(('#pop', 'block')), + ], + + 'bracket-check': [ + include('spaces'), + (r':', Punctuation, ('#pop', 'object-sep', 'expr')), # is object + default(('#pop', 'block', 'optional-semicolon', 'expr-chain')), # is block + ], + + # code block + 'block': [ + include('spaces'), + (r'\}', Punctuation, '#pop'), + default('expr-statement'), + ], + + # object in key-value pairs + 'object': [ + include('spaces'), + (r'\}', Punctuation, '#pop'), + default(('#pop', 'object-sep', 'expr', 'colon', 'ident-or-string')) + ], + + # a key of an object + 'ident-or-string': [ + include('spaces'), + (ident_no_keyword, Name, '#pop'), + (r"'", String.Single, ('#pop', 'string-single')), + (r'"', String.Double, ('#pop', 'string-double')), + ], + + # after a key-value pair in object + 'object-sep': [ + include('spaces'), + (r'\}', Punctuation, '#pop'), + (r',', Punctuation, ('#pop', 'object')), + ], + + + + } + + def analyse_text(text): + if re.match(r'\w+\s*:\s*\w', text): + return 0.3 + + +class HxmlLexer(RegexLexer): + """ + Lexer for `haXe build <http://haxe.org/doc/compiler>`_ files. + + .. versionadded:: 1.6 + """ + name = 'Hxml' + aliases = ['haxeml', 'hxml'] + filenames = ['*.hxml'] + + tokens = { + 'root': [ + # Seperator + (r'(--)(next)', bygroups(Punctuation, Generic.Heading)), + # Compiler switches with one dash + (r'(-)(prompt|debug|v)', bygroups(Punctuation, Keyword.Keyword)), + # Compilerswitches with two dashes + (r'(--)(neko-source|flash-strict|flash-use-stage|no-opt|no-traces|' + r'no-inline|times|no-output)', bygroups(Punctuation, Keyword)), + # Targets and other options that take an argument + (r'(-)(cpp|js|neko|x|as3|swf9?|swf-lib|php|xml|main|lib|D|resource|' + r'cp|cmd)( +)(.+)', + bygroups(Punctuation, Keyword, Whitespace, String)), + # Options that take only numerical arguments + (r'(-)(swf-version)( +)(\d+)', + bygroups(Punctuation, Keyword, Number.Integer)), + # An Option that defines the size, the fps and the background + # color of an flash movie + (r'(-)(swf-header)( +)(\d+)(:)(\d+)(:)(\d+)(:)([A-Fa-f0-9]{6})', + bygroups(Punctuation, Keyword, Whitespace, Number.Integer, + Punctuation, Number.Integer, Punctuation, Number.Integer, + Punctuation, Number.Hex)), + # options with two dashes that takes arguments + (r'(--)(js-namespace|php-front|php-lib|remap|gen-hx-classes)( +)' + r'(.+)', bygroups(Punctuation, Keyword, Whitespace, String)), + # Single line comment, multiline ones are not allowed. + (r'#.*', Comment.Single) + ] + } diff --git a/pygments/lexers/html.py b/pygments/lexers/html.py new file mode 100644 index 00000000..34f2dd4f --- /dev/null +++ b/pygments/lexers/html.py @@ -0,0 +1,589 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.html + ~~~~~~~~~~~~~~~~~~~~ + + Lexers for HTML, XML and related markup. + + :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import RegexLexer, ExtendedRegexLexer, include, bygroups, \ + default, using +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Punctuation +from pygments.util import looks_like_xml, html_doctype_matches + +from pygments.lexers.javascript import JavascriptLexer +from pygments.lexers.jvm import ScalaLexer +from pygments.lexers.css import CssLexer, _indentation, _starts_block +from pygments.lexers.ruby import RubyLexer + +__all__ = ['HtmlLexer', 'DtdLexer', 'XmlLexer', 'XsltLexer', 'HamlLexer', + 'ScamlLexer', 'JadeLexer'] + + +class HtmlLexer(RegexLexer): + """ + For HTML 4 and XHTML 1 markup. Nested JavaScript and CSS is highlighted + by the appropriate lexer. + """ + + name = 'HTML' + aliases = ['html'] + filenames = ['*.html', '*.htm', '*.xhtml', '*.xslt'] + mimetypes = ['text/html', 'application/xhtml+xml'] + + flags = re.IGNORECASE | re.DOTALL + tokens = { + 'root': [ + ('[^<&]+', Text), + (r'&\S*?;', Name.Entity), + (r'\<\!\[CDATA\[.*?\]\]\>', Comment.Preproc), + ('<!--', Comment, 'comment'), + (r'<\?.*?\?>', Comment.Preproc), + ('<![^>]*>', Comment.Preproc), + (r'<\s*script\s*', Name.Tag, ('script-content', 'tag')), + (r'<\s*style\s*', Name.Tag, ('style-content', 'tag')), + # note: this allows tag names not used in HTML like <x:with-dash>, + # this is to support yet-unknown template engines and the like + (r'<\s*[\w:.-]+', Name.Tag, 'tag'), + (r'<\s*/\s*[\w:.-]+\s*>', Name.Tag), + ], + 'comment': [ + ('[^-]+', Comment), + ('-->', Comment, '#pop'), + ('-', Comment), + ], + 'tag': [ + (r'\s+', Text), + (r'[\w:-]+\s*=', Name.Attribute, 'attr'), + (r'[\w:-]+', Name.Attribute), + (r'/?\s*>', Name.Tag, '#pop'), + ], + 'script-content': [ + (r'<\s*/\s*script\s*>', Name.Tag, '#pop'), + (r'.+?(?=<\s*/\s*script\s*>)', using(JavascriptLexer)), + ], + 'style-content': [ + (r'<\s*/\s*style\s*>', Name.Tag, '#pop'), + (r'.+?(?=<\s*/\s*style\s*>)', using(CssLexer)), + ], + 'attr': [ + ('".*?"', String, '#pop'), + ("'.*?'", String, '#pop'), + (r'[^\s>]+', String, '#pop'), + ], + } + + def analyse_text(text): + if html_doctype_matches(text): + return 0.5 + + +class DtdLexer(RegexLexer): + """ + A lexer for DTDs (Document Type Definitions). + + .. versionadded:: 1.5 + """ + + 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). + """ + + flags = re.MULTILINE | re.DOTALL | re.UNICODE + + name = 'XML' + aliases = ['xml'] + filenames = ['*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', + '*.wsdl', '*.wsf'] + mimetypes = ['text/xml', 'application/xml', 'image/svg+xml', + 'application/rss+xml', 'application/atom+xml'] + + tokens = { + 'root': [ + ('[^<&]+', Text), + (r'&\S*?;', Name.Entity), + (r'\<\!\[CDATA\[.*?\]\]\>', Comment.Preproc), + ('<!--', Comment, 'comment'), + (r'<\?.*?\?>', Comment.Preproc), + ('<![^>]*>', Comment.Preproc), + (r'<\s*[\w:.-]+', Name.Tag, 'tag'), + (r'<\s*/\s*[\w:.-]+\s*>', Name.Tag), + ], + 'comment': [ + ('[^-]+', Comment), + ('-->', Comment, '#pop'), + ('-', Comment), + ], + 'tag': [ + (r'\s+', Text), + (r'[\w.:-]+\s*=', Name.Attribute, 'attr'), + (r'/?\s*>', Name.Tag, '#pop'), + ], + 'attr': [ + ('\s+', Text), + ('".*?"', String, '#pop'), + ("'.*?'", String, '#pop'), + (r'[^\s>]+', String, '#pop'), + ], + } + + def analyse_text(text): + if looks_like_xml(text): + return 0.5 + + +class XsltLexer(XmlLexer): + """ + A lexer for XSLT. + + .. versionadded:: 0.10 + """ + + name = 'XSLT' + aliases = ['xslt'] + filenames = ['*.xsl', '*.xslt', '*.xpl'] # xpl is XProc + mimetypes = ['application/xsl+xml', 'application/xslt+xml'] + + EXTRA_KEYWORDS = set(( + 'apply-imports', 'apply-templates', 'attribute', + 'attribute-set', 'call-template', 'choose', 'comment', + 'copy', 'copy-of', 'decimal-format', 'element', 'fallback', + 'for-each', 'if', 'import', 'include', 'key', 'message', + 'namespace-alias', 'number', 'otherwise', 'output', 'param', + 'preserve-space', 'processing-instruction', 'sort', + 'strip-space', 'stylesheet', 'template', 'text', 'transform', + 'value-of', 'variable', 'when', 'with-param' + )) + + def get_tokens_unprocessed(self, text): + for index, token, value in XmlLexer.get_tokens_unprocessed(self, text): + m = re.match('</?xsl:([^>]*)/?>?', value) + + if token is Name.Tag and m and m.group(1) in self.EXTRA_KEYWORDS: + yield index, Keyword, value + else: + yield index, token, value + + def analyse_text(text): + if looks_like_xml(text) and '<xsl' in text: + return 0.8 + + +class HamlLexer(ExtendedRegexLexer): + """ + For Haml markup. + + .. versionadded:: 1.3 + """ + + name = 'Haml' + aliases = ['haml'] + filenames = ['*.haml'] + mimetypes = ['text/x-haml'] + + flags = re.IGNORECASE + # Haml can include " |\n" anywhere, + # which is ignored and used to wrap long lines. + # To accomodate this, use this custom faux dot instead. + _dot = r'(?: \|\n(?=.* \|)|.)' + + # In certain places, a comma at the end of the line + # allows line wrapping as well. + _comma_dot = r'(?:,\s*\n|' + _dot + ')' + tokens = { + 'root': [ + (r'[ \t]*\n', Text), + (r'[ \t]*', _indentation), + ], + + 'css': [ + (r'\.[\w:-]+', Name.Class, 'tag'), + (r'\#[\w:-]+', Name.Function, 'tag'), + ], + + 'eval-or-plain': [ + (r'[&!]?==', Punctuation, 'plain'), + (r'([&!]?[=~])(' + _comma_dot + r'*\n)', + bygroups(Punctuation, using(RubyLexer)), + 'root'), + default('plain'), + ], + + 'content': [ + include('css'), + (r'%[\w:-]+', Name.Tag, 'tag'), + (r'!!!' + _dot + r'*\n', Name.Namespace, '#pop'), + (r'(/)(\[' + _dot + '*?\])(' + _dot + r'*\n)', + bygroups(Comment, Comment.Special, Comment), + '#pop'), + (r'/' + _dot + r'*\n', _starts_block(Comment, 'html-comment-block'), + '#pop'), + (r'-#' + _dot + r'*\n', _starts_block(Comment.Preproc, + 'haml-comment-block'), '#pop'), + (r'(-)(' + _comma_dot + r'*\n)', + bygroups(Punctuation, using(RubyLexer)), + '#pop'), + (r':' + _dot + r'*\n', _starts_block(Name.Decorator, 'filter-block'), + '#pop'), + include('eval-or-plain'), + ], + + 'tag': [ + include('css'), + (r'\{(,\n|' + _dot + ')*?\}', using(RubyLexer)), + (r'\[' + _dot + '*?\]', using(RubyLexer)), + (r'\(', Text, 'html-attributes'), + (r'/[ \t]*\n', Punctuation, '#pop:2'), + (r'[<>]{1,2}(?=[ \t=])', Punctuation), + include('eval-or-plain'), + ], + + 'plain': [ + (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text), + (r'(#\{)(' + _dot + '*?)(\})', + bygroups(String.Interpol, using(RubyLexer), String.Interpol)), + (r'\n', Text, 'root'), + ], + + 'html-attributes': [ + (r'\s+', Text), + (r'[\w:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'), + (r'[\w:-]+', Name.Attribute), + (r'\)', Text, '#pop'), + ], + + 'html-attribute-value': [ + (r'[ \t]+', Text), + (r'\w+', Name.Variable, '#pop'), + (r'@\w+', Name.Variable.Instance, '#pop'), + (r'\$\w+', Name.Variable.Global, '#pop'), + (r"'(\\\\|\\'|[^'\n])*'", String, '#pop'), + (r'"(\\\\|\\"|[^"\n])*"', String, '#pop'), + ], + + 'html-comment-block': [ + (_dot + '+', Comment), + (r'\n', Text, 'root'), + ], + + 'haml-comment-block': [ + (_dot + '+', Comment.Preproc), + (r'\n', Text, 'root'), + ], + + 'filter-block': [ + (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator), + (r'(#\{)(' + _dot + '*?)(\})', + bygroups(String.Interpol, using(RubyLexer), String.Interpol)), + (r'\n', Text, 'root'), + ], + } + + +class ScamlLexer(ExtendedRegexLexer): + """ + For `Scaml markup <http://scalate.fusesource.org/>`_. Scaml is Haml for Scala. + + .. versionadded:: 1.4 + """ + + name = 'Scaml' + aliases = ['scaml'] + filenames = ['*.scaml'] + mimetypes = ['text/x-scaml'] + + flags = re.IGNORECASE + # Scaml does not yet support the " |\n" notation to + # wrap long lines. Once it does, use the custom faux + # dot instead. + # _dot = r'(?: \|\n(?=.* \|)|.)' + _dot = r'.' + + tokens = { + 'root': [ + (r'[ \t]*\n', Text), + (r'[ \t]*', _indentation), + ], + + 'css': [ + (r'\.[\w:-]+', Name.Class, 'tag'), + (r'\#[\w:-]+', Name.Function, 'tag'), + ], + + 'eval-or-plain': [ + (r'[&!]?==', Punctuation, 'plain'), + (r'([&!]?[=~])(' + _dot + r'*\n)', + bygroups(Punctuation, using(ScalaLexer)), + 'root'), + default('plain'), + ], + + 'content': [ + include('css'), + (r'%[\w:-]+', Name.Tag, 'tag'), + (r'!!!' + _dot + r'*\n', Name.Namespace, '#pop'), + (r'(/)(\[' + _dot + '*?\])(' + _dot + r'*\n)', + bygroups(Comment, Comment.Special, Comment), + '#pop'), + (r'/' + _dot + r'*\n', _starts_block(Comment, 'html-comment-block'), + '#pop'), + (r'-#' + _dot + r'*\n', _starts_block(Comment.Preproc, + 'scaml-comment-block'), '#pop'), + (r'(-@\s*)(import)?(' + _dot + r'*\n)', + bygroups(Punctuation, Keyword, using(ScalaLexer)), + '#pop'), + (r'(-)(' + _dot + r'*\n)', + bygroups(Punctuation, using(ScalaLexer)), + '#pop'), + (r':' + _dot + r'*\n', _starts_block(Name.Decorator, 'filter-block'), + '#pop'), + include('eval-or-plain'), + ], + + 'tag': [ + include('css'), + (r'\{(,\n|' + _dot + ')*?\}', using(ScalaLexer)), + (r'\[' + _dot + '*?\]', using(ScalaLexer)), + (r'\(', Text, 'html-attributes'), + (r'/[ \t]*\n', Punctuation, '#pop:2'), + (r'[<>]{1,2}(?=[ \t=])', Punctuation), + include('eval-or-plain'), + ], + + 'plain': [ + (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text), + (r'(#\{)(' + _dot + '*?)(\})', + bygroups(String.Interpol, using(ScalaLexer), String.Interpol)), + (r'\n', Text, 'root'), + ], + + 'html-attributes': [ + (r'\s+', Text), + (r'[\w:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'), + (r'[\w:-]+', Name.Attribute), + (r'\)', Text, '#pop'), + ], + + 'html-attribute-value': [ + (r'[ \t]+', Text), + (r'\w+', Name.Variable, '#pop'), + (r'@\w+', Name.Variable.Instance, '#pop'), + (r'\$\w+', Name.Variable.Global, '#pop'), + (r"'(\\\\|\\'|[^'\n])*'", String, '#pop'), + (r'"(\\\\|\\"|[^"\n])*"', String, '#pop'), + ], + + 'html-comment-block': [ + (_dot + '+', Comment), + (r'\n', Text, 'root'), + ], + + 'scaml-comment-block': [ + (_dot + '+', Comment.Preproc), + (r'\n', Text, 'root'), + ], + + 'filter-block': [ + (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator), + (r'(#\{)(' + _dot + '*?)(\})', + bygroups(String.Interpol, using(ScalaLexer), String.Interpol)), + (r'\n', Text, 'root'), + ], + } + + +class JadeLexer(ExtendedRegexLexer): + """ + For Jade markup. + Jade is a variant of Scaml, see: + http://scalate.fusesource.org/documentation/scaml-reference.html + + .. versionadded:: 1.4 + """ + + name = 'Jade' + aliases = ['jade'] + filenames = ['*.jade'] + mimetypes = ['text/x-jade'] + + flags = re.IGNORECASE + _dot = r'.' + + tokens = { + 'root': [ + (r'[ \t]*\n', Text), + (r'[ \t]*', _indentation), + ], + + 'css': [ + (r'\.[\w:-]+', Name.Class, 'tag'), + (r'\#[\w:-]+', Name.Function, 'tag'), + ], + + 'eval-or-plain': [ + (r'[&!]?==', Punctuation, 'plain'), + (r'([&!]?[=~])(' + _dot + r'*\n)', + bygroups(Punctuation, using(ScalaLexer)), 'root'), + default('plain'), + ], + + 'content': [ + include('css'), + (r'!!!' + _dot + r'*\n', Name.Namespace, '#pop'), + (r'(/)(\[' + _dot + '*?\])(' + _dot + r'*\n)', + bygroups(Comment, Comment.Special, Comment), + '#pop'), + (r'/' + _dot + r'*\n', _starts_block(Comment, 'html-comment-block'), + '#pop'), + (r'-#' + _dot + r'*\n', _starts_block(Comment.Preproc, + 'scaml-comment-block'), '#pop'), + (r'(-@\s*)(import)?(' + _dot + r'*\n)', + bygroups(Punctuation, Keyword, using(ScalaLexer)), + '#pop'), + (r'(-)(' + _dot + r'*\n)', + bygroups(Punctuation, using(ScalaLexer)), + '#pop'), + (r':' + _dot + r'*\n', _starts_block(Name.Decorator, 'filter-block'), + '#pop'), + (r'[\w:-]+', Name.Tag, 'tag'), + (r'\|', Text, 'eval-or-plain'), + ], + + 'tag': [ + include('css'), + (r'\{(,\n|' + _dot + ')*?\}', using(ScalaLexer)), + (r'\[' + _dot + '*?\]', using(ScalaLexer)), + (r'\(', Text, 'html-attributes'), + (r'/[ \t]*\n', Punctuation, '#pop:2'), + (r'[<>]{1,2}(?=[ \t=])', Punctuation), + include('eval-or-plain'), + ], + + 'plain': [ + (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text), + (r'(#\{)(' + _dot + '*?)(\})', + bygroups(String.Interpol, using(ScalaLexer), String.Interpol)), + (r'\n', Text, 'root'), + ], + + 'html-attributes': [ + (r'\s+', Text), + (r'[\w:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'), + (r'[\w:-]+', Name.Attribute), + (r'\)', Text, '#pop'), + ], + + 'html-attribute-value': [ + (r'[ \t]+', Text), + (r'\w+', Name.Variable, '#pop'), + (r'@\w+', Name.Variable.Instance, '#pop'), + (r'\$\w+', Name.Variable.Global, '#pop'), + (r"'(\\\\|\\'|[^'\n])*'", String, '#pop'), + (r'"(\\\\|\\"|[^"\n])*"', String, '#pop'), + ], + + 'html-comment-block': [ + (_dot + '+', Comment), + (r'\n', Text, 'root'), + ], + + 'scaml-comment-block': [ + (_dot + '+', Comment.Preproc), + (r'\n', Text, 'root'), + ], + + 'filter-block': [ + (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator), + (r'(#\{)(' + _dot + '*?)(\})', + bygroups(String.Interpol, using(ScalaLexer), String.Interpol)), + (r'\n', Text, 'root'), + ], + } diff --git a/pygments/lexers/installers.py b/pygments/lexers/installers.py index b91613cd..b76db0a9 100644 --- a/pygments/lexers/installers.py +++ b/pygments/lexers/installers.py @@ -15,7 +15,8 @@ from pygments.lexer import RegexLexer, include, bygroups, using, this from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Punctuation, Generic, Number, Whitespace -__all__ = ['NSISLexer', 'RPMSpecLexer'] +__all__ = ['NSISLexer', 'RPMSpecLexer', 'SourcesListLexer', + 'DebianControlLexer'] class NSISLexer(RegexLexer): diff --git a/pygments/lexers/javascript.py b/pygments/lexers/javascript.py new file mode 100644 index 00000000..6e4e07e8 --- /dev/null +++ b/pygments/lexers/javascript.py @@ -0,0 +1,1192 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.javascript + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Lexers for JavaScript and related languages. + + :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import RegexLexer, include, bygroups, default, \ + using, this +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Punctuation, Other +from pygments.util import get_bool_opt, iteritems + +__all__ = ['JavascriptLexer', 'KalLexer', 'LiveScriptLexer', 'DartLexer', + 'TypeScriptLexer', 'LassoLexer', 'ObjectiveJLexer', + 'CoffeeScriptLexer', 'MaskLexer'] + + +class JavascriptLexer(RegexLexer): + """ + For JavaScript source code. + """ + + name = 'JavaScript' + aliases = ['js', 'javascript'] + filenames = ['*.js', ] + mimetypes = ['application/javascript', 'application/x-javascript', + 'text/x-javascript', 'text/javascript', ] + + flags = re.DOTALL + tokens = { + 'commentsandwhitespace': [ + (r'\s+', Text), + (r'<!--', Comment), + (r'//.*?\n', Comment.Single), + (r'/\*.*?\*/', Comment.Multiline) + ], + 'slashstartsregex': [ + include('commentsandwhitespace'), + (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' + r'([gim]+\b|\B)', String.Regex, '#pop'), + (r'(?=/)', Text, ('#pop', 'badregex')), + default('#pop') + ], + 'badregex': [ + (r'\n', Text, '#pop') + ], + 'root': [ + (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), + include('commentsandwhitespace'), + (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' + r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'), + (r'[{(\[;,]', Punctuation, 'slashstartsregex'), + (r'[})\].]', Punctuation), + (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' + r'throw|try|catch|finally|new|delete|typeof|instanceof|void|yield|' + r'this)\b', Keyword, 'slashstartsregex'), + (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), + (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' + r'extends|final|float|goto|implements|import|int|interface|long|native|' + r'package|private|protected|public|short|static|super|synchronized|throws|' + r'transient|volatile)\b', Keyword.Reserved), + (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), + (r'(Array|Boolean|Date|Error|Function|Math|netscape|' + r'Number|Object|Packages|RegExp|String|sun|decodeURI|' + r'decodeURIComponent|encodeURI|encodeURIComponent|' + r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' + r'window)\b', Name.Builtin), + (r'[$a-zA-Z_]\w*', Name.Other), + (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), + (r'0x[0-9a-fA-F]+', Number.Hex), + (r'[0-9]+', Number.Integer), + (r'"(\\\\|\\"|[^"])*"', String.Double), + (r"'(\\\\|\\'|[^'])*'", String.Single), + ] + } + + +class KalLexer(RegexLexer): + """ + For `Kal`_ source code. + + .. _Kal: http://rzimmerman.github.io/kal + + + .. versionadded:: 2.0 + """ + + name = 'Kal' + aliases = ['kal'] + filenames = ['*.kal'] + mimetypes = ['text/kal', 'application/kal'] + + flags = re.DOTALL + tokens = { + 'commentsandwhitespace': [ + (r'\s+', Text), + (r'###[^#].*?###', Comment.Multiline), + (r'#(?!##[^#]).*?\n', Comment.Single), + ], + 'functiondef': [ + (r'[$a-zA-Z_][\w\$]*\s*', Name.Function, '#pop'), + include('commentsandwhitespace'), + ], + 'classdef': [ + (r'\binherits\s+from\b', Keyword), + (r'[$a-zA-Z_][\w\$]*\s*\n', Name.Class, '#pop'), + (r'[$a-zA-Z_][\w\$]*\s*', Name.Class), + include('commentsandwhitespace'), + ], + 'listcomprehension': [ + (r'\]', Punctuation, '#pop'), + (r'\b(property|value)\b', Keyword), + include('root'), + ], + 'waitfor': [ + (r'\n', Punctuation, '#pop'), + (r'\bfrom\b', Keyword), + include('root'), + ], + 'root': [ + include('commentsandwhitespace'), + (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' + r'([gim]+\b|\B)', String.Regex), + (r'\?|:|_(?=\n)|==?|!=|-(?!>)|[<>+*/-]=?', + Operator), + (r'\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|' + r'\bbut\b|\bbitwise\b|\bmod\b|\^|\bxor\b|\bexists\b|\bdoesnt\s+exist\b', + Operator.Word), + (r'(?:\([^()]+\))?\s*>', Name.Function), + (r'[{(]', Punctuation), + (r'\[', Punctuation, 'listcomprehension'), + (r'[})\]\.\,]', Punctuation), + (r'\b(function|method|task)\b', Keyword.Declaration, 'functiondef'), + (r'\bclass\b', Keyword.Declaration, 'classdef'), + (r'\b(safe\s+)?wait\s+for\b', Keyword, 'waitfor'), + (r'\b(me|this)(\.[$a-zA-Z_][\w\.\$]*)?\b', Name.Variable.Instance), + (r'(?<![\.\$])(for(\s+(parallel|series))?|in|of|while|until|' + r'break|return|continue|' + r'when|if|unless|else|otherwise|except\s+when|' + r'throw|raise|fail\s+with|try|catch|finally|new|delete|' + r'typeof|instanceof|super|run\s+in\s+parallel|' + r'inherits\s+from)\b', Keyword), + (r'(?<![\.\$])(true|false|yes|no|on|off|null|nothing|none|' + r'NaN|Infinity|undefined)\b', + Keyword.Constant), + (r'(Array|Boolean|Date|Error|Function|Math|netscape|' + r'Number|Object|Packages|RegExp|String|sun|decodeURI|' + r'decodeURIComponent|encodeURI|encodeURIComponent|' + r'eval|isFinite|isNaN|parseFloat|parseInt|document|window|' + r'print)\b', + Name.Builtin), + (r'[$a-zA-Z_][\w\.\$]*\s*(:|[\+\-\*\/]?\=)?\b', Name.Variable), + (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), + (r'0x[0-9a-fA-F]+', Number.Hex), + (r'[0-9]+', Number.Integer), + ('"""', String, 'tdqs'), + ("'''", String, 'tsqs'), + ('"', String, 'dqs'), + ("'", String, 'sqs'), + ], + 'strings': [ + (r'[^#\\\'"]+', String), + # note that all kal strings are multi-line. + # hashmarks, quotes and backslashes must be parsed one at a time + ], + 'interpoling_string': [ + (r'}', String.Interpol, "#pop"), + include('root') + ], + 'dqs': [ + (r'"', String, '#pop'), + (r'\\.|\'', String), # double-quoted string don't need ' escapes + (r'#{', String.Interpol, "interpoling_string"), + include('strings') + ], + 'sqs': [ + (r"'", String, '#pop'), + (r'#|\\.|"', String), # single quoted strings don't need " escapses + include('strings') + ], + 'tdqs': [ + (r'"""', String, '#pop'), + (r'\\.|\'|"', String), # no need to escape quotes in triple-string + (r'#{', String.Interpol, "interpoling_string"), + include('strings'), + ], + 'tsqs': [ + (r"'''", String, '#pop'), + (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings + include('strings') + ], + } + + +class LiveScriptLexer(RegexLexer): + """ + For `LiveScript`_ source code. + + .. _LiveScript: http://gkz.github.com/LiveScript/ + + New in Pygments 1.6. + """ + + name = 'LiveScript' + aliases = ['live-script', 'livescript'] + filenames = ['*.ls'] + mimetypes = ['text/livescript'] + + flags = re.DOTALL + tokens = { + 'commentsandwhitespace': [ + (r'\s+', Text), + (r'/\*.*?\*/', Comment.Multiline), + (r'#.*?\n', Comment.Single), + ], + 'multilineregex': [ + include('commentsandwhitespace'), + (r'//([gim]+\b|\B)', String.Regex, '#pop'), + (r'/', String.Regex), + (r'[^/#]+', String.Regex) + ], + 'slashstartsregex': [ + include('commentsandwhitespace'), + (r'//', String.Regex, ('#pop', 'multilineregex')), + (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' + r'([gim]+\b|\B)', String.Regex, '#pop'), + default('#pop'), + ], + 'root': [ + # this next expr leads to infinite loops root -> slashstartsregex + # (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), + include('commentsandwhitespace'), + (r'(?:\([^()]+\))?[ ]*[~-]{1,2}>|' + r'(?:\(?[^()\n]+\)?)?[ ]*<[~-]{1,2}', Name.Function), + (r'\+\+|&&|(?<![\.\$])\b(?:and|x?or|is|isnt|not)\b|\?|:|=|' + r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|' + r'~(?!\~?>)|-(?!\-?>)|<(?!\[)|(?<!\])>|' + r'[+*`%&\|\^/])=?', + Operator, 'slashstartsregex'), + (r'[{(\[;,]', Punctuation, 'slashstartsregex'), + (r'[})\].]', Punctuation), + (r'(?<![\.\$])(for|own|in|of|while|until|loop|break|' + r'return|continue|switch|when|then|if|unless|else|' + r'throw|try|catch|finally|new|delete|typeof|instanceof|super|' + r'extends|this|class|by|const|var|to|til)\b', Keyword, + 'slashstartsregex'), + (r'(?<![\.\$])(true|false|yes|no|on|off|' + r'null|NaN|Infinity|undefined|void)\b', + Keyword.Constant), + (r'(Array|Boolean|Date|Error|Function|Math|netscape|' + r'Number|Object|Packages|RegExp|String|sun|decodeURI|' + r'decodeURIComponent|encodeURI|encodeURIComponent|' + r'eval|isFinite|isNaN|parseFloat|parseInt|document|window)\b', + Name.Builtin), + (r'[$a-zA-Z_][\w\.\-:\$]*\s*[:=]\s', Name.Variable, + 'slashstartsregex'), + (r'@[$a-zA-Z_][\w\.\-:\$]*\s*[:=]\s', Name.Variable.Instance, + 'slashstartsregex'), + (r'@', Name.Other, 'slashstartsregex'), + (r'@?[$a-zA-Z_][\w\-]*', Name.Other, 'slashstartsregex'), + (r'[0-9]+\.[0-9]+([eE][0-9]+)?[fd]?(?:[a-zA-Z_]+)?', Number.Float), + (r'[0-9]+(~[0-9a-z]+)?(?:[a-zA-Z_]+)?', Number.Integer), + ('"""', String, 'tdqs'), + ("'''", String, 'tsqs'), + ('"', String, 'dqs'), + ("'", String, 'sqs'), + (r'\\\S+', String), + (r'<\[.*?\]>', String), + ], + 'strings': [ + (r'[^#\\\'"]+', String), + # note that all coffee script strings are multi-line. + # hashmarks, quotes and backslashes must be parsed one at a time + ], + 'interpoling_string': [ + (r'}', String.Interpol, "#pop"), + include('root') + ], + 'dqs': [ + (r'"', String, '#pop'), + (r'\\.|\'', String), # double-quoted string don't need ' escapes + (r'#{', String.Interpol, "interpoling_string"), + (r'#', String), + include('strings') + ], + 'sqs': [ + (r"'", String, '#pop'), + (r'#|\\.|"', String), # single quoted strings don't need " escapses + include('strings') + ], + 'tdqs': [ + (r'"""', String, '#pop'), + (r'\\.|\'|"', String), # no need to escape quotes in triple-string + (r'#{', String.Interpol, "interpoling_string"), + (r'#', String), + include('strings'), + ], + 'tsqs': [ + (r"'''", String, '#pop'), + (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings + include('strings') + ], + } + + +class DartLexer(RegexLexer): + """ + For `Dart <http://dartlang.org/>`_ source code. + + .. versionadded:: 1.5 + """ + + name = 'Dart' + aliases = ['dart'] + filenames = ['*.dart'] + mimetypes = ['text/x-dart'] + + flags = re.MULTILINE | re.DOTALL + + tokens = { + 'root': [ + include('string_literal'), + (r'#!(.*?)$', Comment.Preproc), + (r'\b(import|export)\b', Keyword, 'import_decl'), + (r'\b(library|source|part of|part)\b', Keyword), + (r'[^\S\n]+', Text), + (r'//.*?\n', Comment.Single), + (r'/\*.*?\*/', Comment.Multiline), + (r'\b(class)\b(\s+)', + bygroups(Keyword.Declaration, Text), 'class'), + (r'\b(assert|break|case|catch|continue|default|do|else|finally|for|' + r'if|in|is|new|return|super|switch|this|throw|try|while)\b', + Keyword), + (r'\b(abstract|const|extends|factory|final|get|implements|' + r'native|operator|set|static|typedef|var)\b', Keyword.Declaration), + (r'\b(bool|double|Dynamic|int|num|Object|String|void)\b', Keyword.Type), + (r'\b(false|null|true)\b', Keyword.Constant), + (r'[~!%^&*+=|?:<>/-]|as\b', Operator), + (r'[a-zA-Z_$]\w*:', Name.Label), + (r'[a-zA-Z_$]\w*', Name), + (r'[(){}\[\],.;]', Punctuation), + (r'0[xX][0-9a-fA-F]+', Number.Hex), + # DIGIT+ (‘.’ DIGIT*)? EXPONENT? + (r'\d+(\.\d*)?([eE][+-]?\d+)?', Number), + (r'\.\d+([eE][+-]?\d+)?', Number), # ‘.’ DIGIT+ EXPONENT? + (r'\n', Text) + # pseudo-keyword negate intentionally left out + ], + 'class': [ + (r'[a-zA-Z_$]\w*', Name.Class, '#pop') + ], + 'import_decl': [ + include('string_literal'), + (r'\s+', Text), + (r'\b(as|show|hide)\b', Keyword), + (r'[a-zA-Z_$]\w*', Name), + (r'\,', Punctuation), + (r'\;', Punctuation, '#pop') + ], + 'string_literal': [ + # Raw strings. + (r'r"""([\s|\S]*?)"""', String.Double), + (r"r'''([\s|\S]*?)'''", String.Single), + (r'r"(.*?)"', String.Double), + (r"r'(.*?)'", String.Single), + # Normal Strings. + (r'"""', String.Double, 'string_double_multiline'), + (r"'''", String.Single, 'string_single_multiline'), + (r'"', String.Double, 'string_double'), + (r"'", String.Single, 'string_single') + ], + 'string_common': [ + (r"\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u\{[0-9A-Fa-f]*\}|[a-z\'\"$\\])", + String.Escape), + (r'(\$)([a-zA-Z_]\w*)', bygroups(String.Interpol, Name)), + (r'(\$\{)(.*?)(\})', + bygroups(String.Interpol, using(this), String.Interpol)) + ], + 'string_double': [ + (r'"', String.Double, '#pop'), + (r'[^\"$\\\n]+', String.Double), + include('string_common'), + (r'\$+', String.Double) + ], + 'string_double_multiline': [ + (r'"""', String.Double, '#pop'), + (r'[^\"$\\]+', String.Double), + include('string_common'), + (r'(\$|\")+', String.Double) + ], + 'string_single': [ + (r"'", String.Single, '#pop'), + (r"[^\'$\\\n]+", String.Single), + include('string_common'), + (r'\$+', String.Single) + ], + 'string_single_multiline': [ + (r"'''", String.Single, '#pop'), + (r'[^\'$\\]+', String.Single), + include('string_common'), + (r'(\$|\')+', String.Single) + ] + } + + +class TypeScriptLexer(RegexLexer): + """ + For `TypeScript <http://typescriptlang.org/>`_ source code. + + .. versionadded:: 1.6 + """ + + name = 'TypeScript' + aliases = ['ts'] + filenames = ['*.ts'] + mimetypes = ['text/x-typescript'] + + flags = re.DOTALL + tokens = { + 'commentsandwhitespace': [ + (r'\s+', Text), + (r'<!--', Comment), + (r'//.*?\n', Comment.Single), + (r'/\*.*?\*/', Comment.Multiline) + ], + 'slashstartsregex': [ + include('commentsandwhitespace'), + (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' + r'([gim]+\b|\B)', String.Regex, '#pop'), + (r'(?=/)', Text, ('#pop', 'badregex')), + default('#pop') + ], + 'badregex': [ + (r'\n', Text, '#pop') + ], + 'root': [ + (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), + include('commentsandwhitespace'), + (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' + r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'), + (r'[{(\[;,]', Punctuation, 'slashstartsregex'), + (r'[})\].]', Punctuation), + (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' + r'throw|try|catch|finally|new|delete|typeof|instanceof|void|' + r'this)\b', Keyword, 'slashstartsregex'), + (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), + (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' + r'extends|final|float|goto|implements|import|int|interface|long|native|' + r'package|private|protected|public|short|static|super|synchronized|throws|' + r'transient|volatile)\b', Keyword.Reserved), + (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), + (r'(Array|Boolean|Date|Error|Function|Math|netscape|' + r'Number|Object|Packages|RegExp|String|sun|decodeURI|' + r'decodeURIComponent|encodeURI|encodeURIComponent|' + r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' + r'window)\b', Name.Builtin), + # Match stuff like: module name {...} + (r'\b(module)(\s*)(\s*[\w?.$][\w?.$]*)(\s*)', + bygroups(Keyword.Reserved, Text, Name.Other, Text), 'slashstartsregex'), + # Match variable type keywords + (r'\b(string|bool|number)\b', Keyword.Type), + # Match stuff like: constructor + (r'\b(constructor|declare|interface|as|AS)\b', Keyword.Reserved), + # Match stuff like: super(argument, list) + (r'(super)(\s*)(\([a-zA-Z0-9,_?.$\s]+\s*\))', + bygroups(Keyword.Reserved, Text), 'slashstartsregex'), + # Match stuff like: function() {...} + (r'([a-zA-Z_?.$][\w?.$]*)\(\) \{', Name.Other, 'slashstartsregex'), + # Match stuff like: (function: return type) + (r'([\w?.$][\w?.$]*)(\s*:\s*)([\w?.$][\w?.$]*)', + bygroups(Name.Other, Text, Keyword.Type)), + (r'[$a-zA-Z_]\w*', Name.Other), + (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), + (r'0x[0-9a-fA-F]+', Number.Hex), + (r'[0-9]+', Number.Integer), + (r'"(\\\\|\\"|[^"])*"', String.Double), + (r"'(\\\\|\\'|[^'])*'", String.Single), + ] + } + + +class LassoLexer(RegexLexer): + """ + For `Lasso <http://www.lassosoft.com/>`_ source code, covering both Lasso 9 + syntax and LassoScript for Lasso 8.6 and earlier. For Lasso embedded in + HTML, use the `LassoHtmlLexer`. + + Additional options accepted: + + `builtinshighlighting` + If given and ``True``, highlight builtin types, traits, methods, and + members (default: ``True``). + `requiredelimiters` + If given and ``True``, only highlight code between delimiters as Lasso + (default: ``False``). + + .. versionadded:: 1.6 + """ + + name = 'Lasso' + aliases = ['lasso', 'lassoscript'] + filenames = ['*.lasso', '*.lasso[89]'] + alias_filenames = ['*.incl', '*.inc', '*.las'] + mimetypes = ['text/x-lasso'] + flags = re.IGNORECASE | re.DOTALL | re.MULTILINE + + tokens = { + 'root': [ + (r'^#!.+lasso9\b', Comment.Preproc, 'lasso'), + (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'), + (r'\[noprocess\]', Comment.Preproc, ('delimiters', 'noprocess')), + (r'\[', Comment.Preproc, ('delimiters', 'squarebrackets')), + (r'<\?(LassoScript|lasso|=)', Comment.Preproc, + ('delimiters', 'anglebrackets')), + (r'<(!--.*?-->)?', Other, 'delimiters'), + (r'\s+', Other), + default(('delimiters', 'lassofile')), + ], + 'delimiters': [ + (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'), + (r'\[noprocess\]', Comment.Preproc, 'noprocess'), + (r'\[', Comment.Preproc, 'squarebrackets'), + (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'), + (r'<(!--.*?-->)?', Other), + (r'[^[<]+', Other), + ], + 'nosquarebrackets': [ + (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'), + (r'<', Other), + (r'[^<]+', Other), + ], + 'noprocess': [ + (r'\[/noprocess\]', Comment.Preproc, '#pop'), + (r'\[', Other), + (r'[^[]', Other), + ], + 'squarebrackets': [ + (r'\]', Comment.Preproc, '#pop'), + include('lasso'), + ], + 'anglebrackets': [ + (r'\?>', Comment.Preproc, '#pop'), + include('lasso'), + ], + 'lassofile': [ + (r'\]|\?>', Comment.Preproc, '#pop'), + include('lasso'), + ], + 'whitespacecomments': [ + (r'\s+', Text), + (r'//.*?\n', Comment.Single), + (r'/\*\*!.*?\*/', String.Doc), + (r'/\*.*?\*/', Comment.Multiline), + ], + 'lasso': [ + # whitespace/comments + include('whitespacecomments'), + + # literals + (r'\d*\.\d+(e[+-]?\d+)?', Number.Float), + (r'0x[\da-f]+', Number.Hex), + (r'\d+', Number.Integer), + (r'([+-]?)(infinity|NaN)\b', bygroups(Operator, Number)), + (r"'", String.Single, 'singlestring'), + (r'"', String.Double, 'doublestring'), + (r'`[^`]*`', String.Backtick), + + # names + (r'\$[a-z_][\w.]*', Name.Variable), + (r'#([a-z_][\w.]*|\d+)', Name.Variable.Instance), + (r"(\.)('[a-z_][\w.]*')", + bygroups(Name.Builtin.Pseudo, Name.Variable.Class)), + (r"(self)(\s*->\s*)('[a-z_][\w.]*')", + bygroups(Name.Builtin.Pseudo, Operator, Name.Variable.Class)), + (r'(\.\.?)([a-z_][\w.]*(=(?!=))?)', + bygroups(Name.Builtin.Pseudo, Name.Other.Member)), + (r'(->\\?\s*|&\s*)([a-z_][\w.]*(=(?!=))?)', + bygroups(Operator, Name.Other.Member)), + (r'(self|inherited)\b', Name.Builtin.Pseudo), + (r'-[a-z_][\w.]*', Name.Attribute), + (r'::\s*[a-z_][\w.]*', Name.Label), + (r'(error_(code|msg)_\w+|Error_AddError|Error_ColumnRestriction|' + r'Error_DatabaseConnectionUnavailable|Error_DatabaseTimeout|' + r'Error_DeleteError|Error_FieldRestriction|Error_FileNotFound|' + r'Error_InvalidDatabase|Error_InvalidPassword|' + r'Error_InvalidUsername|Error_ModuleNotFound|' + r'Error_NoError|Error_NoPermission|Error_OutOfMemory|' + r'Error_ReqColumnMissing|Error_ReqFieldMissing|' + r'Error_RequiredColumnMissing|Error_RequiredFieldMissing|' + r'Error_UpdateError)\b', Name.Exception), + + # definitions + (r'(define)(\s+)([a-z_][\w.]*)(\s*=>\s*)(type|trait|thread)\b', + bygroups(Keyword.Declaration, Text, Name.Class, Operator, Keyword)), + (r'(define)(\s+)([a-z_][\w.]*)(\s*->\s*)([a-z_][\w.]*=?|[-+*/%])', + bygroups(Keyword.Declaration, Text, Name.Class, Operator, + Name.Function), 'signature'), + (r'(define)(\s+)([a-z_][\w.]*)', + bygroups(Keyword.Declaration, Text, Name.Function), 'signature'), + (r'(public|protected|private|provide)(\s+)(([a-z_][\w.]*=?|[-+*/%])' + r'(?=\s*\())', bygroups(Keyword, Text, Name.Function), + 'signature'), + (r'(public|protected|private|provide)(\s+)([a-z_][\w.]*)', + bygroups(Keyword, Text, Name.Function)), + + # keywords + (r'(true|false|none|minimal|full|all|void)\b', Keyword.Constant), + (r'(local|var|variable|global|data(?=\s))\b', Keyword.Declaration), + (r'(array|date|decimal|duration|integer|map|pair|string|tag|xml|' + r'null|bytes|list|queue|set|stack|staticarray|tie)\b', Keyword.Type), + (r'([a-z_][\w.]*)(\s+)(in)\b', bygroups(Name, Text, Keyword)), + (r'(let|into)(\s+)([a-z_][\w.]*)', bygroups(Keyword, Text, Name)), + (r'require\b', Keyword, 'requiresection'), + (r'(/?)(Namespace_Using)\b', bygroups(Punctuation, Keyword.Namespace)), + (r'(/?)(Cache|Database_Names|Database_SchemaNames|' + r'Database_TableNames|Define_Tag|Define_Type|Email_Batch|' + r'Encode_Set|HTML_Comment|Handle|Handle_Error|Header|If|Inline|' + r'Iterate|LJAX_Target|Link|Link_CurrentAction|Link_CurrentGroup|' + r'Link_CurrentRecord|Link_Detail|Link_FirstGroup|' + r'Link_FirstRecord|Link_LastGroup|Link_LastRecord|Link_NextGroup|' + r'Link_NextRecord|Link_PrevGroup|Link_PrevRecord|Log|Loop|' + r'NoProcess|Output_None|Portal|Private|Protect|Records|Referer|' + r'Referrer|Repeating|ResultSet|Rows|Search_Args|Search_Arguments|' + r'Select|Sort_Args|Sort_Arguments|Thread_Atomic|Value_List|While|' + r'Abort|Case|Else|If_Empty|If_False|If_Null|If_True|Loop_Abort|' + r'Loop_Continue|Loop_Count|Params|Params_Up|Return|Return_Value|' + r'Run_Children|SOAP_DefineTag|SOAP_LastRequest|SOAP_LastResponse|' + r'Tag_Name|ascending|average|by|define|descending|do|equals|' + r'frozen|group|handle_failure|import|in|into|join|let|match|max|' + r'min|on|order|parent|protected|provide|public|require|returnhome|' + r'skip|split_thread|sum|take|thread|to|trait|type|where|with|' + r'yield|yieldhome)\b', + bygroups(Punctuation, Keyword)), + + # other + (r',', Punctuation, 'commamember'), + (r'(and|or|not)\b', Operator.Word), + (r'([a-z_][\w.]*)(\s*::\s*[a-z_][\w.]*)?(\s*=(?!=))', + bygroups(Name, Name.Label, Operator)), + (r'(/?)([\w.]+)', bygroups(Punctuation, Name.Other)), + (r'(=)(n?bw|n?ew|n?cn|lte?|gte?|n?eq|n?rx|ft)\b', + bygroups(Operator, Operator.Word)), + (r':=|[-+*/%=<>&|!?\\]+', Operator), + (r'[{}():;,@^]', Punctuation), + ], + 'singlestring': [ + (r"'", String.Single, '#pop'), + (r"[^'\\]+", String.Single), + include('escape'), + (r"\\", String.Single), + ], + 'doublestring': [ + (r'"', String.Double, '#pop'), + (r'[^"\\]+', String.Double), + include('escape'), + (r'\\', String.Double), + ], + 'escape': [ + (r'\\(U[\da-f]{8}|u[\da-f]{4}|x[\da-f]{1,2}|[0-7]{1,3}|:[^:]+:|' + r'[abefnrtv?\"\'\\]|$)', String.Escape), + ], + 'signature': [ + (r'=>', Operator, '#pop'), + (r'\)', Punctuation, '#pop'), + (r'[(,]', Punctuation, 'parameter'), + include('lasso'), + ], + 'parameter': [ + (r'\)', Punctuation, '#pop'), + (r'-?[a-z_][\w.]*', Name.Attribute, '#pop'), + (r'\.\.\.', Name.Builtin.Pseudo), + include('lasso'), + ], + 'requiresection': [ + (r'(([a-z_][\w.]*=?|[-+*/%])(?=\s*\())', Name, 'requiresignature'), + (r'(([a-z_][\w.]*=?|[-+*/%])(?=(\s*::\s*[\w.]+)?\s*,))', Name), + (r'[a-z_][\w.]*=?|[-+*/%]', Name, '#pop'), + (r'::\s*[a-z_][\w.]*', Name.Label), + (r',', Punctuation), + include('whitespacecomments'), + ], + 'requiresignature': [ + (r'(\)(?=(\s*::\s*[\w.]+)?\s*,))', Punctuation, '#pop'), + (r'\)', Punctuation, '#pop:2'), + (r'-?[a-z_][\w.]*', Name.Attribute), + (r'::\s*[a-z_][\w.]*', Name.Label), + (r'\.\.\.', Name.Builtin.Pseudo), + (r'[(,]', Punctuation), + include('whitespacecomments'), + ], + 'commamember': [ + (r'(([a-z_][\w.]*=?|[-+*/%])' + r'(?=\s*(\(([^()]*\([^()]*\))*[^)]*\)\s*)?(::[\w.\s]+)?=>))', + Name.Function, 'signature'), + include('whitespacecomments'), + default('#pop'), + ], + } + + def __init__(self, **options): + self.builtinshighlighting = get_bool_opt( + options, 'builtinshighlighting', True) + self.requiredelimiters = get_bool_opt( + options, 'requiredelimiters', False) + + self._builtins = set() + self._members = set() + if self.builtinshighlighting: + from pygments.lexers._lassobuiltins import BUILTINS, MEMBERS + for key, value in iteritems(BUILTINS): + self._builtins.update(value) + for key, value in iteritems(MEMBERS): + self._members.update(value) + RegexLexer.__init__(self, **options) + + def get_tokens_unprocessed(self, text): + stack = ['root'] + if self.requiredelimiters: + stack.append('delimiters') + for index, token, value in \ + RegexLexer.get_tokens_unprocessed(self, text, stack): + if (token is Name.Other and value.lower() in self._builtins or + token is Name.Other.Member and + value.lower().rstrip('=') in self._members): + yield index, Name.Builtin, value + continue + yield index, token, value + + def analyse_text(text): + rv = 0.0 + if 'bin/lasso9' in text: + rv += 0.8 + if re.search(r'<\?(=|lasso)|\A\[', text, re.I): + rv += 0.4 + if re.search(r'local\(', text, re.I): + rv += 0.4 + if '?>' in text: + rv += 0.1 + return rv + + +class ObjectiveJLexer(RegexLexer): + """ + For Objective-J source code with preprocessor directives. + + .. versionadded:: 1.3 + """ + + name = 'Objective-J' + aliases = ['objective-j', 'objectivej', 'obj-j', 'objj'] + filenames = ['*.j'] + mimetypes = ['text/x-objective-j'] + + #: optional Comment or Whitespace + _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)*' + + flags = re.DOTALL | re.MULTILINE + + tokens = { + 'root': [ + include('whitespace'), + + # function definition + (r'^(' + _ws + r'[\+-]' + _ws + r')([\(a-zA-Z_].*?[^\(])(' + _ws + '{)', + bygroups(using(this), using(this, state='function_signature'), + using(this))), + + # class definition + (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text), + 'classname'), + (r'(@class|@protocol)(\s*)', bygroups(Keyword, Text), + 'forward_classname'), + (r'(\s*)(@end)(\s*)', bygroups(Text, Keyword, Text)), + + include('statements'), + ('[{\(\)}]', Punctuation), + (';', Punctuation), + ], + 'whitespace': [ + (r'(@import)(\s+)("(?:\\\\|\\"|[^"])*")', + bygroups(Comment.Preproc, Text, String.Double)), + (r'(@import)(\s+)(<(?:\\\\|\\>|[^>])*>)', + bygroups(Comment.Preproc, Text, String.Double)), + (r'(#(?:include|import))(\s+)("(?:\\\\|\\"|[^"])*")', + bygroups(Comment.Preproc, Text, String.Double)), + (r'(#(?:include|import))(\s+)(<(?:\\\\|\\>|[^>])*>)', + bygroups(Comment.Preproc, Text, String.Double)), + + (r'#if\s+0', Comment.Preproc, 'if0'), + (r'#', Comment.Preproc, 'macro'), + + (r'\n', Text), + (r'\s+', Text), + (r'\\\n', Text), # line continuation + (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single), + (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), + (r'<!--', Comment), + ], + 'slashstartsregex': [ + include('whitespace'), + (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' + r'([gim]+\b|\B)', String.Regex, '#pop'), + (r'(?=/)', Text, ('#pop', 'badregex')), + default('#pop'), + ], + 'badregex': [ + (r'\n', Text, '#pop'), + ], + 'statements': [ + (r'(L|@)?"', String, 'string'), + (r"(L|@)?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", + String.Char), + (r'"(\\\\|\\"|[^"])*"', String.Double), + (r"'(\\\\|\\'|[^'])*'", String.Single), + (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float), + (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), + (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex), + (r'0[0-7]+[Ll]?', Number.Oct), + (r'\d+[Ll]?', Number.Integer), + + (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), + + (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' + r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', + Operator, 'slashstartsregex'), + (r'[{(\[;,]', Punctuation, 'slashstartsregex'), + (r'[})\].]', Punctuation), + + (r'(for|in|while|do|break|return|continue|switch|case|default|if|' + r'else|throw|try|catch|finally|new|delete|typeof|instanceof|void|' + r'prototype|__proto__)\b', Keyword, 'slashstartsregex'), + + (r'(var|with|function)\b', Keyword.Declaration, 'slashstartsregex'), + + (r'(@selector|@private|@protected|@public|@encode|' + r'@synchronized|@try|@throw|@catch|@finally|@end|@property|' + r'@synthesize|@dynamic|@for|@accessors|new)\b', Keyword), + + (r'(int|long|float|short|double|char|unsigned|signed|void|' + r'id|BOOL|bool|boolean|IBOutlet|IBAction|SEL|@outlet|@action)\b', + Keyword.Type), + + (r'(self|super)\b', Name.Builtin), + + (r'(TRUE|YES|FALSE|NO|Nil|nil|NULL)\b', Keyword.Constant), + (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), + (r'(ABS|ASIN|ACOS|ATAN|ATAN2|SIN|COS|TAN|EXP|POW|CEIL|FLOOR|ROUND|' + r'MIN|MAX|RAND|SQRT|E|LN2|LN10|LOG2E|LOG10E|PI|PI2|PI_2|SQRT1_2|' + r'SQRT2)\b', Keyword.Constant), + + (r'(Array|Boolean|Date|Error|Function|Math|netscape|' + r'Number|Object|Packages|RegExp|String|sun|decodeURI|' + r'decodeURIComponent|encodeURI|encodeURIComponent|' + r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' + r'window)\b', Name.Builtin), + + (r'([$a-zA-Z_]\w*)(' + _ws + r')(?=\()', + bygroups(Name.Function, using(this))), + + (r'[$a-zA-Z_]\w*', Name), + ], + 'classname': [ + # interface definition that inherits + (r'([a-zA-Z_]\w*)(' + _ws + r':' + _ws + + r')([a-zA-Z_]\w*)?', + bygroups(Name.Class, using(this), Name.Class), '#pop'), + # interface definition for a category + (r'([a-zA-Z_]\w*)(' + _ws + r'\()([a-zA-Z_]\w*)(\))', + bygroups(Name.Class, using(this), Name.Label, Text), '#pop'), + # simple interface / implementation + (r'([a-zA-Z_]\w*)', Name.Class, '#pop'), + ], + 'forward_classname': [ + (r'([a-zA-Z_]\w*)(\s*,\s*)', + bygroups(Name.Class, Text), '#push'), + (r'([a-zA-Z_]\w*)(\s*;?)', + bygroups(Name.Class, Text), '#pop'), + ], + 'function_signature': [ + include('whitespace'), + + # start of a selector w/ parameters + (r'(\(' + _ws + r')' # open paren + r'([a-zA-Z_]\w+)' # return type + r'(' + _ws + r'\)' + _ws + r')' # close paren + r'([$a-zA-Z_]\w+' + _ws + r':)', # function name + bygroups(using(this), Keyword.Type, using(this), + Name.Function), 'function_parameters'), + + # no-param function + (r'(\(' + _ws + r')' # open paren + r'([a-zA-Z_]\w+)' # return type + r'(' + _ws + r'\)' + _ws + r')' # close paren + r'([$a-zA-Z_]\w+)', # function name + bygroups(using(this), Keyword.Type, using(this), + Name.Function), "#pop"), + + # no return type given, start of a selector w/ parameters + (r'([$a-zA-Z_]\w+' + _ws + r':)', # function name + bygroups(Name.Function), 'function_parameters'), + + # no return type given, no-param function + (r'([$a-zA-Z_]\w+)', # function name + bygroups(Name.Function), "#pop"), + + ('', Text, '#pop'), + ], + 'function_parameters': [ + include('whitespace'), + + # parameters + (r'(\(' + _ws + ')' # open paren + r'([^\)]+)' # type + r'(' + _ws + r'\)' + _ws + r')' # close paren + r'([$a-zA-Z_]\w+)', # param name + bygroups(using(this), Keyword.Type, using(this), Text)), + + # one piece of a selector name + (r'([$a-zA-Z_]\w+' + _ws + r':)', # function name + Name.Function), + + # smallest possible selector piece + (r'(:)', Name.Function), + + # var args + (r'(,' + _ws + r'\.\.\.)', using(this)), + + # param name + (r'([$a-zA-Z_]\w+)', Text), + ], + 'expression': [ + (r'([$a-zA-Z_]\w*)(\()', bygroups(Name.Function, + Punctuation)), + (r'(\))', Punctuation, "#pop"), + ], + 'string': [ + (r'"', String, '#pop'), + (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), + (r'[^\\"\n]+', String), # all other characters + (r'\\\n', String), # line continuation + (r'\\', String), # stray backslash + ], + 'macro': [ + (r'[^/\n]+', Comment.Preproc), + (r'/[*](.|\n)*?[*]/', Comment.Multiline), + (r'//.*?\n', Comment.Single, '#pop'), + (r'/', Comment.Preproc), + (r'(?<=\\)\n', Comment.Preproc), + (r'\n', Comment.Preproc, '#pop'), + ], + 'if0': [ + (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'), + (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'), + (r'.*?\n', Comment), + ] + } + + def analyse_text(text): + if re.search('^\s*@import\s+[<"]', text, re.MULTILINE): + # special directive found in most Objective-J files + return True + return False + + +class CoffeeScriptLexer(RegexLexer): + """ + For `CoffeeScript`_ source code. + + .. _CoffeeScript: http://coffeescript.org + + .. versionadded:: 1.3 + """ + + name = 'CoffeeScript' + aliases = ['coffee-script', 'coffeescript', 'coffee'] + filenames = ['*.coffee'] + mimetypes = ['text/coffeescript'] + + flags = re.DOTALL + tokens = { + 'commentsandwhitespace': [ + (r'\s+', Text), + (r'###[^#].*?###', Comment.Multiline), + (r'#(?!##[^#]).*?\n', Comment.Single), + ], + 'multilineregex': [ + (r'[^/#]+', String.Regex), + (r'///([gim]+\b|\B)', String.Regex, '#pop'), + (r'#{', String.Interpol, 'interpoling_string'), + (r'[/#]', String.Regex), + ], + 'slashstartsregex': [ + include('commentsandwhitespace'), + (r'///', String.Regex, ('#pop', 'multilineregex')), + (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' + r'([gim]+\b|\B)', String.Regex, '#pop'), + default('#pop'), + ], + 'root': [ + # this next expr leads to infinite loops root -> slashstartsregex + # (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), + include('commentsandwhitespace'), + (r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|' + r'\|\||\\(?=\n)|' + r'(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&\|\^/])=?', + Operator, 'slashstartsregex'), + (r'(?:\([^()]*\))?\s*[=-]>', Name.Function), + (r'[{(\[;,]', Punctuation, 'slashstartsregex'), + (r'[})\].]', Punctuation), + (r'(?<![\.\$])(for|own|in|of|while|until|' + r'loop|break|return|continue|' + r'switch|when|then|if|unless|else|' + r'throw|try|catch|finally|new|delete|typeof|instanceof|super|' + r'extends|this|class|by)\b', Keyword, 'slashstartsregex'), + (r'(?<![\.\$])(true|false|yes|no|on|off|null|' + r'NaN|Infinity|undefined)\b', + Keyword.Constant), + (r'(Array|Boolean|Date|Error|Function|Math|netscape|' + r'Number|Object|Packages|RegExp|String|sun|decodeURI|' + r'decodeURIComponent|encodeURI|encodeURIComponent|' + r'eval|isFinite|isNaN|parseFloat|parseInt|document|window)\b', + Name.Builtin), + (r'[$a-zA-Z_][\w\.:\$]*\s*[:=]\s', Name.Variable, + 'slashstartsregex'), + (r'@[$a-zA-Z_][\w\.:\$]*\s*[:=]\s', Name.Variable.Instance, + 'slashstartsregex'), + (r'@', Name.Other, 'slashstartsregex'), + (r'@?[$a-zA-Z_][\w\$]*', Name.Other, 'slashstartsregex'), + (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), + (r'0x[0-9a-fA-F]+', Number.Hex), + (r'[0-9]+', Number.Integer), + ('"""', String, 'tdqs'), + ("'''", String, 'tsqs'), + ('"', String, 'dqs'), + ("'", String, 'sqs'), + ], + 'strings': [ + (r'[^#\\\'"]+', String), + # note that all coffee script strings are multi-line. + # hashmarks, quotes and backslashes must be parsed one at a time + ], + 'interpoling_string': [ + (r'}', String.Interpol, "#pop"), + include('root') + ], + 'dqs': [ + (r'"', String, '#pop'), + (r'\\.|\'', String), # double-quoted string don't need ' escapes + (r'#{', String.Interpol, "interpoling_string"), + (r'#', String), + include('strings') + ], + 'sqs': [ + (r"'", String, '#pop'), + (r'#|\\.|"', String), # single quoted strings don't need " escapses + include('strings') + ], + 'tdqs': [ + (r'"""', String, '#pop'), + (r'\\.|\'|"', String), # no need to escape quotes in triple-string + (r'#{', String.Interpol, "interpoling_string"), + (r'#', String), + include('strings'), + ], + 'tsqs': [ + (r"'''", String, '#pop'), + (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings + include('strings') + ], + } + + +class MaskLexer(RegexLexer): + """ + For `Mask <http://github.com/atmajs/MaskJS>`__ markup. + + .. versionadded:: 2.0 + """ + name = 'Mask' + aliases = ['mask'] + filenames = ['*.mask'] + mimetypes = ['text/x-mask'] + + flags = re.MULTILINE | re.IGNORECASE | re.DOTALL + tokens = { + 'root': [ + (r'\s+', Text), + (r'//.*?\n', Comment.Single), + (r'/\*.*?\*/', Comment.Multiline), + (r'[\{\};>]', Punctuation), + (r"'''", String, 'string-trpl-single'), + (r'"""', String, 'string-trpl-double'), + (r"'", String, 'string-single'), + (r'"', String, 'string-double'), + (r'([\w-]+)', Name.Tag, 'node'), + (r'([^\.#;{>\s]+)', Name.Class, 'node'), + (r'(#[\w-]+)', Name.Function, 'node'), + (r'(\.[\w-]+)', Name.Variable.Class, 'node') + ], + 'string-base': [ + (r'\\.', String.Escape), + (r'~\[', String.Interpol, 'interpolation'), + (r'.', String.Single), + ], + 'string-single': [ + (r"'", String.Single, '#pop'), + include('string-base') + ], + 'string-double': [ + (r'"', String.Single, '#pop'), + include('string-base') + ], + 'string-trpl-single': [ + (r"'''", String.Single, '#pop'), + include('string-base') + ], + 'string-trpl-double': [ + (r'"""', String.Single, '#pop'), + include('string-base') + ], + 'interpolation': [ + (r'\]', String.Interpol, '#pop'), + (r'\s*:', String.Interpol, 'expression'), + (r'\s*\w+:', Name.Other), + (r'[^\]]+', String.Interpol) + ], + 'expression': [ + (r'[^\]]+', using(JavascriptLexer), '#pop') + ], + 'node': [ + (r'\s+', Text), + (r'\.', Name.Variable.Class, 'node-class'), + (r'\#', Name.Function, 'node-id'), + (r'style[ \t]*=', Name.Attribute, 'node-attr-style-value'), + (r'[\w:-]+[ \t]*=', Name.Attribute, 'node-attr-value'), + (r'[\w:-]+', Name.Attribute), + (r'[>{;]', Punctuation, '#pop') + ], + 'node-class': [ + (r'[\w-]+', Name.Variable.Class), + (r'~\[', String.Interpol, 'interpolation'), + default('#pop') + ], + 'node-id': [ + (r'[\w-]+', Name.Function), + (r'~\[', String.Interpol, 'interpolation'), + default('#pop') + ], + 'node-attr-value': [ + (r'\s+', Text), + (r'\w+', Name.Variable, '#pop'), + (r"'", String, 'string-single-pop2'), + (r'"', String, 'string-double-pop2'), + default('#pop') + ], + 'node-attr-style-value': [ + (r'\s+', Text), + (r"'", String.Single, 'css-single-end'), + (r'"', String.Single, 'css-double-end'), + include('node-attr-value') + ], + 'css-base': [ + (r'\s+', Text), + (r";", Punctuation), + (r"[\w\-]+\s*:", Name.Builtin) + ], + 'css-single-end': [ + include('css-base'), + (r"'", String.Single, '#pop:2'), + (r"[^;']+", Name.Entity) + ], + 'css-double-end': [ + include('css-base'), + (r'"', String.Single, '#pop:2'), + (r"[^;\"]+", Name.Entity) + ], + 'string-single-pop2': [ + (r"'", String.Single, '#pop:2'), + include('string-base') + ], + 'string-double-pop2': [ + (r'"', String.Single, '#pop:2'), + include('string-base') + ], + } diff --git a/pygments/lexers/markup.py b/pygments/lexers/markup.py index df269790..97d20bae 100644 --- a/pygments/lexers/markup.py +++ b/pygments/lexers/markup.py @@ -3,7 +3,7 @@ pygments.lexers.markup ~~~~~~~~~~~~~~~~~~~~~~ - Lexers for markup languages. + Lexers for non-HTML markup languages. :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. diff --git a/pygments/lexers/modeling.py b/pygments/lexers/modeling.py index 3cebebe6..1cd1b6b1 100644 --- a/pygments/lexers/modeling.py +++ b/pygments/lexers/modeling.py @@ -15,7 +15,7 @@ from pygments.lexer import RegexLexer, include, bygroups, using from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation -from pygments.lexers.web import HtmlLexer +from pygments.lexers.html import HtmlLexer __all__ = ['ModelicaLexer'] diff --git a/pygments/lexers/parsers.py b/pygments/lexers/parsers.py index 992f204a..bbbce87c 100644 --- a/pygments/lexers/parsers.py +++ b/pygments/lexers/parsers.py @@ -691,7 +691,7 @@ class AntlrActionScriptLexer(DelegatingLexer): filenames = ['*.G', '*.g'] def __init__(self, **options): - from pygments.lexers.web import ActionScriptLexer + from pygments.lexers.actionscript import ActionScriptLexer super(AntlrActionScriptLexer, self).__init__(ActionScriptLexer, AntlrLexer, **options) diff --git a/pygments/lexers/php.py b/pygments/lexers/php.py new file mode 100644 index 00000000..90496d42 --- /dev/null +++ b/pygments/lexers/php.py @@ -0,0 +1,246 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.php + ~~~~~~~~~~~~~~~~~~~ + + Lexers for PHP and related languages. + + :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import RegexLexer, include, bygroups, default, using, this +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Punctuation, Other +from pygments.util import get_bool_opt, get_list_opt, iteritems + +__all__ = ['ZephirLexer', 'PhpLexer'] + + +class ZephirLexer(RegexLexer): + """ + For `Zephir language <http://zephir-lang.com/>`_ source code. + + Zephir is a compiled high level language aimed + to the creation of C-extensions for PHP. + + .. versionadded:: 2.0 + """ + + name = 'Zephir' + aliases = ['zephir'] + filenames = ['*.zep'] + + zephir_keywords = ['fetch', 'echo', 'isset', 'empty'] + zephir_type = ['bit', 'bits', 'string'] + + flags = re.DOTALL | re.MULTILINE + + tokens = { + 'commentsandwhitespace': [ + (r'\s+', Text), + (r'//.*?\n', Comment.Single), + (r'/\*.*?\*/', Comment.Multiline) + ], + 'slashstartsregex': [ + include('commentsandwhitespace'), + (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' + r'([gim]+\b|\B)', String.Regex, '#pop'), + default('#pop') + ], + 'badregex': [ + (r'\n', Text, '#pop') + ], + 'root': [ + (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), + include('commentsandwhitespace'), + (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' + r'(<<|>>>?|==?|!=?|->|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'), + (r'[{(\[;,]', Punctuation, 'slashstartsregex'), + (r'[})\].]', Punctuation), + (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|loop|' + r'require|inline|throw|try|catch|finally|new|delete|typeof|instanceof|void|' + r'namespace|use|extends|this|fetch|isset|unset|echo|fetch|likely|unlikely|' + r'empty)\b', Keyword, 'slashstartsregex'), + (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), + (r'(abstract|boolean|bool|char|class|const|double|enum|export|extends|final|' + r'native|goto|implements|import|int|string|interface|long|ulong|char|uchar|' + r'float|unsigned|private|protected|public|short|static|self|throws|reverse|' + r'transient|volatile)\b', Keyword.Reserved), + (r'(true|false|null|undefined)\b', Keyword.Constant), + (r'(Array|Boolean|Date|_REQUEST|_COOKIE|_SESSION|' + r'_GET|_POST|_SERVER|this|stdClass|range|count|iterator|' + r'window)\b', Name.Builtin), + (r'[$a-zA-Z_][\w\\]*', Name.Other), + (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), + (r'0x[0-9a-fA-F]+', Number.Hex), + (r'[0-9]+', Number.Integer), + (r'"(\\\\|\\"|[^"])*"', String.Double), + (r"'(\\\\|\\'|[^'])*'", String.Single), + ] + } + + +class PhpLexer(RegexLexer): + """ + For `PHP <http://www.php.net/>`_ source code. + For PHP embedded in HTML, use the `HtmlPhpLexer`. + + Additional options accepted: + + `startinline` + If given and ``True`` the lexer starts highlighting with + php code (i.e.: no starting ``<?php`` required). The default + is ``False``. + `funcnamehighlighting` + If given and ``True``, highlight builtin function names + (default: ``True``). + `disabledmodules` + If given, must be a list of module names whose function names + should not be highlighted. By default all modules are highlighted + except the special ``'unknown'`` module that includes functions + that are known to php but are undocumented. + + To get a list of allowed modules have a look into the + `_phpbuiltins` module: + + .. sourcecode:: pycon + + >>> from pygments.lexers._phpbuiltins import MODULES + >>> MODULES.keys() + ['PHP Options/Info', 'Zip', 'dba', ...] + + In fact the names of those modules match the module names from + the php documentation. + """ + + name = 'PHP' + aliases = ['php', 'php3', 'php4', 'php5'] + filenames = ['*.php', '*.php[345]', '*.inc'] + mimetypes = ['text/x-php'] + + # Note that a backslash is included in the following two patterns + # PHP uses a backslash as a namespace separator + _ident_char = r'[\\\w]|[^\x00-\x7f]' + _ident_begin = r'(?:[\\_a-z]|[^\x00-\x7f])' + _ident_end = r'(?:' + _ident_char + ')*' + _ident_inner = _ident_begin + _ident_end + + flags = re.IGNORECASE | re.DOTALL | re.MULTILINE + tokens = { + 'root': [ + (r'<\?(php)?', Comment.Preproc, 'php'), + (r'[^<]+', Other), + (r'<', Other) + ], + 'php': [ + (r'\?>', Comment.Preproc, '#pop'), + (r'<<<(\'?)(' + _ident_inner + ')\1\n.*?\n\2\;?\n', String), + (r'\s+', Text), + (r'#.*?\n', Comment.Single), + (r'//.*?\n', Comment.Single), + # put the empty comment here, it is otherwise seen as + # the start of a docstring + (r'/\*\*/', Comment.Multiline), + (r'/\*\*.*?\*/', String.Doc), + (r'/\*.*?\*/', Comment.Multiline), + (r'(->|::)(\s*)(' + _ident_inner + ')', + bygroups(Operator, Text, Name.Attribute)), + (r'[~!%^&*+=|:.<>/?@-]+', Operator), + (r'[\[\]{}();,]+', Punctuation), + (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), + (r'(function)(\s*)(?=\()', bygroups(Keyword, Text)), + (r'(function)(\s+)(&?)(\s*)', + bygroups(Keyword, Text, Operator, Text), 'functionname'), + (r'(const)(\s+)(' + _ident_inner + ')', + bygroups(Keyword, Text, Name.Constant)), + (r'(and|E_PARSE|old_function|E_ERROR|or|as|E_WARNING|parent|' + r'eval|PHP_OS|break|exit|case|extends|PHP_VERSION|cfunction|' + r'FALSE|print|for|require|continue|foreach|require_once|' + r'declare|return|default|static|do|switch|die|stdClass|' + r'echo|else|TRUE|elseif|var|empty|if|xor|enddeclare|include|' + r'virtual|endfor|include_once|while|endforeach|global|__FILE__|' + r'endif|list|__LINE__|endswitch|new|__sleep|endwhile|not|' + r'array|__wakeup|E_ALL|NULL|final|php_user_filter|interface|' + r'implements|public|private|protected|abstract|clone|try|' + r'catch|throw|this|use|namespace|trait|yield|' + r'finally)\b', Keyword), + (r'(true|false|null)\b', Keyword.Constant), + (r'\$\{\$+' + _ident_inner + '\}', Name.Variable), + (r'\$+' + _ident_inner, Name.Variable), + (_ident_inner, Name.Other), + (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float), + (r'\d+[eE][+-]?[0-9]+', Number.Float), + (r'0[0-7]+', Number.Oct), + (r'0[xX][a-f0-9]+', Number.Hex), + (r'\d+', Number.Integer), + (r'0b[01]+', Number.Bin), + (r"'([^'\\]*(?:\\.[^'\\]*)*)'", String.Single), + (r'`([^`\\]*(?:\\.[^`\\]*)*)`', String.Backtick), + (r'"', String.Double, 'string'), + ], + 'classname': [ + (_ident_inner, Name.Class, '#pop') + ], + 'functionname': [ + (_ident_inner, Name.Function, '#pop') + ], + 'string': [ + (r'"', String.Double, '#pop'), + (r'[^{$"\\]+', String.Double), + (r'\\([nrt\"$\\]|[0-7]{1,3}|x[0-9a-f]{1,2})', String.Escape), + (r'\$' + _ident_inner + '(\[\S+?\]|->' + _ident_inner + ')?', + String.Interpol), + (r'(\{\$\{)(.*?)(\}\})', + bygroups(String.Interpol, using(this, _startinline=True), + String.Interpol)), + (r'(\{)(\$.*?)(\})', + bygroups(String.Interpol, using(this, _startinline=True), + String.Interpol)), + (r'(\$\{)(\S+)(\})', + bygroups(String.Interpol, Name.Variable, String.Interpol)), + (r'[${\\]+', String.Double) + ], + } + + def __init__(self, **options): + self.funcnamehighlighting = get_bool_opt( + options, 'funcnamehighlighting', True) + self.disabledmodules = get_list_opt( + options, 'disabledmodules', ['unknown']) + self.startinline = get_bool_opt(options, 'startinline', False) + + # private option argument for the lexer itself + if '_startinline' in options: + self.startinline = options.pop('_startinline') + + # collect activated functions in a set + self._functions = set() + if self.funcnamehighlighting: + from pygments.lexers._phpbuiltins import MODULES + for key, value in iteritems(MODULES): + if key not in self.disabledmodules: + self._functions.update(value) + RegexLexer.__init__(self, **options) + + def get_tokens_unprocessed(self, text): + stack = ['root'] + if self.startinline: + stack.append('php') + for index, token, value in \ + RegexLexer.get_tokens_unprocessed(self, text, stack): + if token is Name.Other: + if value in self._functions: + yield index, Name.Builtin, value + continue + yield index, token, value + + def analyse_text(text): + rv = 0.0 + if re.search(r'<\?(?!xml)', text): + rv += 0.3 + if '?>' in text: + rv += 0.1 + return rv diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py index d8b7a503..0a7ce17d 100644 --- a/pygments/lexers/templates.py +++ b/pygments/lexers/templates.py @@ -11,8 +11,9 @@ import re -from pygments.lexers.web import \ - PhpLexer, HtmlLexer, XmlLexer, JavascriptLexer, CssLexer, LassoLexer +from pygments.lexers.html import HtmlLexer, XmlLexer +from pygments.lexers.javascript import JavascriptLexer, LassoLexer +from pygments.lexers.css import CssLexer from pygments.lexers.python import PythonLexer from pygments.lexers.perl import PerlLexer from pygments.lexers.jvm import JavaLexer, TeaLangLexer diff --git a/pygments/lexers/text.py b/pygments/lexers/text.py index d4aeaeeb..3a26106c 100644 --- a/pygments/lexers/text.py +++ b/pygments/lexers/text.py @@ -18,7 +18,7 @@ from pygments.lexers.markup import BBCodeLexer, MoinWikiLexer, RstLexer, \ from pygments.lexers.installers import DebianControlLexer, SourcesListLexer from pygments.lexers.misc.make import MakefileLexer, BaseMakefileLexer, \ CMakeLexer -from pygments.lexers.dsls import HxmlLexer +from pygments.lexers.haxe import HxmlLexer from pygments.lexers.diff import DiffLexer, DarcsPatchLexer from pygments.lexers.data import YamlLexer from pygments.lexers.textfmts import IrcLogsLexer, GettextLexer, HttpLexer diff --git a/pygments/lexers/web.py b/pygments/lexers/web.py index b28d3df7..8db0da5b 100644 --- a/pygments/lexers/web.py +++ b/pygments/lexers/web.py @@ -3,4513 +3,22 @@ pygments.lexers.web ~~~~~~~~~~~~~~~~~~~ - Lexers for web-related languages and markup. + Just export previously exported lexers. :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ -import re -import copy - -from pygments.lexer import RegexLexer, ExtendedRegexLexer, bygroups, using, \ - include, this, default -from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ - Number, Other, Punctuation, Literal -from pygments.util import get_bool_opt, get_list_opt, looks_like_xml, \ - html_doctype_matches, unirange, iteritems -from pygments.lexers.ruby import RubyLexer -from pygments.lexers.jvm import ScalaLexer - - -__all__ = ['HtmlLexer', 'XmlLexer', 'JavascriptLexer', 'JsonLexer', 'CssLexer', - 'PhpLexer', 'ActionScriptLexer', 'XsltLexer', 'ActionScript3Lexer', - 'MxmlLexer', 'HaxeLexer', 'HamlLexer', 'SassLexer', 'ScssLexer', - 'ObjectiveJLexer', 'CoffeeScriptLexer', 'LiveScriptLexer', - 'DuelLexer', 'ScamlLexer', 'JadeLexer', 'XQueryLexer', - 'DtdLexer', 'DartLexer', 'LassoLexer', 'QmlLexer', 'TypeScriptLexer', - 'KalLexer', 'CirruLexer', 'MaskLexer', 'ZephirLexer', 'SlimLexer'] - - -class JavascriptLexer(RegexLexer): - """ - For JavaScript source code. - """ - - name = 'JavaScript' - aliases = ['js', 'javascript'] - filenames = ['*.js', ] - mimetypes = ['application/javascript', 'application/x-javascript', - 'text/x-javascript', 'text/javascript', ] - - flags = re.DOTALL - tokens = { - 'commentsandwhitespace': [ - (r'\s+', Text), - (r'<!--', Comment), - (r'//.*?\n', Comment.Single), - (r'/\*.*?\*/', Comment.Multiline) - ], - 'slashstartsregex': [ - include('commentsandwhitespace'), - (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' - r'([gim]+\b|\B)', String.Regex, '#pop'), - (r'(?=/)', Text, ('#pop', 'badregex')), - default('#pop') - ], - 'badregex': [ - (r'\n', Text, '#pop') - ], - 'root': [ - (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), - include('commentsandwhitespace'), - (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' - r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'), - (r'[{(\[;,]', Punctuation, 'slashstartsregex'), - (r'[})\].]', Punctuation), - (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' - r'throw|try|catch|finally|new|delete|typeof|instanceof|void|yield|' - r'this)\b', Keyword, 'slashstartsregex'), - (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), - (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' - r'extends|final|float|goto|implements|import|int|interface|long|native|' - r'package|private|protected|public|short|static|super|synchronized|throws|' - r'transient|volatile)\b', Keyword.Reserved), - (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), - (r'(Array|Boolean|Date|Error|Function|Math|netscape|' - r'Number|Object|Packages|RegExp|String|sun|decodeURI|' - r'decodeURIComponent|encodeURI|encodeURIComponent|' - r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' - r'window)\b', Name.Builtin), - (r'[$a-zA-Z_]\w*', Name.Other), - (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), - (r'0x[0-9a-fA-F]+', Number.Hex), - (r'[0-9]+', Number.Integer), - (r'"(\\\\|\\"|[^"])*"', String.Double), - (r"'(\\\\|\\'|[^'])*'", String.Single), - ] - } - - -class JsonLexer(RegexLexer): - """ - For JSON data structures. - - .. versionadded:: 1.5 - """ - - name = 'JSON' - aliases = ['json'] - filenames = ['*.json'] - mimetypes = [ 'application/json', ] - - # integer part of a number - int_part = r'-?(0|[1-9]\d*)' - - # fractional part of a number - frac_part = r'\.\d+' - - # exponential part of a number - exp_part = r'[eE](\+|-)?\d+' - - - flags = re.DOTALL - tokens = { - 'whitespace': [ - (r'\s+', Text), - ], - - # represents a simple terminal value - 'simplevalue': [ - (r'(true|false|null)\b', Keyword.Constant), - (('%(int_part)s(%(frac_part)s%(exp_part)s|' - '%(exp_part)s|%(frac_part)s)') % vars(), - Number.Float), - (int_part, Number.Integer), - (r'"(\\\\|\\"|[^"])*"', String.Double), - ], - - - # the right hand side of an object, after the attribute name - 'objectattribute': [ - include('value'), - (r':', Punctuation), - # comma terminates the attribute but expects more - (r',', Punctuation, '#pop'), - # a closing bracket terminates the entire object, so pop twice - (r'}', Punctuation, ('#pop', '#pop')), - ], - - # a json object - { attr, attr, ... } - 'objectvalue': [ - include('whitespace'), - (r'"(\\\\|\\"|[^"])*"', Name.Tag, 'objectattribute'), - (r'}', Punctuation, '#pop'), - ], - - # json array - [ value, value, ... } - 'arrayvalue': [ - include('whitespace'), - include('value'), - (r',', Punctuation), - (r']', Punctuation, '#pop'), - ], - - # a json value - either a simple value or a complex value (object or array) - 'value': [ - include('whitespace'), - include('simplevalue'), - (r'{', Punctuation, 'objectvalue'), - (r'\[', Punctuation, 'arrayvalue'), - ], - - - # the root of a json document whould be a value - 'root': [ - include('value'), - ], - - } - +from pygments.lexers.html import HtmlLexer, DtdLexer, XmlLexer, XsltLexer, \ + HamlLexer, ScamlLexer, JadeLexer +from pygments.lexers.css import CssLexer, SassLexer, ScssLexer +from pygments.lexers.javascript import JavascriptLexer, LiveScriptLexer, \ + DartLexer, TypeScriptLexer, LassoLexer, ObjectiveJLexer, CoffeeScriptLexer +from pygments.lexers.actionscript import ActionScriptLexer, \ + ActionScript3Lexer, MxmlLexer +from pygments.lexers.php import PhpLexer +from pygments.lexers.webmisc import DuelLexer, XQueryLexer, SlimLexer, QmlLexer +from pygments.lexers.data import JsonLexer JSONLexer = JsonLexer # for backwards compatibility with Pygments 1.5 - -class ActionScriptLexer(RegexLexer): - """ - For ActionScript source code. - - .. versionadded:: 0.9 - """ - - name = 'ActionScript' - aliases = ['as', 'actionscript'] - filenames = ['*.as'] - mimetypes = ['application/x-actionscript', 'text/x-actionscript', - 'text/actionscript'] - - flags = re.DOTALL - tokens = { - 'root': [ - (r'\s+', Text), - (r'//.*?\n', Comment.Single), - (r'/\*.*?\*/', Comment.Multiline), - (r'/(\\\\|\\/|[^/\n])*/[gim]*', String.Regex), - (r'[~\^\*!%&<>\|+=:;,/?\\-]+', Operator), - (r'[{}\[\]();.]+', Punctuation), - (r'(case|default|for|each|in|while|do|break|return|continue|if|else|' - r'throw|try|catch|var|with|new|typeof|arguments|instanceof|this|' - r'switch)\b', Keyword), - (r'(class|public|final|internal|native|override|private|protected|' - r'static|import|extends|implements|interface|intrinsic|return|super|' - r'dynamic|function|const|get|namespace|package|set)\b', - Keyword.Declaration), - (r'(true|false|null|NaN|Infinity|-Infinity|undefined|Void)\b', - Keyword.Constant), - (r'(Accessibility|AccessibilityProperties|ActionScriptVersion|' - r'ActivityEvent|AntiAliasType|ApplicationDomain|AsBroadcaster|Array|' - r'AsyncErrorEvent|AVM1Movie|BevelFilter|Bitmap|BitmapData|' - r'BitmapDataChannel|BitmapFilter|BitmapFilterQuality|BitmapFilterType|' - r'BlendMode|BlurFilter|Boolean|ByteArray|Camera|Capabilities|CapsStyle|' - r'Class|Color|ColorMatrixFilter|ColorTransform|ContextMenu|' - r'ContextMenuBuiltInItems|ContextMenuEvent|ContextMenuItem|' - r'ConvultionFilter|CSMSettings|DataEvent|Date|DefinitionError|' - r'DeleteObjectSample|Dictionary|DisplacmentMapFilter|DisplayObject|' - r'DisplacmentMapFilterMode|DisplayObjectContainer|DropShadowFilter|' - r'Endian|EOFError|Error|ErrorEvent|EvalError|Event|EventDispatcher|' - r'EventPhase|ExternalInterface|FileFilter|FileReference|' - r'FileReferenceList|FocusDirection|FocusEvent|Font|FontStyle|FontType|' - r'FrameLabel|FullScreenEvent|Function|GlowFilter|GradientBevelFilter|' - r'GradientGlowFilter|GradientType|Graphics|GridFitType|HTTPStatusEvent|' - r'IBitmapDrawable|ID3Info|IDataInput|IDataOutput|IDynamicPropertyOutput' - r'IDynamicPropertyWriter|IEventDispatcher|IExternalizable|' - r'IllegalOperationError|IME|IMEConversionMode|IMEEvent|int|' - r'InteractiveObject|InterpolationMethod|InvalidSWFError|InvokeEvent|' - r'IOError|IOErrorEvent|JointStyle|Key|Keyboard|KeyboardEvent|KeyLocation|' - r'LineScaleMode|Loader|LoaderContext|LoaderInfo|LoadVars|LocalConnection|' - r'Locale|Math|Matrix|MemoryError|Microphone|MorphShape|Mouse|MouseEvent|' - r'MovieClip|MovieClipLoader|Namespace|NetConnection|NetStatusEvent|' - r'NetStream|NewObjectSample|Number|Object|ObjectEncoding|PixelSnapping|' - r'Point|PrintJob|PrintJobOptions|PrintJobOrientation|ProgressEvent|Proxy|' - r'QName|RangeError|Rectangle|ReferenceError|RegExp|Responder|Sample|Scene|' - r'ScriptTimeoutError|Security|SecurityDomain|SecurityError|' - r'SecurityErrorEvent|SecurityPanel|Selection|Shape|SharedObject|' - r'SharedObjectFlushStatus|SimpleButton|Socket|Sound|SoundChannel|' - r'SoundLoaderContext|SoundMixer|SoundTransform|SpreadMethod|Sprite|' - r'StackFrame|StackOverflowError|Stage|StageAlign|StageDisplayState|' - r'StageQuality|StageScaleMode|StaticText|StatusEvent|String|StyleSheet|' - r'SWFVersion|SyncEvent|SyntaxError|System|TextColorType|TextField|' - r'TextFieldAutoSize|TextFieldType|TextFormat|TextFormatAlign|' - r'TextLineMetrics|TextRenderer|TextSnapshot|Timer|TimerEvent|Transform|' - r'TypeError|uint|URIError|URLLoader|URLLoaderDataFormat|URLRequest|' - r'URLRequestHeader|URLRequestMethod|URLStream|URLVariabeles|VerifyError|' - r'Video|XML|XMLDocument|XMLList|XMLNode|XMLNodeType|XMLSocket|XMLUI)\b', - Name.Builtin), - (r'(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|' - r'isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|' - r'isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|' - r'unescape)\b',Name.Function), - (r'[$a-zA-Z_]\w*', Name.Other), - (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), - (r'0x[0-9a-f]+', Number.Hex), - (r'[0-9]+', Number.Integer), - (r'"(\\\\|\\"|[^"])*"', String.Double), - (r"'(\\\\|\\'|[^'])*'", String.Single), - ] - } - - -class ActionScript3Lexer(RegexLexer): - """ - For ActionScript 3 source code. - - .. versionadded:: 0.11 - """ - - name = 'ActionScript 3' - aliases = ['as3', 'actionscript3'] - filenames = ['*.as'] - mimetypes = ['application/x-actionscript3', 'text/x-actionscript3', - 'text/actionscript3'] - - identifier = r'[$a-zA-Z_]\w*' - typeidentifier = identifier + '(?:\.<\w+>)?' - - flags = re.DOTALL | re.MULTILINE - tokens = { - 'root': [ - (r'\s+', Text), - (r'(function\s+)(' + identifier + r')(\s*)(\()', - bygroups(Keyword.Declaration, Name.Function, Text, Operator), - 'funcparams'), - (r'(var|const)(\s+)(' + identifier + r')(\s*)(:)(\s*)(' + - typeidentifier + r')', - bygroups(Keyword.Declaration, Text, Name, Text, Punctuation, Text, - Keyword.Type)), - (r'(import|package)(\s+)((?:' + identifier + r'|\.)+)(\s*)', - bygroups(Keyword, Text, Name.Namespace, Text)), - (r'(new)(\s+)(' + typeidentifier + r')(\s*)(\()', - bygroups(Keyword, Text, Keyword.Type, Text, Operator)), - (r'//.*?\n', Comment.Single), - (r'/\*.*?\*/', Comment.Multiline), - (r'/(\\\\|\\/|[^\n])*/[gisx]*', String.Regex), - (r'(\.)(' + identifier + r')', bygroups(Operator, Name.Attribute)), - (r'(case|default|for|each|in|while|do|break|return|continue|if|else|' - r'throw|try|catch|with|new|typeof|arguments|instanceof|this|' - r'switch|import|include|as|is)\b', - Keyword), - (r'(class|public|final|internal|native|override|private|protected|' - r'static|import|extends|implements|interface|intrinsic|return|super|' - r'dynamic|function|const|get|namespace|package|set)\b', - Keyword.Declaration), - (r'(true|false|null|NaN|Infinity|-Infinity|undefined|void)\b', - Keyword.Constant), - (r'(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|' - r'isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|' - r'isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|' - r'unescape)\b', Name.Function), - (identifier, Name), - (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), - (r'0x[0-9a-f]+', Number.Hex), - (r'[0-9]+', Number.Integer), - (r'"(\\\\|\\"|[^"])*"', String.Double), - (r"'(\\\\|\\'|[^'])*'", String.Single), - (r'[~\^\*!%&<>\|+=:;,/?\\{}\[\]().-]+', Operator), - ], - 'funcparams': [ - (r'\s+', Text), - (r'(\s*)(\.\.\.)?(' + identifier + r')(\s*)(:)(\s*)(' + - typeidentifier + r'|\*)(\s*)', - bygroups(Text, Punctuation, Name, Text, Operator, Text, - Keyword.Type, Text), 'defval'), - (r'\)', Operator, 'type') - ], - 'type': [ - (r'(\s*)(:)(\s*)(' + typeidentifier + r'|\*)', - bygroups(Text, Operator, Text, Keyword.Type), '#pop:2'), - (r'\s*', Text, '#pop:2') - ], - 'defval': [ - (r'(=)(\s*)([^(),]+)(\s*)(,?)', - bygroups(Operator, Text, using(this), Text, Operator), '#pop'), - (r',?', Operator, '#pop') - ] - } - - def analyse_text(text): - if re.match(r'\w+\s*:\s*\w', text): - return 0.3 - return 0 - - -class CssLexer(RegexLexer): - """ - For CSS (Cascading Style Sheets). - """ - - name = 'CSS' - aliases = ['css'] - filenames = ['*.css'] - mimetypes = ['text/css'] - - tokens = { - 'root': [ - include('basics'), - ], - 'basics': [ - (r'\s+', Text), - (r'/\*(?:.|\n)*?\*/', Comment), - (r'{', Punctuation, 'content'), - (r'\:[\w-]+', Name.Decorator), - (r'\.[\w-]+', Name.Class), - (r'\#[\w-]+', Name.Function), - (r'@[\w-]+', Keyword, 'atrule'), - (r'[\w-]+', Name.Tag), - (r'[~\^\*!%&$\[\]\(\)<>\|+=@:;,./?-]', Operator), - (r'"(\\\\|\\"|[^"])*"', String.Double), - (r"'(\\\\|\\'|[^'])*'", String.Single) - ], - 'atrule': [ - (r'{', Punctuation, 'atcontent'), - (r';', Punctuation, '#pop'), - include('basics'), - ], - 'atcontent': [ - include('basics'), - (r'}', Punctuation, '#pop:2'), - ], - 'content': [ - (r'\s+', Text), - (r'}', Punctuation, '#pop'), - (r'url\(.*?\)', String.Other), - (r'^@.*?$', Comment.Preproc), - (r'(azimuth|background-attachment|background-color|' - r'background-image|background-position|background-repeat|' - r'background|border-bottom-color|border-bottom-style|' - r'border-bottom-width|border-left-color|border-left-style|' - r'border-left-width|border-right|border-right-color|' - r'border-right-style|border-right-width|border-top-color|' - r'border-top-style|border-top-width|border-bottom|' - r'border-collapse|border-left|border-width|border-color|' - r'border-spacing|border-style|border-top|border|caption-side|' - r'clear|clip|color|content|counter-increment|counter-reset|' - r'cue-after|cue-before|cue|cursor|direction|display|' - r'elevation|empty-cells|float|font-family|font-size|' - r'font-size-adjust|font-stretch|font-style|font-variant|' - r'font-weight|font|height|letter-spacing|line-height|' - r'list-style-type|list-style-image|list-style-position|' - r'list-style|margin-bottom|margin-left|margin-right|' - r'margin-top|margin|marker-offset|marks|max-height|max-width|' - r'min-height|min-width|opacity|orphans|outline-color|' - r'outline-style|outline-width|outline|overflow(?:-x|-y)?|padding-bottom|' - r'padding-left|padding-right|padding-top|padding|page|' - r'page-break-after|page-break-before|page-break-inside|' - r'pause-after|pause-before|pause|pitch-range|pitch|' - r'play-during|position|quotes|richness|right|size|' - r'speak-header|speak-numeral|speak-punctuation|speak|' - r'speech-rate|stress|table-layout|text-align|text-decoration|' - r'text-indent|text-shadow|text-transform|top|unicode-bidi|' - r'vertical-align|visibility|voice-family|volume|white-space|' - r'widows|width|word-spacing|z-index|bottom|' - r'above|absolute|always|armenian|aural|auto|avoid|baseline|' - r'behind|below|bidi-override|blink|block|bolder|bold|both|' - r'capitalize|center-left|center-right|center|circle|' - r'cjk-ideographic|close-quote|collapse|condensed|continuous|' - r'crop|crosshair|cross|cursive|dashed|decimal-leading-zero|' - r'decimal|default|digits|disc|dotted|double|e-resize|embed|' - r'extra-condensed|extra-expanded|expanded|fantasy|far-left|' - r'far-right|faster|fast|fixed|georgian|groove|hebrew|help|' - r'hidden|hide|higher|high|hiragana-iroha|hiragana|icon|' - r'inherit|inline-table|inline|inset|inside|invert|italic|' - r'justify|katakana-iroha|katakana|landscape|larger|large|' - r'left-side|leftwards|left|level|lighter|line-through|list-item|' - r'loud|lower-alpha|lower-greek|lower-roman|lowercase|ltr|' - r'lower|low|medium|message-box|middle|mix|monospace|' - r'n-resize|narrower|ne-resize|no-close-quote|no-open-quote|' - r'no-repeat|none|normal|nowrap|nw-resize|oblique|once|' - r'open-quote|outset|outside|overline|pointer|portrait|px|' - r'relative|repeat-x|repeat-y|repeat|rgb|ridge|right-side|' - r'rightwards|s-resize|sans-serif|scroll|se-resize|' - r'semi-condensed|semi-expanded|separate|serif|show|silent|' - r'slower|slow|small-caps|small-caption|smaller|soft|solid|' - r'spell-out|square|static|status-bar|super|sw-resize|' - r'table-caption|table-cell|table-column|table-column-group|' - r'table-footer-group|table-header-group|table-row|' - r'table-row-group|text-bottom|text-top|text|thick|thin|' - r'transparent|ultra-condensed|ultra-expanded|underline|' - r'upper-alpha|upper-latin|upper-roman|uppercase|url|' - r'visible|w-resize|wait|wider|x-fast|x-high|x-large|x-loud|' - r'x-low|x-small|x-soft|xx-large|xx-small|yes)\b', Keyword), - (r'(indigo|gold|firebrick|indianred|yellow|darkolivegreen|' - r'darkseagreen|mediumvioletred|mediumorchid|chartreuse|' - r'mediumslateblue|black|springgreen|crimson|lightsalmon|brown|' - r'turquoise|olivedrab|cyan|silver|skyblue|gray|darkturquoise|' - r'goldenrod|darkgreen|darkviolet|darkgray|lightpink|teal|' - r'darkmagenta|lightgoldenrodyellow|lavender|yellowgreen|thistle|' - r'violet|navy|orchid|blue|ghostwhite|honeydew|cornflowerblue|' - r'darkblue|darkkhaki|mediumpurple|cornsilk|red|bisque|slategray|' - r'darkcyan|khaki|wheat|deepskyblue|darkred|steelblue|aliceblue|' - r'gainsboro|mediumturquoise|floralwhite|coral|purple|lightgrey|' - r'lightcyan|darksalmon|beige|azure|lightsteelblue|oldlace|' - r'greenyellow|royalblue|lightseagreen|mistyrose|sienna|' - r'lightcoral|orangered|navajowhite|lime|palegreen|burlywood|' - r'seashell|mediumspringgreen|fuchsia|papayawhip|blanchedalmond|' - r'peru|aquamarine|white|darkslategray|ivory|dodgerblue|' - r'lemonchiffon|chocolate|orange|forestgreen|slateblue|olive|' - r'mintcream|antiquewhite|darkorange|cadetblue|moccasin|' - r'limegreen|saddlebrown|darkslateblue|lightskyblue|deeppink|' - r'plum|aqua|darkgoldenrod|maroon|sandybrown|magenta|tan|' - r'rosybrown|pink|lightblue|palevioletred|mediumseagreen|' - r'dimgray|powderblue|seagreen|snow|mediumblue|midnightblue|' - r'paleturquoise|palegoldenrod|whitesmoke|darkorchid|salmon|' - r'lightslategray|lawngreen|lightgreen|tomato|hotpink|' - r'lightyellow|lavenderblush|linen|mediumaquamarine|green|' - r'blueviolet|peachpuff)\b', Name.Builtin), - (r'\!important', Comment.Preproc), - (r'/\*(?:.|\n)*?\*/', Comment), - (r'\#[a-zA-Z0-9]{1,6}', Number), - (r'[\.-]?[0-9]*[\.]?[0-9]+(em|px|pt|pc|in|mm|cm|ex|s)\b', Number), - # Separate regex for percentages, as can't do word boundaries with % - (r'[\.-]?[0-9]*[\.]?[0-9]+%', Number), - (r'-?[0-9]+', Number), - (r'[~\^\*!%&<>\|+=@:,./?-]+', Operator), - (r'[\[\]();]+', Punctuation), - (r'"(\\\\|\\"|[^"])*"', String.Double), - (r"'(\\\\|\\'|[^'])*'", String.Single), - (r'[a-zA-Z_]\w*', Name) - ] - } - - -class ObjectiveJLexer(RegexLexer): - """ - For Objective-J source code with preprocessor directives. - - .. versionadded:: 1.3 - """ - - name = 'Objective-J' - aliases = ['objective-j', 'objectivej', 'obj-j', 'objj'] - filenames = ['*.j'] - mimetypes = ['text/x-objective-j'] - - #: optional Comment or Whitespace - _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)*' - - flags = re.DOTALL | re.MULTILINE - - tokens = { - 'root': [ - include('whitespace'), - - # function definition - (r'^(' + _ws + r'[\+-]' + _ws + r')([\(a-zA-Z_].*?[^\(])(' + _ws + '{)', - bygroups(using(this), using(this, state='function_signature'), - using(this))), - - # class definition - (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text), - 'classname'), - (r'(@class|@protocol)(\s*)', bygroups(Keyword, Text), - 'forward_classname'), - (r'(\s*)(@end)(\s*)', bygroups(Text, Keyword, Text)), - - include('statements'), - ('[{\(\)}]', Punctuation), - (';', Punctuation), - ], - 'whitespace': [ - (r'(@import)(\s+)("(?:\\\\|\\"|[^"])*")', - bygroups(Comment.Preproc, Text, String.Double)), - (r'(@import)(\s+)(<(?:\\\\|\\>|[^>])*>)', - bygroups(Comment.Preproc, Text, String.Double)), - (r'(#(?:include|import))(\s+)("(?:\\\\|\\"|[^"])*")', - bygroups(Comment.Preproc, Text, String.Double)), - (r'(#(?:include|import))(\s+)(<(?:\\\\|\\>|[^>])*>)', - bygroups(Comment.Preproc, Text, String.Double)), - - (r'#if\s+0', Comment.Preproc, 'if0'), - (r'#', Comment.Preproc, 'macro'), - - (r'\n', Text), - (r'\s+', Text), - (r'\\\n', Text), # line continuation - (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single), - (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), - (r'<!--', Comment), - ], - 'slashstartsregex': [ - include('whitespace'), - (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' - r'([gim]+\b|\B)', String.Regex, '#pop'), - (r'(?=/)', Text, ('#pop', 'badregex')), - default('#pop'), - ], - 'badregex': [ - (r'\n', Text, '#pop'), - ], - 'statements': [ - (r'(L|@)?"', String, 'string'), - (r"(L|@)?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", - String.Char), - (r'"(\\\\|\\"|[^"])*"', String.Double), - (r"'(\\\\|\\'|[^'])*'", String.Single), - (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float), - (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), - (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex), - (r'0[0-7]+[Ll]?', Number.Oct), - (r'\d+[Ll]?', Number.Integer), - - (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), - - (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' - r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', - Operator, 'slashstartsregex'), - (r'[{(\[;,]', Punctuation, 'slashstartsregex'), - (r'[})\].]', Punctuation), - - (r'(for|in|while|do|break|return|continue|switch|case|default|if|' - r'else|throw|try|catch|finally|new|delete|typeof|instanceof|void|' - r'prototype|__proto__)\b', Keyword, 'slashstartsregex'), - - (r'(var|with|function)\b', Keyword.Declaration, 'slashstartsregex'), - - (r'(@selector|@private|@protected|@public|@encode|' - r'@synchronized|@try|@throw|@catch|@finally|@end|@property|' - r'@synthesize|@dynamic|@for|@accessors|new)\b', Keyword), - - (r'(int|long|float|short|double|char|unsigned|signed|void|' - r'id|BOOL|bool|boolean|IBOutlet|IBAction|SEL|@outlet|@action)\b', - Keyword.Type), - - (r'(self|super)\b', Name.Builtin), - - (r'(TRUE|YES|FALSE|NO|Nil|nil|NULL)\b', Keyword.Constant), - (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), - (r'(ABS|ASIN|ACOS|ATAN|ATAN2|SIN|COS|TAN|EXP|POW|CEIL|FLOOR|ROUND|' - r'MIN|MAX|RAND|SQRT|E|LN2|LN10|LOG2E|LOG10E|PI|PI2|PI_2|SQRT1_2|' - r'SQRT2)\b', Keyword.Constant), - - (r'(Array|Boolean|Date|Error|Function|Math|netscape|' - r'Number|Object|Packages|RegExp|String|sun|decodeURI|' - r'decodeURIComponent|encodeURI|encodeURIComponent|' - r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' - r'window)\b', Name.Builtin), - - (r'([$a-zA-Z_]\w*)(' + _ws + r')(?=\()', - bygroups(Name.Function, using(this))), - - (r'[$a-zA-Z_]\w*', Name), - ], - 'classname' : [ - # interface definition that inherits - (r'([a-zA-Z_]\w*)(' + _ws + r':' + _ws + - r')([a-zA-Z_]\w*)?', - bygroups(Name.Class, using(this), Name.Class), '#pop'), - # interface definition for a category - (r'([a-zA-Z_]\w*)(' + _ws + r'\()([a-zA-Z_]\w*)(\))', - bygroups(Name.Class, using(this), Name.Label, Text), '#pop'), - # simple interface / implementation - (r'([a-zA-Z_]\w*)', Name.Class, '#pop'), - ], - 'forward_classname' : [ - (r'([a-zA-Z_]\w*)(\s*,\s*)', - bygroups(Name.Class, Text), '#push'), - (r'([a-zA-Z_]\w*)(\s*;?)', - bygroups(Name.Class, Text), '#pop'), - ], - 'function_signature': [ - include('whitespace'), - - # start of a selector w/ parameters - (r'(\(' + _ws + r')' # open paren - r'([a-zA-Z_]\w+)' # return type - r'(' + _ws + r'\)' + _ws + r')' # close paren - r'([$a-zA-Z_]\w+' + _ws + r':)', # function name - bygroups(using(this), Keyword.Type, using(this), - Name.Function), 'function_parameters'), - - # no-param function - (r'(\(' + _ws + r')' # open paren - r'([a-zA-Z_]\w+)' # return type - r'(' + _ws + r'\)' + _ws + r')' # close paren - r'([$a-zA-Z_]\w+)', # function name - bygroups(using(this), Keyword.Type, using(this), - Name.Function), "#pop"), - - # no return type given, start of a selector w/ parameters - (r'([$a-zA-Z_]\w+' + _ws + r':)', # function name - bygroups (Name.Function), 'function_parameters'), - - # no return type given, no-param function - (r'([$a-zA-Z_]\w+)', # function name - bygroups(Name.Function), "#pop"), - - ('', Text, '#pop'), - ], - 'function_parameters': [ - include('whitespace'), - - # parameters - (r'(\(' + _ws + ')' # open paren - r'([^\)]+)' # type - r'(' + _ws + r'\)' + _ws + r')' # close paren - r'([$a-zA-Z_]\w+)', # param name - bygroups(using(this), Keyword.Type, using(this), Text)), - - # one piece of a selector name - (r'([$a-zA-Z_]\w+' + _ws + r':)', # function name - Name.Function), - - # smallest possible selector piece - (r'(:)', Name.Function), - - # var args - (r'(,' + _ws + r'\.\.\.)', using(this)), - - # param name - (r'([$a-zA-Z_]\w+)', Text), - ], - 'expression' : [ - (r'([$a-zA-Z_]\w*)(\()', bygroups(Name.Function, - Punctuation)), - (r'(\))', Punctuation, "#pop"), - ], - 'string': [ - (r'"', String, '#pop'), - (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), - (r'[^\\"\n]+', String), # all other characters - (r'\\\n', String), # line continuation - (r'\\', String), # stray backslash - ], - 'macro': [ - (r'[^/\n]+', Comment.Preproc), - (r'/[*](.|\n)*?[*]/', Comment.Multiline), - (r'//.*?\n', Comment.Single, '#pop'), - (r'/', Comment.Preproc), - (r'(?<=\\)\n', Comment.Preproc), - (r'\n', Comment.Preproc, '#pop'), - ], - 'if0': [ - (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'), - (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'), - (r'.*?\n', Comment), - ] - } - - def analyse_text(text): - if re.search('^\s*@import\s+[<"]', text, re.MULTILINE): - # special directive found in most Objective-J files - return True - return False - - -class HtmlLexer(RegexLexer): - """ - For HTML 4 and XHTML 1 markup. Nested JavaScript and CSS is highlighted - by the appropriate lexer. - """ - - name = 'HTML' - aliases = ['html'] - filenames = ['*.html', '*.htm', '*.xhtml', '*.xslt'] - mimetypes = ['text/html', 'application/xhtml+xml'] - - flags = re.IGNORECASE | re.DOTALL - tokens = { - 'root': [ - ('[^<&]+', Text), - (r'&\S*?;', Name.Entity), - (r'\<\!\[CDATA\[.*?\]\]\>', Comment.Preproc), - ('<!--', Comment, 'comment'), - (r'<\?.*?\?>', Comment.Preproc), - ('<![^>]*>', Comment.Preproc), - (r'<\s*script\s*', Name.Tag, ('script-content', 'tag')), - (r'<\s*style\s*', Name.Tag, ('style-content', 'tag')), - # note: this allows tag names not used in HTML like <x:with-dash>, - # this is to support yet-unknown template engines and the like - (r'<\s*[\w:.-]+', Name.Tag, 'tag'), - (r'<\s*/\s*[\w:.-]+\s*>', Name.Tag), - ], - 'comment': [ - ('[^-]+', Comment), - ('-->', Comment, '#pop'), - ('-', Comment), - ], - 'tag': [ - (r'\s+', Text), - (r'[\w:-]+\s*=', Name.Attribute, 'attr'), - (r'[\w:-]+', Name.Attribute), - (r'/?\s*>', Name.Tag, '#pop'), - ], - 'script-content': [ - (r'<\s*/\s*script\s*>', Name.Tag, '#pop'), - (r'.+?(?=<\s*/\s*script\s*>)', using(JavascriptLexer)), - ], - 'style-content': [ - (r'<\s*/\s*style\s*>', Name.Tag, '#pop'), - (r'.+?(?=<\s*/\s*style\s*>)', using(CssLexer)), - ], - 'attr': [ - ('".*?"', String, '#pop'), - ("'.*?'", String, '#pop'), - (r'[^\s>]+', String, '#pop'), - ], - } - - def analyse_text(text): - if html_doctype_matches(text): - return 0.5 - - -class PhpLexer(RegexLexer): - """ - For `PHP <http://www.php.net/>`_ source code. - For PHP embedded in HTML, use the `HtmlPhpLexer`. - - Additional options accepted: - - `startinline` - If given and ``True`` the lexer starts highlighting with - php code (i.e.: no starting ``<?php`` required). The default - is ``False``. - `funcnamehighlighting` - If given and ``True``, highlight builtin function names - (default: ``True``). - `disabledmodules` - If given, must be a list of module names whose function names - should not be highlighted. By default all modules are highlighted - except the special ``'unknown'`` module that includes functions - that are known to php but are undocumented. - - To get a list of allowed modules have a look into the - `_phpbuiltins` module: - - .. sourcecode:: pycon - - >>> from pygments.lexers._phpbuiltins import MODULES - >>> MODULES.keys() - ['PHP Options/Info', 'Zip', 'dba', ...] - - In fact the names of those modules match the module names from - the php documentation. - """ - - name = 'PHP' - aliases = ['php', 'php3', 'php4', 'php5'] - filenames = ['*.php', '*.php[345]', '*.inc'] - mimetypes = ['text/x-php'] - - # Note that a backslash is included in the following two patterns - # PHP uses a backslash as a namespace separator - _ident_char = r'[\\\w]|[^\x00-\x7f]' - _ident_begin = r'(?:[\\_a-z]|[^\x00-\x7f])' - _ident_end = r'(?:' + _ident_char + ')*' - _ident_inner = _ident_begin + _ident_end - - flags = re.IGNORECASE | re.DOTALL | re.MULTILINE - tokens = { - 'root': [ - (r'<\?(php)?', Comment.Preproc, 'php'), - (r'[^<]+', Other), - (r'<', Other) - ], - 'php': [ - (r'\?>', Comment.Preproc, '#pop'), - (r'<<<(\'?)(' + _ident_inner + ')\1\n.*?\n\2\;?\n', String), - (r'\s+', Text), - (r'#.*?\n', Comment.Single), - (r'//.*?\n', Comment.Single), - # put the empty comment here, it is otherwise seen as - # the start of a docstring - (r'/\*\*/', Comment.Multiline), - (r'/\*\*.*?\*/', String.Doc), - (r'/\*.*?\*/', Comment.Multiline), - (r'(->|::)(\s*)(' + _ident_inner + ')', - bygroups(Operator, Text, Name.Attribute)), - (r'[~!%^&*+=|:.<>/?@-]+', Operator), - (r'[\[\]{}();,]+', Punctuation), - (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), - (r'(function)(\s*)(?=\()', bygroups(Keyword, Text)), - (r'(function)(\s+)(&?)(\s*)', - bygroups(Keyword, Text, Operator, Text), 'functionname'), - (r'(const)(\s+)(' + _ident_inner + ')', - bygroups(Keyword, Text, Name.Constant)), - (r'(and|E_PARSE|old_function|E_ERROR|or|as|E_WARNING|parent|' - r'eval|PHP_OS|break|exit|case|extends|PHP_VERSION|cfunction|' - r'FALSE|print|for|require|continue|foreach|require_once|' - r'declare|return|default|static|do|switch|die|stdClass|' - r'echo|else|TRUE|elseif|var|empty|if|xor|enddeclare|include|' - r'virtual|endfor|include_once|while|endforeach|global|__FILE__|' - r'endif|list|__LINE__|endswitch|new|__sleep|endwhile|not|' - r'array|__wakeup|E_ALL|NULL|final|php_user_filter|interface|' - r'implements|public|private|protected|abstract|clone|try|' - r'catch|throw|this|use|namespace|trait|yield|' - r'finally)\b', Keyword), - (r'(true|false|null)\b', Keyword.Constant), - (r'\$\{\$+' + _ident_inner + '\}', Name.Variable), - (r'\$+' + _ident_inner, Name.Variable), - (_ident_inner, Name.Other), - (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float), - (r'\d+[eE][+-]?[0-9]+', Number.Float), - (r'0[0-7]+', Number.Oct), - (r'0[xX][a-f0-9]+', Number.Hex), - (r'\d+', Number.Integer), - (r'0b[01]+', Number.Bin), - (r"'([^'\\]*(?:\\.[^'\\]*)*)'", String.Single), - (r'`([^`\\]*(?:\\.[^`\\]*)*)`', String.Backtick), - (r'"', String.Double, 'string'), - ], - 'classname': [ - (_ident_inner, Name.Class, '#pop') - ], - 'functionname': [ - (_ident_inner, Name.Function, '#pop') - ], - 'string': [ - (r'"', String.Double, '#pop'), - (r'[^{$"\\]+', String.Double), - (r'\\([nrt\"$\\]|[0-7]{1,3}|x[0-9a-f]{1,2})', String.Escape), - (r'\$' + _ident_inner + '(\[\S+?\]|->' + _ident_inner + ')?', - String.Interpol), - (r'(\{\$\{)(.*?)(\}\})', - bygroups(String.Interpol, using(this, _startinline=True), - String.Interpol)), - (r'(\{)(\$.*?)(\})', - bygroups(String.Interpol, using(this, _startinline=True), - String.Interpol)), - (r'(\$\{)(\S+)(\})', - bygroups(String.Interpol, Name.Variable, String.Interpol)), - (r'[${\\]+', String.Double) - ], - } - - def __init__(self, **options): - self.funcnamehighlighting = get_bool_opt( - options, 'funcnamehighlighting', True) - self.disabledmodules = get_list_opt( - options, 'disabledmodules', ['unknown']) - self.startinline = get_bool_opt(options, 'startinline', False) - - # private option argument for the lexer itself - if '_startinline' in options: - self.startinline = options.pop('_startinline') - - # collect activated functions in a set - self._functions = set() - if self.funcnamehighlighting: - from pygments.lexers._phpbuiltins import MODULES - for key, value in iteritems(MODULES): - if key not in self.disabledmodules: - self._functions.update(value) - RegexLexer.__init__(self, **options) - - def get_tokens_unprocessed(self, text): - stack = ['root'] - if self.startinline: - stack.append('php') - for index, token, value in \ - RegexLexer.get_tokens_unprocessed(self, text, stack): - if token is Name.Other: - if value in self._functions: - yield index, Name.Builtin, value - continue - yield index, token, value - - def analyse_text(text): - rv = 0.0 - if re.search(r'<\?(?!xml)', text): - rv += 0.3 - if '?>' in text: - rv += 0.1 - return rv - - -class DtdLexer(RegexLexer): - """ - A lexer for DTDs (Document Type Definitions). - - .. versionadded:: 1.5 - """ - - 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). - """ - - flags = re.MULTILINE | re.DOTALL | re.UNICODE - - name = 'XML' - aliases = ['xml'] - filenames = ['*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', - '*.wsdl', '*.wsf'] - mimetypes = ['text/xml', 'application/xml', 'image/svg+xml', - 'application/rss+xml', 'application/atom+xml'] - - tokens = { - 'root': [ - ('[^<&]+', Text), - (r'&\S*?;', Name.Entity), - (r'\<\!\[CDATA\[.*?\]\]\>', Comment.Preproc), - ('<!--', Comment, 'comment'), - (r'<\?.*?\?>', Comment.Preproc), - ('<![^>]*>', Comment.Preproc), - (r'<\s*[\w:.-]+', Name.Tag, 'tag'), - (r'<\s*/\s*[\w:.-]+\s*>', Name.Tag), - ], - 'comment': [ - ('[^-]+', Comment), - ('-->', Comment, '#pop'), - ('-', Comment), - ], - 'tag': [ - (r'\s+', Text), - (r'[\w.:-]+\s*=', Name.Attribute, 'attr'), - (r'/?\s*>', Name.Tag, '#pop'), - ], - 'attr': [ - ('\s+', Text), - ('".*?"', String, '#pop'), - ("'.*?'", String, '#pop'), - (r'[^\s>]+', String, '#pop'), - ], - } - - def analyse_text(text): - if looks_like_xml(text): - return 0.5 - - -class XsltLexer(XmlLexer): - ''' - A lexer for XSLT. - - .. versionadded:: 0.10 - ''' - - name = 'XSLT' - aliases = ['xslt'] - filenames = ['*.xsl', '*.xslt', '*.xpl'] # xpl is XProc - mimetypes = ['application/xsl+xml', 'application/xslt+xml'] - - EXTRA_KEYWORDS = set([ - 'apply-imports', 'apply-templates', 'attribute', - 'attribute-set', 'call-template', 'choose', 'comment', - 'copy', 'copy-of', 'decimal-format', 'element', 'fallback', - 'for-each', 'if', 'import', 'include', 'key', 'message', - 'namespace-alias', 'number', 'otherwise', 'output', 'param', - 'preserve-space', 'processing-instruction', 'sort', - 'strip-space', 'stylesheet', 'template', 'text', 'transform', - 'value-of', 'variable', 'when', 'with-param' - ]) - - def get_tokens_unprocessed(self, text): - for index, token, value in XmlLexer.get_tokens_unprocessed(self, text): - m = re.match('</?xsl:([^>]*)/?>?', value) - - if token is Name.Tag and m and m.group(1) in self.EXTRA_KEYWORDS: - yield index, Keyword, value - else: - yield index, token, value - - def analyse_text(text): - if looks_like_xml(text) and '<xsl' in text: - return 0.8 - - -class MxmlLexer(RegexLexer): - """ - For MXML markup. - Nested AS3 in <script> tags is highlighted by the appropriate lexer. - - .. versionadded:: 1.1 - """ - flags = re.MULTILINE | re.DOTALL - name = 'MXML' - aliases = ['mxml'] - filenames = ['*.mxml'] - mimetimes = ['text/xml', 'application/xml'] - - tokens = { - 'root': [ - ('[^<&]+', Text), - (r'&\S*?;', Name.Entity), - (r'(\<\!\[CDATA\[)(.*?)(\]\]\>)', - bygroups(String, using(ActionScript3Lexer), String)), - ('<!--', Comment, 'comment'), - (r'<\?.*?\?>', Comment.Preproc), - ('<![^>]*>', Comment.Preproc), - (r'<\s*[\w:.-]+', Name.Tag, 'tag'), - (r'<\s*/\s*[\w:.-]+\s*>', Name.Tag), - ], - 'comment': [ - ('[^-]+', Comment), - ('-->', Comment, '#pop'), - ('-', Comment), - ], - 'tag': [ - (r'\s+', Text), - (r'[\w.:-]+\s*=', Name.Attribute, 'attr'), - (r'/?\s*>', Name.Tag, '#pop'), - ], - 'attr': [ - ('\s+', Text), - ('".*?"', String, '#pop'), - ("'.*?'", String, '#pop'), - (r'[^\s>]+', String, '#pop'), - ], - } - - -class HaxeLexer(ExtendedRegexLexer): - """ - For Haxe source code (http://haxe.org/). - - .. versionadded:: 1.3 - """ - - name = 'Haxe' - aliases = ['hx', 'haxe', 'hxsl'] - filenames = ['*.hx', '*.hxsl'] - mimetypes = ['text/haxe', 'text/x-haxe', 'text/x-hx'] - - # keywords extracted from lexer.mll in the haxe compiler source - keyword = (r'(?:function|class|static|var|if|else|while|do|for|' - r'break|return|continue|extends|implements|import|' - r'switch|case|default|public|private|try|untyped|' - r'catch|new|this|throw|extern|enum|in|interface|' - r'cast|override|dynamic|typedef|package|' - r'inline|using|null|true|false|abstract)\b') - - # idtype in lexer.mll - typeid = r'_*[A-Z]\w*' - - # combined ident and dollar and idtype - ident = r'(?:_*[a-z]\w*|_+[0-9]\w*|' + typeid + '|_+|\$\w+)' - - binop = (r'(?:%=|&=|\|=|\^=|\+=|\-=|\*=|/=|<<=|>\s*>\s*=|>\s*>\s*>\s*=|==|' - r'!=|<=|>\s*=|&&|\|\||<<|>>>|>\s*>|\.\.\.|<|>|%|&|\||\^|\+|\*|' - r'/|\-|=>|=)') - - # ident except keywords - ident_no_keyword = r'(?!' + keyword + ')' + ident - - flags = re.DOTALL | re.MULTILINE - - preproc_stack = [] - - def preproc_callback(self, match, ctx): - proc = match.group(2) - - if proc == 'if': - # store the current stack - self.preproc_stack.append(ctx.stack[:]) - elif proc in ['else', 'elseif']: - # restore the stack back to right before #if - if self.preproc_stack: ctx.stack = self.preproc_stack[-1][:] - elif proc == 'end': - # remove the saved stack of previous #if - if self.preproc_stack: self.preproc_stack.pop() - - # #if and #elseif should follow by an expr - if proc in ['if', 'elseif']: - ctx.stack.append('preproc-expr') - - # #error can be optionally follow by the error msg - if proc in ['error']: - ctx.stack.append('preproc-error') - - yield match.start(), Comment.Preproc, '#' + proc - ctx.pos = match.end() - - - tokens = { - 'root': [ - include('spaces'), - include('meta'), - (r'(?:package)\b', Keyword.Namespace, ('semicolon', 'package')), - (r'(?:import)\b', Keyword.Namespace, ('semicolon', 'import')), - (r'(?:using)\b', Keyword.Namespace, ('semicolon', 'using')), - (r'(?:extern|private)\b', Keyword.Declaration), - (r'(?:abstract)\b', Keyword.Declaration, 'abstract'), - (r'(?:class|interface)\b', Keyword.Declaration, 'class'), - (r'(?:enum)\b', Keyword.Declaration, 'enum'), - (r'(?:typedef)\b', Keyword.Declaration, 'typedef'), - - # top-level expression - # although it is not supported in haxe, but it is common to write - # expression in web pages the positive lookahead here is to prevent - # an infinite loop at the EOF - (r'(?=.)', Text, 'expr-statement'), - ], - - # space/tab/comment/preproc - 'spaces': [ - (r'\s+', Text), - (r'//[^\n\r]*', Comment.Single), - (r'/\*.*?\*/', Comment.Multiline), - (r'(#)(if|elseif|else|end|error)\b', preproc_callback), - ], - - 'string-single-interpol': [ - (r'\$\{', String.Interpol, ('string-interpol-close', 'expr')), - (r'\$\$', String.Escape), - (r'\$(?=' + ident + ')', String.Interpol, 'ident'), - include('string-single'), - ], - - 'string-single': [ - (r"'", String.Single, '#pop'), - (r'\\.', String.Escape), - (r'.', String.Single), - ], - - 'string-double': [ - (r'"', String.Double, '#pop'), - (r'\\.', String.Escape), - (r'.', String.Double), - ], - - 'string-interpol-close': [ - (r'\$'+ident, String.Interpol), - (r'\}', String.Interpol, '#pop'), - ], - - 'package': [ - include('spaces'), - (ident, Name.Namespace), - (r'\.', Punctuation, 'import-ident'), - default('#pop'), - ], - - 'import': [ - include('spaces'), - (ident, Name.Namespace), - (r'\*', Keyword), # wildcard import - (r'\.', Punctuation, 'import-ident'), - (r'in', Keyword.Namespace, 'ident'), - default('#pop'), - ], - - 'import-ident': [ - include('spaces'), - (r'\*', Keyword, '#pop'), # wildcard import - (ident, Name.Namespace, '#pop'), - ], - - 'using': [ - include('spaces'), - (ident, Name.Namespace), - (r'\.', Punctuation, 'import-ident'), - default('#pop'), - ], - - 'preproc-error': [ - (r'\s+', Comment.Preproc), - (r"'", String.Single, ('#pop', 'string-single')), - (r'"', String.Double, ('#pop', 'string-double')), - default('#pop'), - ], - - 'preproc-expr': [ - (r'\s+', Comment.Preproc), - (r'\!', Comment.Preproc), - (r'\(', Comment.Preproc, ('#pop', 'preproc-parenthesis')), - - (ident, Comment.Preproc, '#pop'), - - # Float - (r'\.[0-9]+', Number.Float), - (r'[0-9]+[eE][\+\-]?[0-9]+', Number.Float), - (r'[0-9]+\.[0-9]*[eE][\+\-]?[0-9]+', Number.Float), - (r'[0-9]+\.[0-9]+', Number.Float), - (r'[0-9]+\.(?!' + ident + '|\.\.)', Number.Float), - - # Int - (r'0x[0-9a-fA-F]+', Number.Hex), - (r'[0-9]+', Number.Integer), - - # String - (r"'", String.Single, ('#pop', 'string-single')), - (r'"', String.Double, ('#pop', 'string-double')), - ], - - 'preproc-parenthesis': [ - (r'\s+', Comment.Preproc), - (r'\)', Comment.Preproc, '#pop'), - ('', Text, 'preproc-expr-in-parenthesis'), - ], - - 'preproc-expr-chain': [ - (r'\s+', Comment.Preproc), - (binop, Comment.Preproc, ('#pop', 'preproc-expr-in-parenthesis')), - default('#pop'), - ], - - # same as 'preproc-expr' but able to chain 'preproc-expr-chain' - 'preproc-expr-in-parenthesis': [ - (r'\s+', Comment.Preproc), - (r'\!', Comment.Preproc), - (r'\(', Comment.Preproc, - ('#pop', 'preproc-expr-chain', 'preproc-parenthesis')), - - (ident, Comment.Preproc, ('#pop', 'preproc-expr-chain')), - - # Float - (r'\.[0-9]+', Number.Float, ('#pop', 'preproc-expr-chain')), - (r'[0-9]+[eE][\+\-]?[0-9]+', Number.Float, ('#pop', 'preproc-expr-chain')), - (r'[0-9]+\.[0-9]*[eE][\+\-]?[0-9]+', Number.Float, ('#pop', 'preproc-expr-chain')), - (r'[0-9]+\.[0-9]+', Number.Float, ('#pop', 'preproc-expr-chain')), - (r'[0-9]+\.(?!' + ident + '|\.\.)', Number.Float, ('#pop', 'preproc-expr-chain')), - - # Int - (r'0x[0-9a-fA-F]+', Number.Hex, ('#pop', 'preproc-expr-chain')), - (r'[0-9]+', Number.Integer, ('#pop', 'preproc-expr-chain')), - - # String - (r"'", String.Single, - ('#pop', 'preproc-expr-chain', 'string-single')), - (r'"', String.Double, - ('#pop', 'preproc-expr-chain', 'string-double')), - ], - - 'abstract' : [ - include('spaces'), - default(('#pop', 'abstract-body', 'abstract-relation', - 'abstract-opaque', 'type-param-constraint', 'type-name')), - ], - - 'abstract-body' : [ - include('spaces'), - (r'\{', Punctuation, ('#pop', 'class-body')), - ], - - 'abstract-opaque' : [ - include('spaces'), - (r'\(', Punctuation, ('#pop', 'parenthesis-close', 'type')), - default('#pop'), - ], - - 'abstract-relation': [ - include('spaces'), - (r'(?:to|from)', Keyword.Declaration, 'type'), - (r',', Punctuation), - default('#pop'), - ], - - 'meta': [ - include('spaces'), - (r'@', Name.Decorator, ('meta-body', 'meta-ident', 'meta-colon')), - ], - - # optional colon - 'meta-colon': [ - include('spaces'), - (r':', Name.Decorator, '#pop'), - default('#pop'), - ], - - # same as 'ident' but set token as Name.Decorator instead of Name - 'meta-ident': [ - include('spaces'), - (ident, Name.Decorator, '#pop'), - ], - - 'meta-body': [ - include('spaces'), - (r'\(', Name.Decorator, ('#pop', 'meta-call')), - default('#pop'), - ], - - 'meta-call': [ - include('spaces'), - (r'\)', Name.Decorator, '#pop'), - default(('#pop', 'meta-call-sep', 'expr')), - ], - - 'meta-call-sep': [ - include('spaces'), - (r'\)', Name.Decorator, '#pop'), - (r',', Punctuation, ('#pop', 'meta-call')), - ], - - 'typedef': [ - include('spaces'), - default(('#pop', 'typedef-body', 'type-param-constraint', - 'type-name')), - ], - - 'typedef-body': [ - include('spaces'), - (r'=', Operator, ('#pop', 'optional-semicolon', 'type')), - ], - - 'enum': [ - include('spaces'), - default(('#pop', 'enum-body', 'bracket-open', - 'type-param-constraint', 'type-name')), - ], - - 'enum-body': [ - include('spaces'), - include('meta'), - (r'\}', Punctuation, '#pop'), - (ident_no_keyword, Name, ('enum-member', 'type-param-constraint')), - ], - - 'enum-member': [ - include('spaces'), - (r'\(', Punctuation, - ('#pop', 'semicolon', 'flag', 'function-param')), - default(('#pop', 'semicolon', 'flag')), - ], - - 'class': [ - include('spaces'), - default(('#pop', 'class-body', 'bracket-open', 'extends', - 'type-param-constraint', 'type-name')), - ], - - 'extends': [ - include('spaces'), - (r'(?:extends|implements)\b', Keyword.Declaration, 'type'), - (r',', Punctuation), # the comma is made optional here, since haxe2 - # requires the comma but haxe3 does not allow it - default('#pop'), - ], - - 'bracket-open': [ - include('spaces'), - (r'\{', Punctuation, '#pop'), - ], - - 'bracket-close': [ - include('spaces'), - (r'\}', Punctuation, '#pop'), - ], - - 'class-body': [ - include('spaces'), - include('meta'), - (r'\}', Punctuation, '#pop'), - (r'(?:static|public|private|override|dynamic|inline|macro)\b', - Keyword.Declaration), - default('class-member'), - ], - - 'class-member': [ - include('spaces'), - (r'(var)\b', Keyword.Declaration, - ('#pop', 'optional-semicolon', 'var')), - (r'(function)\b', Keyword.Declaration, - ('#pop', 'optional-semicolon', 'class-method')), - ], - - # local function, anonymous or not - 'function-local': [ - include('spaces'), - (r'(' + ident_no_keyword + ')?', Name.Function, - ('#pop', 'optional-expr', 'flag', 'function-param', - 'parenthesis-open', 'type-param-constraint')), - ], - - 'optional-expr': [ - include('spaces'), - include('expr'), - default('#pop'), - ], - - 'class-method': [ - include('spaces'), - (ident, Name.Function, ('#pop', 'optional-expr', 'flag', - 'function-param', 'parenthesis-open', - 'type-param-constraint')), - ], - - # function arguments - 'function-param': [ - include('spaces'), - (r'\)', Punctuation, '#pop'), - (r'\?', Punctuation), - (ident_no_keyword, Name, - ('#pop', 'function-param-sep', 'assign', 'flag')), - ], - - 'function-param-sep': [ - include('spaces'), - (r'\)', Punctuation, '#pop'), - (r',', Punctuation, ('#pop', 'function-param')), - ], - - 'prop-get-set': [ - include('spaces'), - (r'\(', Punctuation, ('#pop', 'parenthesis-close', - 'prop-get-set-opt', 'comma', 'prop-get-set-opt')), - default('#pop'), - ], - - 'prop-get-set-opt': [ - include('spaces'), - (r'(?:default|null|never|dynamic|get|set)\b', Keyword, '#pop'), - (ident_no_keyword, Text, '#pop'), #custom getter/setter - ], - - 'expr-statement': [ - include('spaces'), - # makes semicolon optional here, just to avoid checking the last - # one is bracket or not. - default(('#pop', 'optional-semicolon', 'expr')), - ], - - 'expr': [ - include('spaces'), - (r'@', Name.Decorator, ('#pop', 'optional-expr', 'meta-body', - 'meta-ident', 'meta-colon')), - (r'(?:\+\+|\-\-|~(?!/)|!|\-)', Operator), - (r'\(', Punctuation, ('#pop', 'expr-chain', 'parenthesis')), - (r'(?:static|public|private|override|dynamic|inline)\b', - Keyword.Declaration), - (r'(?:function)\b', Keyword.Declaration, ('#pop', 'expr-chain', - 'function-local')), - (r'\{', Punctuation, ('#pop', 'expr-chain', 'bracket')), - (r'(?:true|false|null)\b', Keyword.Constant, ('#pop', 'expr-chain')), - (r'(?:this)\b', Keyword, ('#pop', 'expr-chain')), - (r'(?:cast)\b', Keyword, ('#pop', 'expr-chain', 'cast')), - (r'(?:try)\b', Keyword, ('#pop', 'catch', 'expr')), - (r'(?:var)\b', Keyword.Declaration, ('#pop', 'var')), - (r'(?:new)\b', Keyword, ('#pop', 'expr-chain', 'new')), - (r'(?:switch)\b', Keyword, ('#pop', 'switch')), - (r'(?:if)\b', Keyword, ('#pop', 'if')), - (r'(?:do)\b', Keyword, ('#pop', 'do')), - (r'(?:while)\b', Keyword, ('#pop', 'while')), - (r'(?:for)\b', Keyword, ('#pop', 'for')), - (r'(?:untyped|throw)\b', Keyword), - (r'(?:return)\b', Keyword, ('#pop', 'optional-expr')), - (r'(?:macro)\b', Keyword, ('#pop', 'macro')), - (r'(?:continue|break)\b', Keyword, '#pop'), - (r'(?:\$\s*[a-z]\b|\$(?!'+ident+'))', Name, ('#pop', 'dollar')), - (ident_no_keyword, Name, ('#pop', 'expr-chain')), - - # Float - (r'\.[0-9]+', Number.Float, ('#pop', 'expr-chain')), - (r'[0-9]+[eE][\+\-]?[0-9]+', Number.Float, ('#pop', 'expr-chain')), - (r'[0-9]+\.[0-9]*[eE][\+\-]?[0-9]+', Number.Float, ('#pop', 'expr-chain')), - (r'[0-9]+\.[0-9]+', Number.Float, ('#pop', 'expr-chain')), - (r'[0-9]+\.(?!' + ident + '|\.\.)', Number.Float, ('#pop', 'expr-chain')), - - # Int - (r'0x[0-9a-fA-F]+', Number.Hex, ('#pop', 'expr-chain')), - (r'[0-9]+', Number.Integer, ('#pop', 'expr-chain')), - - # String - (r"'", String.Single, ('#pop', 'expr-chain', 'string-single-interpol')), - (r'"', String.Double, ('#pop', 'expr-chain', 'string-double')), - - # EReg - (r'~/(\\\\|\\/|[^/\n])*/[gimsu]*', String.Regex, ('#pop', 'expr-chain')), - - # Array - (r'\[', Punctuation, ('#pop', 'expr-chain', 'array-decl')), - ], - - 'expr-chain': [ - include('spaces'), - (r'(?:\+\+|\-\-)', Operator), - (binop, Operator, ('#pop', 'expr')), - (r'(?:in)\b', Keyword, ('#pop', 'expr')), - (r'\?', Operator, ('#pop', 'expr', 'ternary', 'expr')), - (r'(\.)(' + ident_no_keyword + ')', bygroups(Punctuation, Name)), - (r'\[', Punctuation, 'array-access'), - (r'\(', Punctuation, 'call'), - default('#pop'), - ], - - # macro reification - 'macro': [ - include('spaces'), - include('meta'), - (r':', Punctuation, ('#pop', 'type')), - - (r'(?:extern|private)\b', Keyword.Declaration), - (r'(?:abstract)\b', Keyword.Declaration, ('#pop', 'optional-semicolon', 'abstract')), - (r'(?:class|interface)\b', Keyword.Declaration, ('#pop', 'optional-semicolon', 'macro-class')), - (r'(?:enum)\b', Keyword.Declaration, ('#pop', 'optional-semicolon', 'enum')), - (r'(?:typedef)\b', Keyword.Declaration, ('#pop', 'optional-semicolon', 'typedef')), - - default(('#pop', 'expr')), - ], - - 'macro-class': [ - (r'\{', Punctuation, ('#pop', 'class-body')), - include('class') - ], - - # cast can be written as "cast expr" or "cast(expr, type)" - 'cast': [ - include('spaces'), - (r'\(', Punctuation, ('#pop', 'parenthesis-close', - 'cast-type', 'expr')), - default(('#pop', 'expr')), - ], - - # optionally give a type as the 2nd argument of cast() - 'cast-type': [ - include('spaces'), - (r',', Punctuation, ('#pop', 'type')), - default('#pop'), - ], - - 'catch': [ - include('spaces'), - (r'(?:catch)\b', Keyword, ('expr', 'function-param', - 'parenthesis-open')), - default('#pop'), - ], - - # do-while loop - 'do': [ - include('spaces'), - default(('#pop', 'do-while', 'expr')), - ], - - # the while after do - 'do-while': [ - include('spaces'), - (r'(?:while)\b', Keyword, ('#pop', 'parenthesis', - 'parenthesis-open')), - ], - - 'while': [ - include('spaces'), - (r'\(', Punctuation, ('#pop', 'expr', 'parenthesis')), - ], - - 'for': [ - include('spaces'), - (r'\(', Punctuation, ('#pop', 'expr', 'parenthesis')), - ], - - 'if': [ - include('spaces'), - (r'\(', Punctuation, ('#pop', 'else', 'optional-semicolon', 'expr', - 'parenthesis')), - ], - - 'else': [ - include('spaces'), - (r'(?:else)\b', Keyword, ('#pop', 'expr')), - default('#pop'), - ], - - 'switch': [ - include('spaces'), - default(('#pop', 'switch-body', 'bracket-open', 'expr')), - ], - - 'switch-body': [ - include('spaces'), - (r'(?:case|default)\b', Keyword, ('case-block', 'case')), - (r'\}', Punctuation, '#pop'), - ], - - 'case': [ - include('spaces'), - (r':', Punctuation, '#pop'), - default(('#pop', 'case-sep', 'case-guard', 'expr')), - ], - - 'case-sep': [ - include('spaces'), - (r':', Punctuation, '#pop'), - (r',', Punctuation, ('#pop', 'case')), - ], - - 'case-guard': [ - include('spaces'), - (r'(?:if)\b', Keyword, ('#pop', 'parenthesis', 'parenthesis-open')), - default('#pop'), - ], - - # optional multiple expr under a case - 'case-block': [ - include('spaces'), - (r'(?!(?:case|default)\b|\})', Keyword, 'expr-statement'), - default('#pop'), - ], - - 'new': [ - include('spaces'), - default(('#pop', 'call', 'parenthesis-open', 'type')), - ], - - 'array-decl': [ - include('spaces'), - (r'\]', Punctuation, '#pop'), - default(('#pop', 'array-decl-sep', 'expr')), - ], - - 'array-decl-sep': [ - include('spaces'), - (r'\]', Punctuation, '#pop'), - (r',', Punctuation, ('#pop', 'array-decl')), - ], - - 'array-access': [ - include('spaces'), - default(('#pop', 'array-access-close', 'expr')), - ], - - 'array-access-close': [ - include('spaces'), - (r'\]', Punctuation, '#pop'), - ], - - 'comma': [ - include('spaces'), - (r',', Punctuation, '#pop'), - ], - - 'colon': [ - include('spaces'), - (r':', Punctuation, '#pop'), - ], - - 'semicolon': [ - include('spaces'), - (r';', Punctuation, '#pop'), - ], - - 'optional-semicolon': [ - include('spaces'), - (r';', Punctuation, '#pop'), - default('#pop'), - ], - - # identity that CAN be a Haxe keyword - 'ident': [ - include('spaces'), - (ident, Name, '#pop'), - ], - - 'dollar': [ - include('spaces'), - (r'\{', Punctuation, ('#pop', 'expr-chain', 'bracket-close', 'expr')), - default(('#pop', 'expr-chain')), - ], - - 'type-name': [ - include('spaces'), - (typeid, Name, '#pop'), - ], - - 'type-full-name': [ - include('spaces'), - (r'\.', Punctuation, 'ident'), - default('#pop'), - ], - - 'type': [ - include('spaces'), - (r'\?', Punctuation), - (ident, Name, ('#pop', 'type-check', 'type-full-name')), - (r'\{', Punctuation, ('#pop', 'type-check', 'type-struct')), - (r'\(', Punctuation, ('#pop', 'type-check', 'type-parenthesis')), - ], - - 'type-parenthesis': [ - include('spaces'), - default(('#pop', 'parenthesis-close', 'type')), - ], - - 'type-check': [ - include('spaces'), - (r'->', Punctuation, ('#pop', 'type')), - (r'<(?!=)', Punctuation, 'type-param'), - default('#pop'), - ], - - 'type-struct': [ - include('spaces'), - (r'\}', Punctuation, '#pop'), - (r'\?', Punctuation), - (r'>', Punctuation, ('comma', 'type')), - (ident_no_keyword, Name, ('#pop', 'type-struct-sep', 'type', 'colon')), - include('class-body'), - ], - - 'type-struct-sep': [ - include('spaces'), - (r'\}', Punctuation, '#pop'), - (r',', Punctuation, ('#pop', 'type-struct')), - ], - - # type-param can be a normal type or a constant literal... - 'type-param-type': [ - # Float - (r'\.[0-9]+', Number.Float, '#pop'), - (r'[0-9]+[eE][\+\-]?[0-9]+', Number.Float, '#pop'), - (r'[0-9]+\.[0-9]*[eE][\+\-]?[0-9]+', Number.Float, '#pop'), - (r'[0-9]+\.[0-9]+', Number.Float, '#pop'), - (r'[0-9]+\.(?!' + ident + '|\.\.)', Number.Float, '#pop'), - - # Int - (r'0x[0-9a-fA-F]+', Number.Hex, '#pop'), - (r'[0-9]+', Number.Integer, '#pop'), - - # String - (r"'", String.Single, ('#pop', 'string-single')), - (r'"', String.Double, ('#pop', 'string-double')), - - # EReg - (r'~/(\\\\|\\/|[^/\n])*/[gim]*', String.Regex, '#pop'), - - # Array - (r'\[', Operator, ('#pop', 'array-decl')), - - include('type'), - ], - - # type-param part of a type - # ie. the <A,B> path in Map<A,B> - 'type-param': [ - include('spaces'), - default(('#pop', 'type-param-sep', 'type-param-type')), - ], - - 'type-param-sep': [ - include('spaces'), - (r'>', Punctuation, '#pop'), - (r',', Punctuation, ('#pop', 'type-param')), - ], - - # optional type-param that may include constraint - # ie. <T:Constraint, T2:(ConstraintA,ConstraintB)> - 'type-param-constraint': [ - include('spaces'), - (r'<(?!=)', Punctuation, ('#pop', 'type-param-constraint-sep', - 'type-param-constraint-flag', 'type-name')), - default('#pop'), - ], - - 'type-param-constraint-sep': [ - include('spaces'), - (r'>', Punctuation, '#pop'), - (r',', Punctuation, ('#pop', 'type-param-constraint-sep', - 'type-param-constraint-flag', 'type-name')), - ], - - # the optional constraint inside type-param - 'type-param-constraint-flag': [ - include('spaces'), - (r':', Punctuation, ('#pop', 'type-param-constraint-flag-type')), - default('#pop'), - ], - - 'type-param-constraint-flag-type': [ - include('spaces'), - (r'\(', Punctuation, ('#pop', 'type-param-constraint-flag-type-sep', - 'type')), - default(('#pop', 'type')), - ], - - 'type-param-constraint-flag-type-sep': [ - include('spaces'), - (r'\)', Punctuation, '#pop'), - (r',', Punctuation, 'type'), - ], - - # a parenthesis expr that contain exactly one expr - 'parenthesis': [ - include('spaces'), - default(('#pop', 'parenthesis-close', 'flag', 'expr')), - ], - - 'parenthesis-open': [ - include('spaces'), - (r'\(', Punctuation, '#pop'), - ], - - 'parenthesis-close': [ - include('spaces'), - (r'\)', Punctuation, '#pop'), - ], - - 'var': [ - include('spaces'), - (ident_no_keyword, Text, ('#pop', 'var-sep', 'assign', 'flag', 'prop-get-set')), - ], - - # optional more var decl. - 'var-sep': [ - include('spaces'), - (r',', Punctuation, ('#pop', 'var')), - default('#pop'), - ], - - # optional assignment - 'assign': [ - include('spaces'), - (r'=', Operator, ('#pop', 'expr')), - default('#pop'), - ], - - # optional type flag - 'flag': [ - include('spaces'), - (r':', Punctuation, ('#pop', 'type')), - default('#pop'), - ], - - # colon as part of a ternary operator (?:) - 'ternary': [ - include('spaces'), - (r':', Operator, '#pop'), - ], - - # function call - 'call': [ - include('spaces'), - (r'\)', Punctuation, '#pop'), - default(('#pop', 'call-sep', 'expr')), - ], - - # after a call param - 'call-sep': [ - include('spaces'), - (r'\)', Punctuation, '#pop'), - (r',', Punctuation, ('#pop', 'call')), - ], - - # bracket can be block or object - 'bracket': [ - include('spaces'), - (r'(?!(?:\$\s*[a-z]\b|\$(?!'+ident+')))' + ident_no_keyword, Name, - ('#pop', 'bracket-check')), - (r"'", String.Single, ('#pop', 'bracket-check', 'string-single')), - (r'"', String.Double, ('#pop', 'bracket-check', 'string-double')), - default(('#pop', 'block')), - ], - - 'bracket-check': [ - include('spaces'), - (r':', Punctuation, ('#pop', 'object-sep', 'expr')), #is object - default(('#pop', 'block', 'optional-semicolon', 'expr-chain')), #is block - ], - - # code block - 'block': [ - include('spaces'), - (r'\}', Punctuation, '#pop'), - default('expr-statement'), - ], - - # object in key-value pairs - 'object': [ - include('spaces'), - (r'\}', Punctuation, '#pop'), - default(('#pop', 'object-sep', 'expr', 'colon', 'ident-or-string')) - ], - - # a key of an object - 'ident-or-string': [ - include('spaces'), - (ident_no_keyword, Name, '#pop'), - (r"'", String.Single, ('#pop', 'string-single')), - (r'"', String.Double, ('#pop', 'string-double')), - ], - - # after a key-value pair in object - 'object-sep': [ - include('spaces'), - (r'\}', Punctuation, '#pop'), - (r',', Punctuation, ('#pop', 'object')), - ], - - - - } - - def analyse_text(text): - if re.match(r'\w+\s*:\s*\w', text): return 0.3 - - -def _indentation(lexer, match, ctx): - indentation = match.group(0) - yield match.start(), Text, indentation - ctx.last_indentation = indentation - ctx.pos = match.end() - - if hasattr(ctx, 'block_state') and ctx.block_state and \ - indentation.startswith(ctx.block_indentation) and \ - indentation != ctx.block_indentation: - ctx.stack.append(ctx.block_state) - else: - ctx.block_state = None - ctx.block_indentation = None - ctx.stack.append('content') - -def _starts_block(token, state): - def callback(lexer, match, ctx): - yield match.start(), token, match.group(0) - - if hasattr(ctx, 'last_indentation'): - ctx.block_indentation = ctx.last_indentation - else: - ctx.block_indentation = '' - - ctx.block_state = state - ctx.pos = match.end() - - return callback - - -class HamlLexer(ExtendedRegexLexer): - """ - For Haml markup. - - .. versionadded:: 1.3 - """ - - name = 'Haml' - aliases = ['haml'] - filenames = ['*.haml'] - mimetypes = ['text/x-haml'] - - flags = re.IGNORECASE - # Haml can include " |\n" anywhere, - # which is ignored and used to wrap long lines. - # To accomodate this, use this custom faux dot instead. - _dot = r'(?: \|\n(?=.* \|)|.)' - - # In certain places, a comma at the end of the line - # allows line wrapping as well. - _comma_dot = r'(?:,\s*\n|' + _dot + ')' - tokens = { - 'root': [ - (r'[ \t]*\n', Text), - (r'[ \t]*', _indentation), - ], - - 'css': [ - (r'\.[\w:-]+', Name.Class, 'tag'), - (r'\#[\w:-]+', Name.Function, 'tag'), - ], - - 'eval-or-plain': [ - (r'[&!]?==', Punctuation, 'plain'), - (r'([&!]?[=~])(' + _comma_dot + r'*\n)', - bygroups(Punctuation, using(RubyLexer)), - 'root'), - default('plain'), - ], - - 'content': [ - include('css'), - (r'%[\w:-]+', Name.Tag, 'tag'), - (r'!!!' + _dot + r'*\n', Name.Namespace, '#pop'), - (r'(/)(\[' + _dot + '*?\])(' + _dot + r'*\n)', - bygroups(Comment, Comment.Special, Comment), - '#pop'), - (r'/' + _dot + r'*\n', _starts_block(Comment, 'html-comment-block'), - '#pop'), - (r'-#' + _dot + r'*\n', _starts_block(Comment.Preproc, - 'haml-comment-block'), '#pop'), - (r'(-)(' + _comma_dot + r'*\n)', - bygroups(Punctuation, using(RubyLexer)), - '#pop'), - (r':' + _dot + r'*\n', _starts_block(Name.Decorator, 'filter-block'), - '#pop'), - include('eval-or-plain'), - ], - - 'tag': [ - include('css'), - (r'\{(,\n|' + _dot + ')*?\}', using(RubyLexer)), - (r'\[' + _dot + '*?\]', using(RubyLexer)), - (r'\(', Text, 'html-attributes'), - (r'/[ \t]*\n', Punctuation, '#pop:2'), - (r'[<>]{1,2}(?=[ \t=])', Punctuation), - include('eval-or-plain'), - ], - - 'plain': [ - (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text), - (r'(#\{)(' + _dot + '*?)(\})', - bygroups(String.Interpol, using(RubyLexer), String.Interpol)), - (r'\n', Text, 'root'), - ], - - 'html-attributes': [ - (r'\s+', Text), - (r'[\w:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'), - (r'[\w:-]+', Name.Attribute), - (r'\)', Text, '#pop'), - ], - - 'html-attribute-value': [ - (r'[ \t]+', Text), - (r'\w+', Name.Variable, '#pop'), - (r'@\w+', Name.Variable.Instance, '#pop'), - (r'\$\w+', Name.Variable.Global, '#pop'), - (r"'(\\\\|\\'|[^'\n])*'", String, '#pop'), - (r'"(\\\\|\\"|[^"\n])*"', String, '#pop'), - ], - - 'html-comment-block': [ - (_dot + '+', Comment), - (r'\n', Text, 'root'), - ], - - 'haml-comment-block': [ - (_dot + '+', Comment.Preproc), - (r'\n', Text, 'root'), - ], - - 'filter-block': [ - (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator), - (r'(#\{)(' + _dot + '*?)(\})', - bygroups(String.Interpol, using(RubyLexer), String.Interpol)), - (r'\n', Text, 'root'), - ], - } - - -common_sass_tokens = { - 'value': [ - (r'[ \t]+', Text), - (r'[!$][\w-]+', Name.Variable), - (r'url\(', String.Other, 'string-url'), - (r'[a-z_-][\w-]*(?=\()', Name.Function), - (r'(azimuth|background-attachment|background-color|' - r'background-image|background-position|background-repeat|' - r'background|border-bottom-color|border-bottom-style|' - r'border-bottom-width|border-left-color|border-left-style|' - r'border-left-width|border-right|border-right-color|' - r'border-right-style|border-right-width|border-top-color|' - r'border-top-style|border-top-width|border-bottom|' - r'border-collapse|border-left|border-width|border-color|' - r'border-spacing|border-style|border-top|border|caption-side|' - r'clear|clip|color|content|counter-increment|counter-reset|' - r'cue-after|cue-before|cue|cursor|direction|display|' - r'elevation|empty-cells|float|font-family|font-size|' - r'font-size-adjust|font-stretch|font-style|font-variant|' - r'font-weight|font|height|letter-spacing|line-height|' - r'list-style-type|list-style-image|list-style-position|' - r'list-style|margin-bottom|margin-left|margin-right|' - r'margin-top|margin|marker-offset|marks|max-height|max-width|' - r'min-height|min-width|opacity|orphans|outline|outline-color|' - r'outline-style|outline-width|overflow|padding-bottom|' - r'padding-left|padding-right|padding-top|padding|page|' - r'page-break-after|page-break-before|page-break-inside|' - r'pause-after|pause-before|pause|pitch|pitch-range|' - r'play-during|position|quotes|richness|right|size|' - r'speak-header|speak-numeral|speak-punctuation|speak|' - r'speech-rate|stress|table-layout|text-align|text-decoration|' - r'text-indent|text-shadow|text-transform|top|unicode-bidi|' - r'vertical-align|visibility|voice-family|volume|white-space|' - r'widows|width|word-spacing|z-index|bottom|left|' - r'above|absolute|always|armenian|aural|auto|avoid|baseline|' - r'behind|below|bidi-override|blink|block|bold|bolder|both|' - r'capitalize|center-left|center-right|center|circle|' - r'cjk-ideographic|close-quote|collapse|condensed|continuous|' - r'crop|crosshair|cross|cursive|dashed|decimal-leading-zero|' - r'decimal|default|digits|disc|dotted|double|e-resize|embed|' - r'extra-condensed|extra-expanded|expanded|fantasy|far-left|' - r'far-right|faster|fast|fixed|georgian|groove|hebrew|help|' - r'hidden|hide|higher|high|hiragana-iroha|hiragana|icon|' - r'inherit|inline-table|inline|inset|inside|invert|italic|' - r'justify|katakana-iroha|katakana|landscape|larger|large|' - r'left-side|leftwards|level|lighter|line-through|list-item|' - r'loud|lower-alpha|lower-greek|lower-roman|lowercase|ltr|' - r'lower|low|medium|message-box|middle|mix|monospace|' - r'n-resize|narrower|ne-resize|no-close-quote|no-open-quote|' - r'no-repeat|none|normal|nowrap|nw-resize|oblique|once|' - r'open-quote|outset|outside|overline|pointer|portrait|px|' - r'relative|repeat-x|repeat-y|repeat|rgb|ridge|right-side|' - r'rightwards|s-resize|sans-serif|scroll|se-resize|' - r'semi-condensed|semi-expanded|separate|serif|show|silent|' - r'slow|slower|small-caps|small-caption|smaller|soft|solid|' - r'spell-out|square|static|status-bar|super|sw-resize|' - r'table-caption|table-cell|table-column|table-column-group|' - r'table-footer-group|table-header-group|table-row|' - r'table-row-group|text|text-bottom|text-top|thick|thin|' - r'transparent|ultra-condensed|ultra-expanded|underline|' - r'upper-alpha|upper-latin|upper-roman|uppercase|url|' - r'visible|w-resize|wait|wider|x-fast|x-high|x-large|x-loud|' - r'x-low|x-small|x-soft|xx-large|xx-small|yes)\b', Name.Constant), - (r'(indigo|gold|firebrick|indianred|darkolivegreen|' - r'darkseagreen|mediumvioletred|mediumorchid|chartreuse|' - r'mediumslateblue|springgreen|crimson|lightsalmon|brown|' - r'turquoise|olivedrab|cyan|skyblue|darkturquoise|' - r'goldenrod|darkgreen|darkviolet|darkgray|lightpink|' - r'darkmagenta|lightgoldenrodyellow|lavender|yellowgreen|thistle|' - r'violet|orchid|ghostwhite|honeydew|cornflowerblue|' - r'darkblue|darkkhaki|mediumpurple|cornsilk|bisque|slategray|' - r'darkcyan|khaki|wheat|deepskyblue|darkred|steelblue|aliceblue|' - r'gainsboro|mediumturquoise|floralwhite|coral|lightgrey|' - r'lightcyan|darksalmon|beige|azure|lightsteelblue|oldlace|' - r'greenyellow|royalblue|lightseagreen|mistyrose|sienna|' - r'lightcoral|orangered|navajowhite|palegreen|burlywood|' - r'seashell|mediumspringgreen|papayawhip|blanchedalmond|' - r'peru|aquamarine|darkslategray|ivory|dodgerblue|' - r'lemonchiffon|chocolate|orange|forestgreen|slateblue|' - r'mintcream|antiquewhite|darkorange|cadetblue|moccasin|' - r'limegreen|saddlebrown|darkslateblue|lightskyblue|deeppink|' - r'plum|darkgoldenrod|sandybrown|magenta|tan|' - r'rosybrown|pink|lightblue|palevioletred|mediumseagreen|' - r'dimgray|powderblue|seagreen|snow|mediumblue|midnightblue|' - r'paleturquoise|palegoldenrod|whitesmoke|darkorchid|salmon|' - r'lightslategray|lawngreen|lightgreen|tomato|hotpink|' - r'lightyellow|lavenderblush|linen|mediumaquamarine|' - r'blueviolet|peachpuff)\b', Name.Entity), - (r'(black|silver|gray|white|maroon|red|purple|fuchsia|green|' - r'lime|olive|yellow|navy|blue|teal|aqua)\b', Name.Builtin), - (r'\!(important|default)', Name.Exception), - (r'(true|false)', Name.Pseudo), - (r'(and|or|not)', Operator.Word), - (r'/\*', Comment.Multiline, 'inline-comment'), - (r'//[^\n]*', Comment.Single), - (r'\#[a-z0-9]{1,6}', Number.Hex), - (r'(-?\d+)(\%|[a-z]+)?', bygroups(Number.Integer, Keyword.Type)), - (r'(-?\d*\.\d+)(\%|[a-z]+)?', bygroups(Number.Float, Keyword.Type)), - (r'#{', String.Interpol, 'interpolation'), - (r'[~\^\*!&%<>\|+=@:,./?-]+', Operator), - (r'[\[\]()]+', Punctuation), - (r'"', String.Double, 'string-double'), - (r"'", String.Single, 'string-single'), - (r'[a-z_-][\w-]*', Name), - ], - - 'interpolation': [ - (r'\}', String.Interpol, '#pop'), - include('value'), - ], - - 'selector': [ - (r'[ \t]+', Text), - (r'\:', Name.Decorator, 'pseudo-class'), - (r'\.', Name.Class, 'class'), - (r'\#', Name.Namespace, 'id'), - (r'[\w-]+', Name.Tag), - (r'#\{', String.Interpol, 'interpolation'), - (r'&', Keyword), - (r'[~\^\*!&\[\]\(\)<>\|+=@:;,./?-]', Operator), - (r'"', String.Double, 'string-double'), - (r"'", String.Single, 'string-single'), - ], - - 'string-double': [ - (r'(\\.|#(?=[^\n{])|[^\n"#])+', String.Double), - (r'#\{', String.Interpol, 'interpolation'), - (r'"', String.Double, '#pop'), - ], - - 'string-single': [ - (r"(\\.|#(?=[^\n{])|[^\n'#])+", String.Double), - (r'#\{', String.Interpol, 'interpolation'), - (r"'", String.Double, '#pop'), - ], - - 'string-url': [ - (r'(\\#|#(?=[^\n{])|[^\n#)])+', String.Other), - (r'#\{', String.Interpol, 'interpolation'), - (r'\)', String.Other, '#pop'), - ], - - 'pseudo-class': [ - (r'[\w-]+', Name.Decorator), - (r'#\{', String.Interpol, 'interpolation'), - default('#pop'), - ], - - 'class': [ - (r'[\w-]+', Name.Class), - (r'#\{', String.Interpol, 'interpolation'), - default('#pop'), - ], - - 'id': [ - (r'[\w-]+', Name.Namespace), - (r'#\{', String.Interpol, 'interpolation'), - default('#pop'), - ], - - 'for': [ - (r'(from|to|through)', Operator.Word), - include('value'), - ], -} - -class SassLexer(ExtendedRegexLexer): - """ - For Sass stylesheets. - - .. versionadded:: 1.3 - """ - - name = 'Sass' - aliases = ['sass'] - filenames = ['*.sass'] - mimetypes = ['text/x-sass'] - - flags = re.IGNORECASE - tokens = { - 'root': [ - (r'[ \t]*\n', Text), - (r'[ \t]*', _indentation), - ], - - 'content': [ - (r'//[^\n]*', _starts_block(Comment.Single, 'single-comment'), - 'root'), - (r'/\*[^\n]*', _starts_block(Comment.Multiline, 'multi-comment'), - 'root'), - (r'@import', Keyword, 'import'), - (r'@for', Keyword, 'for'), - (r'@(debug|warn|if|while)', Keyword, 'value'), - (r'(@mixin)( [\w-]+)', bygroups(Keyword, Name.Function), 'value'), - (r'(@include)( [\w-]+)', bygroups(Keyword, Name.Decorator), 'value'), - (r'@extend', Keyword, 'selector'), - (r'@[\w-]+', Keyword, 'selector'), - (r'=[\w-]+', Name.Function, 'value'), - (r'\+[\w-]+', Name.Decorator, 'value'), - (r'([!$][\w-]\w*)([ \t]*(?:(?:\|\|)?=|:))', - bygroups(Name.Variable, Operator), 'value'), - (r':', Name.Attribute, 'old-style-attr'), - (r'(?=.+?[=:]([^a-z]|$))', Name.Attribute, 'new-style-attr'), - default('selector'), - ], - - 'single-comment': [ - (r'.+', Comment.Single), - (r'\n', Text, 'root'), - ], - - 'multi-comment': [ - (r'.+', Comment.Multiline), - (r'\n', Text, 'root'), - ], - - 'import': [ - (r'[ \t]+', Text), - (r'\S+', String), - (r'\n', Text, 'root'), - ], - - 'old-style-attr': [ - (r'[^\s:="\[]+', Name.Attribute), - (r'#{', String.Interpol, 'interpolation'), - (r'[ \t]*=', Operator, 'value'), - default('value'), - ], - - 'new-style-attr': [ - (r'[^\s:="\[]+', Name.Attribute), - (r'#{', String.Interpol, 'interpolation'), - (r'[ \t]*[=:]', Operator, 'value'), - ], - - 'inline-comment': [ - (r"(\\#|#(?=[^\n{])|\*(?=[^\n/])|[^\n#*])+", Comment.Multiline), - (r'#\{', String.Interpol, 'interpolation'), - (r"\*/", Comment, '#pop'), - ], - } - for group, common in iteritems(common_sass_tokens): - tokens[group] = copy.copy(common) - tokens['value'].append((r'\n', Text, 'root')) - tokens['selector'].append((r'\n', Text, 'root')) - - -class ScssLexer(RegexLexer): - """ - For SCSS stylesheets. - """ - - name = 'SCSS' - aliases = ['scss'] - filenames = ['*.scss'] - mimetypes = ['text/x-scss'] - - flags = re.IGNORECASE | re.DOTALL - tokens = { - 'root': [ - (r'\s+', Text), - (r'//.*?\n', Comment.Single), - (r'/\*.*?\*/', Comment.Multiline), - (r'@import', Keyword, 'value'), - (r'@for', Keyword, 'for'), - (r'@(debug|warn|if|while)', Keyword, 'value'), - (r'(@mixin)( [\w-]+)', bygroups(Keyword, Name.Function), 'value'), - (r'(@include)( [\w-]+)', bygroups(Keyword, Name.Decorator), 'value'), - (r'@extend', Keyword, 'selector'), - (r'@[\w-]+', Keyword, 'selector'), - (r'(\$[\w-]*\w)([ \t]*:)', bygroups(Name.Variable, Operator), 'value'), - (r'(?=[^;{}][;}])', Name.Attribute, 'attr'), - (r'(?=[^;{}:]+:[^a-z])', Name.Attribute, 'attr'), - default('selector'), - ], - - 'attr': [ - (r'[^\s:="\[]+', Name.Attribute), - (r'#{', String.Interpol, 'interpolation'), - (r'[ \t]*:', Operator, 'value'), - ], - - 'inline-comment': [ - (r"(\\#|#(?=[^{])|\*(?=[^/])|[^#*])+", Comment.Multiline), - (r'#\{', String.Interpol, 'interpolation'), - (r"\*/", Comment, '#pop'), - ], - } - for group, common in iteritems(common_sass_tokens): - tokens[group] = copy.copy(common) - tokens['value'].extend([(r'\n', Text), (r'[;{}]', Punctuation, 'root')]) - tokens['selector'].extend([(r'\n', Text), (r'[;{}]', Punctuation, 'root')]) - - -class CoffeeScriptLexer(RegexLexer): - """ - For `CoffeeScript`_ source code. - - .. _CoffeeScript: http://coffeescript.org - - .. versionadded:: 1.3 - """ - - name = 'CoffeeScript' - aliases = ['coffee-script', 'coffeescript', 'coffee'] - filenames = ['*.coffee'] - mimetypes = ['text/coffeescript'] - - flags = re.DOTALL - tokens = { - 'commentsandwhitespace': [ - (r'\s+', Text), - (r'###[^#].*?###', Comment.Multiline), - (r'#(?!##[^#]).*?\n', Comment.Single), - ], - 'multilineregex': [ - (r'[^/#]+', String.Regex), - (r'///([gim]+\b|\B)', String.Regex, '#pop'), - (r'#{', String.Interpol, 'interpoling_string'), - (r'[/#]', String.Regex), - ], - 'slashstartsregex': [ - include('commentsandwhitespace'), - (r'///', String.Regex, ('#pop', 'multilineregex')), - (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' - r'([gim]+\b|\B)', String.Regex, '#pop'), - default('#pop'), - ], - 'root': [ - # this next expr leads to infinite loops root -> slashstartsregex - #(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), - include('commentsandwhitespace'), - (r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|' - r'\|\||\\(?=\n)|' - r'(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&\|\^/])=?', - Operator, 'slashstartsregex'), - (r'(?:\([^()]*\))?\s*[=-]>', Name.Function), - (r'[{(\[;,]', Punctuation, 'slashstartsregex'), - (r'[})\].]', Punctuation), - (r'(?<![\.\$])(for|own|in|of|while|until|' - r'loop|break|return|continue|' - r'switch|when|then|if|unless|else|' - r'throw|try|catch|finally|new|delete|typeof|instanceof|super|' - r'extends|this|class|by)\b', Keyword, 'slashstartsregex'), - (r'(?<![\.\$])(true|false|yes|no|on|off|null|' - r'NaN|Infinity|undefined)\b', - Keyword.Constant), - (r'(Array|Boolean|Date|Error|Function|Math|netscape|' - r'Number|Object|Packages|RegExp|String|sun|decodeURI|' - r'decodeURIComponent|encodeURI|encodeURIComponent|' - r'eval|isFinite|isNaN|parseFloat|parseInt|document|window)\b', - Name.Builtin), - (r'[$a-zA-Z_][\w\.:\$]*\s*[:=]\s', Name.Variable, - 'slashstartsregex'), - (r'@[$a-zA-Z_][\w\.:\$]*\s*[:=]\s', Name.Variable.Instance, - 'slashstartsregex'), - (r'@', Name.Other, 'slashstartsregex'), - (r'@?[$a-zA-Z_][\w\$]*', Name.Other, 'slashstartsregex'), - (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), - (r'0x[0-9a-fA-F]+', Number.Hex), - (r'[0-9]+', Number.Integer), - ('"""', String, 'tdqs'), - ("'''", String, 'tsqs'), - ('"', String, 'dqs'), - ("'", String, 'sqs'), - ], - 'strings': [ - (r'[^#\\\'"]+', String), - # note that all coffee script strings are multi-line. - # hashmarks, quotes and backslashes must be parsed one at a time - ], - 'interpoling_string' : [ - (r'}', String.Interpol, "#pop"), - include('root') - ], - 'dqs': [ - (r'"', String, '#pop'), - (r'\\.|\'', String), # double-quoted string don't need ' escapes - (r'#{', String.Interpol, "interpoling_string"), - (r'#', String), - include('strings') - ], - 'sqs': [ - (r"'", String, '#pop'), - (r'#|\\.|"', String), # single quoted strings don't need " escapses - include('strings') - ], - 'tdqs': [ - (r'"""', String, '#pop'), - (r'\\.|\'|"', String), # no need to escape quotes in triple-string - (r'#{', String.Interpol, "interpoling_string"), - (r'#', String), - include('strings'), - ], - 'tsqs': [ - (r"'''", String, '#pop'), - (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings - include('strings') - ], - } - - -class KalLexer(RegexLexer): - """ - For `Kal`_ source code. - - .. _Kal: http://rzimmerman.github.io/kal - - - .. versionadded:: 2.0 - """ - - name = 'Kal' - aliases = ['kal'] - filenames = ['*.kal'] - mimetypes = ['text/kal', 'application/kal'] - - flags = re.DOTALL - tokens = { - 'commentsandwhitespace': [ - (r'\s+', Text), - (r'###[^#].*?###', Comment.Multiline), - (r'#(?!##[^#]).*?\n', Comment.Single), - ], - 'functiondef': [ - (r'[$a-zA-Z_][\w\$]*\s*', Name.Function, '#pop'), - include('commentsandwhitespace'), - ], - 'classdef': [ - (r'\binherits\s+from\b', Keyword), - (r'[$a-zA-Z_][\w\$]*\s*\n', Name.Class, '#pop'), - (r'[$a-zA-Z_][\w\$]*\s*', Name.Class), - include('commentsandwhitespace'), - ], - 'listcomprehension': [ - (r'\]', Punctuation, '#pop'), - (r'\b(property|value)\b', Keyword), - include('root'), - ], - 'waitfor': [ - (r'\n', Punctuation, '#pop'), - (r'\bfrom\b', Keyword), - include('root'), - ], - 'root': [ - include('commentsandwhitespace'), - (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' - r'([gim]+\b|\B)', String.Regex), - (r'\?|:|_(?=\n)|==?|!=|-(?!>)|[<>+*/-]=?', - Operator), - (r'\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|' - r'\bbut\b|\bbitwise\b|\bmod\b|\^|\bxor\b|\bexists\b|\bdoesnt\s+exist\b', - Operator.Word), - (r'(?:\([^()]+\))?\s*>', Name.Function), - (r'[{(]', Punctuation), - (r'\[', Punctuation, 'listcomprehension'), - (r'[})\]\.\,]', Punctuation), - (r'\b(function|method|task)\b', Keyword.Declaration, 'functiondef'), - (r'\bclass\b', Keyword.Declaration, 'classdef'), - (r'\b(safe\s+)?wait\s+for\b', Keyword, 'waitfor'), - (r'\b(me|this)(\.[$a-zA-Z_][\w\.\$]*)?\b', Name.Variable.Instance), - (r'(?<![\.\$])(for(\s+(parallel|series))?|in|of|while|until|' - r'break|return|continue|' - r'when|if|unless|else|otherwise|except\s+when|' - r'throw|raise|fail\s+with|try|catch|finally|new|delete|' - r'typeof|instanceof|super|run\s+in\s+parallel|' - r'inherits\s+from)\b', Keyword), - (r'(?<![\.\$])(true|false|yes|no|on|off|null|nothing|none|' - r'NaN|Infinity|undefined)\b', - Keyword.Constant), - (r'(Array|Boolean|Date|Error|Function|Math|netscape|' - r'Number|Object|Packages|RegExp|String|sun|decodeURI|' - r'decodeURIComponent|encodeURI|encodeURIComponent|' - r'eval|isFinite|isNaN|parseFloat|parseInt|document|window|' - r'print)\b', - Name.Builtin), - (r'[$a-zA-Z_][\w\.\$]*\s*(:|[\+\-\*\/]?\=)?\b', Name.Variable), - (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), - (r'0x[0-9a-fA-F]+', Number.Hex), - (r'[0-9]+', Number.Integer), - ('"""', String, 'tdqs'), - ("'''", String, 'tsqs'), - ('"', String, 'dqs'), - ("'", String, 'sqs'), - ], - 'strings': [ - (r'[^#\\\'"]+', String), - # note that all kal strings are multi-line. - # hashmarks, quotes and backslashes must be parsed one at a time - ], - 'interpoling_string' : [ - (r'}', String.Interpol, "#pop"), - include('root') - ], - 'dqs': [ - (r'"', String, '#pop'), - (r'\\.|\'', String), # double-quoted string don't need ' escapes - (r'#{', String.Interpol, "interpoling_string"), - include('strings') - ], - 'sqs': [ - (r"'", String, '#pop'), - (r'#|\\.|"', String), # single quoted strings don't need " escapses - include('strings') - ], - 'tdqs': [ - (r'"""', String, '#pop'), - (r'\\.|\'|"', String), # no need to escape quotes in triple-string - (r'#{', String.Interpol, "interpoling_string"), - include('strings'), - ], - 'tsqs': [ - (r"'''", String, '#pop'), - (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings - include('strings') - ], - } - - -class LiveScriptLexer(RegexLexer): - """ - For `LiveScript`_ source code. - - .. _LiveScript: http://gkz.github.com/LiveScript/ - - New in Pygments 1.6. - """ - - name = 'LiveScript' - aliases = ['live-script', 'livescript'] - filenames = ['*.ls'] - mimetypes = ['text/livescript'] - - flags = re.DOTALL - tokens = { - 'commentsandwhitespace': [ - (r'\s+', Text), - (r'/\*.*?\*/', Comment.Multiline), - (r'#.*?\n', Comment.Single), - ], - 'multilineregex': [ - include('commentsandwhitespace'), - (r'//([gim]+\b|\B)', String.Regex, '#pop'), - (r'/', String.Regex), - (r'[^/#]+', String.Regex) - ], - 'slashstartsregex': [ - include('commentsandwhitespace'), - (r'//', String.Regex, ('#pop', 'multilineregex')), - (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' - r'([gim]+\b|\B)', String.Regex, '#pop'), - default('#pop'), - ], - 'root': [ - # this next expr leads to infinite loops root -> slashstartsregex - #(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), - include('commentsandwhitespace'), - (r'(?:\([^()]+\))?[ ]*[~-]{1,2}>|' - r'(?:\(?[^()\n]+\)?)?[ ]*<[~-]{1,2}', Name.Function), - (r'\+\+|&&|(?<![\.\$])\b(?:and|x?or|is|isnt|not)\b|\?|:|=|' - r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|' - r'~(?!\~?>)|-(?!\-?>)|<(?!\[)|(?<!\])>|' - r'[+*`%&\|\^/])=?', - Operator, 'slashstartsregex'), - (r'[{(\[;,]', Punctuation, 'slashstartsregex'), - (r'[})\].]', Punctuation), - (r'(?<![\.\$])(for|own|in|of|while|until|loop|break|' - r'return|continue|switch|when|then|if|unless|else|' - r'throw|try|catch|finally|new|delete|typeof|instanceof|super|' - r'extends|this|class|by|const|var|to|til)\b', Keyword, - 'slashstartsregex'), - (r'(?<![\.\$])(true|false|yes|no|on|off|' - r'null|NaN|Infinity|undefined|void)\b', - Keyword.Constant), - (r'(Array|Boolean|Date|Error|Function|Math|netscape|' - r'Number|Object|Packages|RegExp|String|sun|decodeURI|' - r'decodeURIComponent|encodeURI|encodeURIComponent|' - r'eval|isFinite|isNaN|parseFloat|parseInt|document|window)\b', - Name.Builtin), - (r'[$a-zA-Z_][\w\.\-:\$]*\s*[:=]\s', Name.Variable, - 'slashstartsregex'), - (r'@[$a-zA-Z_][\w\.\-:\$]*\s*[:=]\s', Name.Variable.Instance, - 'slashstartsregex'), - (r'@', Name.Other, 'slashstartsregex'), - (r'@?[$a-zA-Z_][\w\-]*', Name.Other, 'slashstartsregex'), - (r'[0-9]+\.[0-9]+([eE][0-9]+)?[fd]?(?:[a-zA-Z_]+)?', Number.Float), - (r'[0-9]+(~[0-9a-z]+)?(?:[a-zA-Z_]+)?', Number.Integer), - ('"""', String, 'tdqs'), - ("'''", String, 'tsqs'), - ('"', String, 'dqs'), - ("'", String, 'sqs'), - (r'\\\S+', String), - (r'<\[.*?\]>', String), - ], - 'strings': [ - (r'[^#\\\'"]+', String), - # note that all coffee script strings are multi-line. - # hashmarks, quotes and backslashes must be parsed one at a time - ], - 'interpoling_string' : [ - (r'}', String.Interpol, "#pop"), - include('root') - ], - 'dqs': [ - (r'"', String, '#pop'), - (r'\\.|\'', String), # double-quoted string don't need ' escapes - (r'#{', String.Interpol, "interpoling_string"), - (r'#', String), - include('strings') - ], - 'sqs': [ - (r"'", String, '#pop'), - (r'#|\\.|"', String), # single quoted strings don't need " escapses - include('strings') - ], - 'tdqs': [ - (r'"""', String, '#pop'), - (r'\\.|\'|"', String), # no need to escape quotes in triple-string - (r'#{', String.Interpol, "interpoling_string"), - (r'#', String), - include('strings'), - ], - 'tsqs': [ - (r"'''", String, '#pop'), - (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings - include('strings') - ], - } - - -class DuelLexer(RegexLexer): - """ - Lexer for Duel Views Engine (formerly JBST) markup with JavaScript code blocks. - See http://duelengine.org/. - See http://jsonml.org/jbst/. - - .. versionadded:: 1.4 - """ - - name = 'Duel' - aliases = ['duel', 'jbst', 'jsonml+bst'] - filenames = ['*.duel','*.jbst'] - mimetypes = ['text/x-duel','text/x-jbst'] - - flags = re.DOTALL - - tokens = { - 'root': [ - (r'(<%[@=#!:]?)(.*?)(%>)', - bygroups(Name.Tag, using(JavascriptLexer), Name.Tag)), - (r'(<%\$)(.*?)(:)(.*?)(%>)', - bygroups(Name.Tag, Name.Function, Punctuation, String, Name.Tag)), - (r'(<%--)(.*?)(--%>)', - bygroups(Name.Tag, Comment.Multiline, Name.Tag)), - (r'(<script.*?>)(.*?)(</script>)', - bygroups(using(HtmlLexer), - using(JavascriptLexer), using(HtmlLexer))), - (r'(.+?)(?=<)', using(HtmlLexer)), - (r'.+', using(HtmlLexer)), - ], - } - - -class ScamlLexer(ExtendedRegexLexer): - """ - For `Scaml markup <http://scalate.fusesource.org/>`_. Scaml is Haml for Scala. - - .. versionadded:: 1.4 - """ - - name = 'Scaml' - aliases = ['scaml'] - filenames = ['*.scaml'] - mimetypes = ['text/x-scaml'] - - flags = re.IGNORECASE - # Scaml does not yet support the " |\n" notation to - # wrap long lines. Once it does, use the custom faux - # dot instead. - # _dot = r'(?: \|\n(?=.* \|)|.)' - _dot = r'.' - - tokens = { - 'root': [ - (r'[ \t]*\n', Text), - (r'[ \t]*', _indentation), - ], - - 'css': [ - (r'\.[\w:-]+', Name.Class, 'tag'), - (r'\#[\w:-]+', Name.Function, 'tag'), - ], - - 'eval-or-plain': [ - (r'[&!]?==', Punctuation, 'plain'), - (r'([&!]?[=~])(' + _dot + r'*\n)', - bygroups(Punctuation, using(ScalaLexer)), - 'root'), - default('plain'), - ], - - 'content': [ - include('css'), - (r'%[\w:-]+', Name.Tag, 'tag'), - (r'!!!' + _dot + r'*\n', Name.Namespace, '#pop'), - (r'(/)(\[' + _dot + '*?\])(' + _dot + r'*\n)', - bygroups(Comment, Comment.Special, Comment), - '#pop'), - (r'/' + _dot + r'*\n', _starts_block(Comment, 'html-comment-block'), - '#pop'), - (r'-#' + _dot + r'*\n', _starts_block(Comment.Preproc, - 'scaml-comment-block'), '#pop'), - (r'(-@\s*)(import)?(' + _dot + r'*\n)', - bygroups(Punctuation, Keyword, using(ScalaLexer)), - '#pop'), - (r'(-)(' + _dot + r'*\n)', - bygroups(Punctuation, using(ScalaLexer)), - '#pop'), - (r':' + _dot + r'*\n', _starts_block(Name.Decorator, 'filter-block'), - '#pop'), - include('eval-or-plain'), - ], - - 'tag': [ - include('css'), - (r'\{(,\n|' + _dot + ')*?\}', using(ScalaLexer)), - (r'\[' + _dot + '*?\]', using(ScalaLexer)), - (r'\(', Text, 'html-attributes'), - (r'/[ \t]*\n', Punctuation, '#pop:2'), - (r'[<>]{1,2}(?=[ \t=])', Punctuation), - include('eval-or-plain'), - ], - - 'plain': [ - (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text), - (r'(#\{)(' + _dot + '*?)(\})', - bygroups(String.Interpol, using(ScalaLexer), String.Interpol)), - (r'\n', Text, 'root'), - ], - - 'html-attributes': [ - (r'\s+', Text), - (r'[\w:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'), - (r'[\w:-]+', Name.Attribute), - (r'\)', Text, '#pop'), - ], - - 'html-attribute-value': [ - (r'[ \t]+', Text), - (r'\w+', Name.Variable, '#pop'), - (r'@\w+', Name.Variable.Instance, '#pop'), - (r'\$\w+', Name.Variable.Global, '#pop'), - (r"'(\\\\|\\'|[^'\n])*'", String, '#pop'), - (r'"(\\\\|\\"|[^"\n])*"', String, '#pop'), - ], - - 'html-comment-block': [ - (_dot + '+', Comment), - (r'\n', Text, 'root'), - ], - - 'scaml-comment-block': [ - (_dot + '+', Comment.Preproc), - (r'\n', Text, 'root'), - ], - - 'filter-block': [ - (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator), - (r'(#\{)(' + _dot + '*?)(\})', - bygroups(String.Interpol, using(ScalaLexer), String.Interpol)), - (r'\n', Text, 'root'), - ], - } - - -class JadeLexer(ExtendedRegexLexer): - """ - For Jade markup. - Jade is a variant of Scaml, see: - http://scalate.fusesource.org/documentation/scaml-reference.html - - .. versionadded:: 1.4 - """ - - name = 'Jade' - aliases = ['jade'] - filenames = ['*.jade'] - mimetypes = ['text/x-jade'] - - flags = re.IGNORECASE - _dot = r'.' - - tokens = { - 'root': [ - (r'[ \t]*\n', Text), - (r'[ \t]*', _indentation), - ], - - 'css': [ - (r'\.[\w:-]+', Name.Class, 'tag'), - (r'\#[\w:-]+', Name.Function, 'tag'), - ], - - 'eval-or-plain': [ - (r'[&!]?==', Punctuation, 'plain'), - (r'([&!]?[=~])(' + _dot + r'*\n)', - bygroups(Punctuation, using(ScalaLexer)), 'root'), - default('plain'), - ], - - 'content': [ - include('css'), - (r'!!!' + _dot + r'*\n', Name.Namespace, '#pop'), - (r'(/)(\[' + _dot + '*?\])(' + _dot + r'*\n)', - bygroups(Comment, Comment.Special, Comment), - '#pop'), - (r'/' + _dot + r'*\n', _starts_block(Comment, 'html-comment-block'), - '#pop'), - (r'-#' + _dot + r'*\n', _starts_block(Comment.Preproc, - 'scaml-comment-block'), '#pop'), - (r'(-@\s*)(import)?(' + _dot + r'*\n)', - bygroups(Punctuation, Keyword, using(ScalaLexer)), - '#pop'), - (r'(-)(' + _dot + r'*\n)', - bygroups(Punctuation, using(ScalaLexer)), - '#pop'), - (r':' + _dot + r'*\n', _starts_block(Name.Decorator, 'filter-block'), - '#pop'), - (r'[\w:-]+', Name.Tag, 'tag'), - (r'\|', Text, 'eval-or-plain'), - ], - - 'tag': [ - include('css'), - (r'\{(,\n|' + _dot + ')*?\}', using(ScalaLexer)), - (r'\[' + _dot + '*?\]', using(ScalaLexer)), - (r'\(', Text, 'html-attributes'), - (r'/[ \t]*\n', Punctuation, '#pop:2'), - (r'[<>]{1,2}(?=[ \t=])', Punctuation), - include('eval-or-plain'), - ], - - 'plain': [ - (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text), - (r'(#\{)(' + _dot + '*?)(\})', - bygroups(String.Interpol, using(ScalaLexer), String.Interpol)), - (r'\n', Text, 'root'), - ], - - 'html-attributes': [ - (r'\s+', Text), - (r'[\w:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'), - (r'[\w:-]+', Name.Attribute), - (r'\)', Text, '#pop'), - ], - - 'html-attribute-value': [ - (r'[ \t]+', Text), - (r'\w+', Name.Variable, '#pop'), - (r'@\w+', Name.Variable.Instance, '#pop'), - (r'\$\w+', Name.Variable.Global, '#pop'), - (r"'(\\\\|\\'|[^'\n])*'", String, '#pop'), - (r'"(\\\\|\\"|[^"\n])*"', String, '#pop'), - ], - - 'html-comment-block': [ - (_dot + '+', Comment), - (r'\n', Text, 'root'), - ], - - 'scaml-comment-block': [ - (_dot + '+', Comment.Preproc), - (r'\n', Text, 'root'), - ], - - 'filter-block': [ - (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator), - (r'(#\{)(' + _dot + '*?)(\})', - bygroups(String.Interpol, using(ScalaLexer), String.Interpol)), - (r'\n', Text, 'root'), - ], - } - - -class XQueryLexer(ExtendedRegexLexer): - """ - An XQuery lexer, parsing a stream and outputting the tokens needed to - highlight xquery code. - - .. versionadded:: 1.4 - """ - name = 'XQuery' - aliases = ['xquery', 'xqy', 'xq', 'xql', 'xqm'] - filenames = ['*.xqy', '*.xquery', '*.xq', '*.xql', '*.xqm'] - mimetypes = ['text/xquery', 'application/xquery'] - - xquery_parse_state = [] - - # FIX UNICODE LATER - #ncnamestartchar = ( - # ur"[A-Z]|_|[a-z]|[\u00C0-\u00D6]|[\u00D8-\u00F6]|[\u00F8-\u02FF]|" - # ur"[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|" - # ur"[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]|" - # ur"[\u10000-\uEFFFF]" - #) - ncnamestartchar = r"(?:[A-Z]|_|[a-z])" - # FIX UNICODE LATER - #ncnamechar = ncnamestartchar + (ur"|-|\.|[0-9]|\u00B7|[\u0300-\u036F]|" - # ur"[\u203F-\u2040]") - ncnamechar = r"(?:" + ncnamestartchar + r"|-|\.|[0-9])" - ncname = "(?:%s+%s*)" % (ncnamestartchar, ncnamechar) - pitarget_namestartchar = r"(?:[A-KN-WY-Z]|_|:|[a-kn-wy-z])" - pitarget_namechar = r"(?:" + pitarget_namestartchar + r"|-|\.|[0-9])" - pitarget = "%s+%s*" % (pitarget_namestartchar, pitarget_namechar) - prefixedname = "%s:%s" % (ncname, ncname) - unprefixedname = ncname - qname = "(?:%s|%s)" % (prefixedname, unprefixedname) - - entityref = r'(?:&(?:lt|gt|amp|quot|apos|nbsp);)' - charref = r'(?:&#[0-9]+;|&#x[0-9a-fA-F]+;)' - - stringdouble = r'(?:"(?:' + entityref + r'|' + charref + r'|""|[^&"])*")' - stringsingle = r"(?:'(?:" + entityref + r"|" + charref + r"|''|[^&'])*')" - - # FIX UNICODE LATER - #elementcontentchar = (ur'\t|\r|\n|[\u0020-\u0025]|[\u0028-\u003b]|' - # ur'[\u003d-\u007a]|\u007c|[\u007e-\u007F]') - elementcontentchar = r'[A-Za-z]|\s|\d|[!"#$%\(\)\*\+,\-\./\:;=\?\@\[\\\]^_\'`\|~]' - #quotattrcontentchar = (ur'\t|\r|\n|[\u0020-\u0021]|[\u0023-\u0025]|' - # ur'[\u0027-\u003b]|[\u003d-\u007a]|\u007c|[\u007e-\u007F]') - quotattrcontentchar = r'[A-Za-z]|\s|\d|[!#$%\(\)\*\+,\-\./\:;=\?\@\[\\\]^_\'`\|~]' - #aposattrcontentchar = (ur'\t|\r|\n|[\u0020-\u0025]|[\u0028-\u003b]|' - # ur'[\u003d-\u007a]|\u007c|[\u007e-\u007F]') - aposattrcontentchar = r'[A-Za-z]|\s|\d|[!"#$%\(\)\*\+,\-\./\:;=\?\@\[\\\]^_`\|~]' - - - # CHAR elements - fix the above elementcontentchar, quotattrcontentchar, - # aposattrcontentchar - #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] - - flags = re.DOTALL | re.MULTILINE | re.UNICODE - - def punctuation_root_callback(lexer, match, ctx): - yield match.start(), Punctuation, match.group(1) - # transition to root always - don't pop off stack - ctx.stack = ['root'] - ctx.pos = match.end() - - def operator_root_callback(lexer, match, ctx): - yield match.start(), Operator, match.group(1) - # transition to root always - don't pop off stack - ctx.stack = ['root'] - ctx.pos = match.end() - - def popstate_tag_callback(lexer, match, ctx): - yield match.start(), Name.Tag, match.group(1) - ctx.stack.append(lexer.xquery_parse_state.pop()) - ctx.pos = match.end() - - def popstate_xmlcomment_callback(lexer, match, ctx): - yield match.start(), String.Doc, match.group(1) - ctx.stack.append(lexer.xquery_parse_state.pop()) - ctx.pos = match.end() - - def popstate_kindtest_callback(lexer, match, ctx): - yield match.start(), Punctuation, match.group(1) - next_state = lexer.xquery_parse_state.pop() - if next_state == 'occurrenceindicator': - if re.match("[?*+]+", match.group(2)): - yield match.start(), Punctuation, match.group(2) - ctx.stack.append('operator') - ctx.pos = match.end() - else: - ctx.stack.append('operator') - ctx.pos = match.end(1) - else: - ctx.stack.append(next_state) - ctx.pos = match.end(1) - - def popstate_callback(lexer, match, ctx): - yield match.start(), Punctuation, match.group(1) - # if we have run out of our state stack, pop whatever is on the pygments - # state stack - if len(lexer.xquery_parse_state) == 0: - ctx.stack.pop() - elif len(ctx.stack) > 1: - ctx.stack.append(lexer.xquery_parse_state.pop()) - else: - # i don't know if i'll need this, but in case, default back to root - ctx.stack = ['root'] - ctx.pos = match.end() - - def pushstate_element_content_starttag_callback(lexer, match, ctx): - yield match.start(), Name.Tag, match.group(1) - lexer.xquery_parse_state.append('element_content') - ctx.stack.append('start_tag') - ctx.pos = match.end() - - def pushstate_cdata_section_callback(lexer, match, ctx): - yield match.start(), String.Doc, match.group(1) - ctx.stack.append('cdata_section') - lexer.xquery_parse_state.append(ctx.state.pop) - ctx.pos = match.end() - - def pushstate_starttag_callback(lexer, match, ctx): - yield match.start(), Name.Tag, match.group(1) - lexer.xquery_parse_state.append(ctx.state.pop) - ctx.stack.append('start_tag') - ctx.pos = match.end() - - def pushstate_operator_order_callback(lexer, match, ctx): - yield match.start(), Keyword, match.group(1) - yield match.start(), Text, match.group(2) - yield match.start(), Punctuation, match.group(3) - ctx.stack = ['root'] - lexer.xquery_parse_state.append('operator') - ctx.pos = match.end() - - def pushstate_operator_root_validate(lexer, match, ctx): - yield match.start(), Keyword, match.group(1) - yield match.start(), Text, match.group(2) - yield match.start(), Punctuation, match.group(3) - ctx.stack = ['root'] - lexer.xquery_parse_state.append('operator') - ctx.pos = match.end() - - def pushstate_operator_root_validate_withmode(lexer, match, ctx): - yield match.start(), Keyword, match.group(1) - yield match.start(), Text, match.group(2) - yield match.start(), Keyword, match.group(3) - ctx.stack = ['root'] - lexer.xquery_parse_state.append('operator') - ctx.pos = match.end() - - def pushstate_operator_processing_instruction_callback(lexer, match, ctx): - yield match.start(), String.Doc, match.group(1) - ctx.stack.append('processing_instruction') - lexer.xquery_parse_state.append('operator') - ctx.pos = match.end() - - def pushstate_element_content_processing_instruction_callback(lexer, match, ctx): - yield match.start(), String.Doc, match.group(1) - ctx.stack.append('processing_instruction') - lexer.xquery_parse_state.append('element_content') - ctx.pos = match.end() - - def pushstate_element_content_cdata_section_callback(lexer, match, ctx): - yield match.start(), String.Doc, match.group(1) - ctx.stack.append('cdata_section') - lexer.xquery_parse_state.append('element_content') - ctx.pos = match.end() - - def pushstate_operator_cdata_section_callback(lexer, match, ctx): - yield match.start(), String.Doc, match.group(1) - ctx.stack.append('cdata_section') - lexer.xquery_parse_state.append('operator') - ctx.pos = match.end() - - def pushstate_element_content_xmlcomment_callback(lexer, match, ctx): - yield match.start(), String.Doc, match.group(1) - ctx.stack.append('xml_comment') - lexer.xquery_parse_state.append('element_content') - ctx.pos = match.end() - - def pushstate_operator_xmlcomment_callback(lexer, match, ctx): - yield match.start(), String.Doc, match.group(1) - ctx.stack.append('xml_comment') - lexer.xquery_parse_state.append('operator') - ctx.pos = match.end() - - def pushstate_kindtest_callback(lexer, match, ctx): - yield match.start(), Keyword, match.group(1) - yield match.start(), Text, match.group(2) - yield match.start(), Punctuation, match.group(3) - lexer.xquery_parse_state.append('kindtest') - ctx.stack.append('kindtest') - ctx.pos = match.end() - - def pushstate_operator_kindtestforpi_callback(lexer, match, ctx): - yield match.start(), Keyword, match.group(1) - yield match.start(), Text, match.group(2) - yield match.start(), Punctuation, match.group(3) - lexer.xquery_parse_state.append('operator') - ctx.stack.append('kindtestforpi') - ctx.pos = match.end() - - def pushstate_operator_kindtest_callback(lexer, match, ctx): - yield match.start(), Keyword, match.group(1) - yield match.start(), Text, match.group(2) - yield match.start(), Punctuation, match.group(3) - lexer.xquery_parse_state.append('operator') - ctx.stack.append('kindtest') - ctx.pos = match.end() - - def pushstate_occurrenceindicator_kindtest_callback(lexer, match, ctx): - yield match.start(), Name.Tag, match.group(1) - yield match.start(), Text, match.group(2) - yield match.start(), Punctuation, match.group(3) - lexer.xquery_parse_state.append('occurrenceindicator') - ctx.stack.append('kindtest') - ctx.pos = match.end() - - def pushstate_operator_starttag_callback(lexer, match, ctx): - yield match.start(), Name.Tag, match.group(1) - lexer.xquery_parse_state.append('operator') - ctx.stack.append('start_tag') - ctx.pos = match.end() - - def pushstate_operator_root_callback(lexer, match, ctx): - yield match.start(), Punctuation, match.group(1) - lexer.xquery_parse_state.append('operator') - ctx.stack = ['root']#.append('root') - ctx.pos = match.end() - - def pushstate_operator_root_construct_callback(lexer, match, ctx): - yield match.start(), Keyword, match.group(1) - yield match.start(), Text, match.group(2) - yield match.start(), Punctuation, match.group(3) - lexer.xquery_parse_state.append('operator') - ctx.stack = ['root'] - ctx.pos = match.end() - - def pushstate_root_callback(lexer, match, ctx): - yield match.start(), Punctuation, match.group(1) - cur_state = ctx.stack.pop() - lexer.xquery_parse_state.append(cur_state) - ctx.stack = ['root']#.append('root') - ctx.pos = match.end() - - def pushstate_operator_attribute_callback(lexer, match, ctx): - yield match.start(), Name.Attribute, match.group(1) - ctx.stack.append('operator') - ctx.pos = match.end() - - def pushstate_operator_callback(lexer, match, ctx): - yield match.start(), Keyword, match.group(1) - yield match.start(), Text, match.group(2) - yield match.start(), Punctuation, match.group(3) - lexer.xquery_parse_state.append('operator') - ctx.pos = match.end() - - tokens = { - 'comment': [ - # xquery comments - (r'(:\))', Comment, '#pop'), - (r'(\(:)', Comment, '#push'), - (r'[^:)]', Comment), - (r'([^:)]|:|\))', Comment), - ], - 'whitespace': [ - (r'\s+', Text), - ], - 'operator': [ - include('whitespace'), - (r'(\})', popstate_callback), - (r'\(:', Comment, 'comment'), - - (r'(\{)', pushstate_root_callback), - (r'then|else|external|at|div|except', Keyword, 'root'), - (r'order by', Keyword, 'root'), - (r'is|mod|order\s+by|stable\s+order\s+by', Keyword, 'root'), - (r'and|or', Operator.Word, 'root'), - (r'(eq|ge|gt|le|lt|ne|idiv|intersect|in)(?=\b)', - Operator.Word, 'root'), - (r'return|satisfies|to|union|where|preserve\s+strip', - Keyword, 'root'), - (r'(>=|>>|>|<=|<<|<|-|\*|!=|\+|\||:=|=)', - operator_root_callback), - (r'(::|;|\[|//|/|,)', - punctuation_root_callback), - (r'(castable|cast)(\s+)(as)\b', - bygroups(Keyword, Text, Keyword), 'singletype'), - (r'(instance)(\s+)(of)\b', - bygroups(Keyword, Text, Keyword), 'itemtype'), - (r'(treat)(\s+)(as)\b', - bygroups(Keyword, Text, Keyword), 'itemtype'), - (r'(case|as)\b', Keyword, 'itemtype'), - (r'(\))(\s*)(as)', - bygroups(Punctuation, Text, Keyword), 'itemtype'), - (r'\$', Name.Variable, 'varname'), - (r'(for|let)(\s+)(\$)', - bygroups(Keyword, Text, Name.Variable), 'varname'), - #(r'\)|\?|\]', Punctuation, '#push'), - (r'\)|\?|\]', Punctuation), - (r'(empty)(\s+)(greatest|least)', bygroups(Keyword, Text, Keyword)), - (r'ascending|descending|default', Keyword, '#push'), - (r'external', Keyword), - (r'collation', Keyword, 'uritooperator'), - # finally catch all string literals and stay in operator state - (stringdouble, String.Double), - (stringsingle, String.Single), - - (r'(catch)(\s*)', bygroups(Keyword, Text), 'root'), - ], - 'uritooperator': [ - (stringdouble, String.Double, '#pop'), - (stringsingle, String.Single, '#pop'), - ], - 'namespacedecl': [ - include('whitespace'), - (r'\(:', Comment, 'comment'), - (r'(at)(\s+)('+stringdouble+')', bygroups(Keyword, Text, String.Double)), - (r"(at)(\s+)("+stringsingle+')', bygroups(Keyword, Text, String.Single)), - (stringdouble, String.Double), - (stringsingle, String.Single), - (r',', Punctuation), - (r'=', Operator), - (r';', Punctuation, 'root'), - (ncname, Name.Namespace), - ], - 'namespacekeyword': [ - include('whitespace'), - (r'\(:', Comment, 'comment'), - (stringdouble, String.Double, 'namespacedecl'), - (stringsingle, String.Single, 'namespacedecl'), - (r'inherit|no-inherit', Keyword, 'root'), - (r'namespace', Keyword, 'namespacedecl'), - (r'(default)(\s+)(element)', bygroups(Keyword, Text, Keyword)), - (r'preserve|no-preserve', Keyword), - (r',', Punctuation), - ], - 'varname': [ - (r'\(:', Comment, 'comment'), - (qname, Name.Variable, 'operator'), - ], - 'singletype': [ - (r'\(:', Comment, 'comment'), - (ncname + r'(:\*)', Name.Variable, 'operator'), - (qname, Name.Variable, 'operator'), - ], - 'itemtype': [ - include('whitespace'), - (r'\(:', Comment, 'comment'), - (r'\$', Punctuation, 'varname'), - (r'(void)(\s*)(\()(\s*)(\))', - bygroups(Keyword, Text, Punctuation, Text, Punctuation), 'operator'), - (r'(element|attribute|schema-element|schema-attribute|comment|text|' - r'node|binary|document-node|empty-sequence)(\s*)(\()', - pushstate_occurrenceindicator_kindtest_callback), - # Marklogic specific type? - (r'(processing-instruction)(\s*)(\()', - bygroups(Keyword, Text, Punctuation), - ('occurrenceindicator', 'kindtestforpi')), - (r'(item)(\s*)(\()(\s*)(\))(?=[*+?])', - bygroups(Keyword, Text, Punctuation, Text, Punctuation), - 'occurrenceindicator'), - (r'\(\#', Punctuation, 'pragma'), - (r';', Punctuation, '#pop'), - (r'then|else', Keyword, '#pop'), - (r'(at)(\s+)(' + stringdouble + ')', - bygroups(Keyword, Text, String.Double), 'namespacedecl'), - (r'(at)(\s+)(' + stringsingle + ')', - bygroups(Keyword, Text, String.Single), 'namespacedecl'), - (r'except|intersect|in|is|return|satisfies|to|union|where', - Keyword, 'root'), - (r'and|div|eq|ge|gt|le|lt|ne|idiv|mod|or', Operator.Word, 'root'), - (r':=|=|,|>=|>>|>|\[|\(|<=|<<|<|-|!=|\|', Operator, 'root'), - (r'external|at', Keyword, 'root'), - (r'(stable)(\s+)(order)(\s+)(by)', - bygroups(Keyword, Text, Keyword, Text, Keyword), 'root'), - (r'(castable|cast)(\s+)(as)', - bygroups(Keyword, Text, Keyword), 'singletype'), - (r'(treat)(\s+)(as)', bygroups(Keyword, Text, Keyword)), - (r'(instance)(\s+)(of)', bygroups(Keyword, Text, Keyword)), - (r'case|as', Keyword, 'itemtype'), - (r'(\))(\s*)(as)', bygroups(Operator, Text, Keyword), 'itemtype'), - (ncname + r':\*', Keyword.Type, 'operator'), - (qname, Keyword.Type, 'occurrenceindicator'), - ], - 'kindtest': [ - (r'\(:', Comment, 'comment'), - (r'{', Punctuation, 'root'), - (r'(\))([*+?]?)', popstate_kindtest_callback), - (r'\*', Name, 'closekindtest'), - (qname, Name, 'closekindtest'), - (r'(element|schema-element)(\s*)(\()', pushstate_kindtest_callback), - ], - 'kindtestforpi': [ - (r'\(:', Comment, 'comment'), - (r'\)', Punctuation, '#pop'), - (ncname, Name.Variable), - (stringdouble, String.Double), - (stringsingle, String.Single), - ], - 'closekindtest': [ - (r'\(:', Comment, 'comment'), - (r'(\))', popstate_callback), - (r',', Punctuation), - (r'(\{)', pushstate_operator_root_callback), - (r'\?', Punctuation), - ], - 'xml_comment': [ - (r'(-->)', popstate_xmlcomment_callback), - (r'[^-]{1,2}', Literal), - (u'\\t|\\r|\\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + - unirange(0x10000, 0x10ffff), Literal), - ], - 'processing_instruction': [ - (r'\s+', Text, 'processing_instruction_content'), - (r'\?>', String.Doc, '#pop'), - (pitarget, Name), - ], - 'processing_instruction_content': [ - (r'\?>', String.Doc, '#pop'), - (u'\\t|\\r|\\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + - unirange(0x10000, 0x10ffff), Literal), - ], - 'cdata_section': [ - (r']]>', String.Doc, '#pop'), - (u'\\t|\\r|\\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + - unirange(0x10000, 0x10ffff), Literal), - ], - 'start_tag': [ - include('whitespace'), - (r'(/>)', popstate_tag_callback), - (r'>', Name.Tag, 'element_content'), - (r'"', Punctuation, 'quot_attribute_content'), - (r"'", Punctuation, 'apos_attribute_content'), - (r'=', Operator), - (qname, Name.Tag), - ], - 'quot_attribute_content': [ - (r'"', Punctuation, 'start_tag'), - (r'(\{)', pushstate_root_callback), - (r'""', Name.Attribute), - (quotattrcontentchar, Name.Attribute), - (entityref, Name.Attribute), - (charref, Name.Attribute), - (r'\{\{|\}\}', Name.Attribute), - ], - 'apos_attribute_content': [ - (r"'", Punctuation, 'start_tag'), - (r'\{', Punctuation, 'root'), - (r"''", Name.Attribute), - (aposattrcontentchar, Name.Attribute), - (entityref, Name.Attribute), - (charref, Name.Attribute), - (r'\{\{|\}\}', Name.Attribute), - ], - 'element_content': [ - (r'</', Name.Tag, 'end_tag'), - (r'(\{)', pushstate_root_callback), - (r'(<!--)', pushstate_element_content_xmlcomment_callback), - (r'(<\?)', pushstate_element_content_processing_instruction_callback), - (r'(<!\[CDATA\[)', pushstate_element_content_cdata_section_callback), - (r'(<)', pushstate_element_content_starttag_callback), - (elementcontentchar, Literal), - (entityref, Literal), - (charref, Literal), - (r'\{\{|\}\}', Literal), - ], - 'end_tag': [ - include('whitespace'), - (r'(>)', popstate_tag_callback), - (qname, Name.Tag), - ], - 'xmlspace_decl': [ - (r'\(:', Comment, 'comment'), - (r'preserve|strip', Keyword, '#pop'), - ], - 'declareordering': [ - (r'\(:', Comment, 'comment'), - include('whitespace'), - (r'ordered|unordered', Keyword, '#pop'), - ], - 'xqueryversion': [ - include('whitespace'), - (r'\(:', Comment, 'comment'), - (stringdouble, String.Double), - (stringsingle, String.Single), - (r'encoding', Keyword), - (r';', Punctuation, '#pop'), - ], - 'pragma': [ - (qname, Name.Variable, 'pragmacontents'), - ], - 'pragmacontents': [ - (r'#\)', Punctuation, 'operator'), - (u'\\t|\\r|\\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + - unirange(0x10000, 0x10ffff), Literal), - (r'(\s+)', Text), - ], - 'occurrenceindicator': [ - include('whitespace'), - (r'\(:', Comment, 'comment'), - (r'\*|\?|\+', Operator, 'operator'), - (r':=', Operator, 'root'), - default('operator'), - ], - 'option': [ - include('whitespace'), - (qname, Name.Variable, '#pop'), - ], - 'qname_braren': [ - include('whitespace'), - (r'(\{)', pushstate_operator_root_callback), - (r'(\()', Punctuation, 'root'), - ], - 'element_qname': [ - (qname, Name.Variable, 'root'), - ], - 'attribute_qname': [ - (qname, Name.Variable, 'root'), - ], - 'root': [ - include('whitespace'), - (r'\(:', Comment, 'comment'), - - # handle operator state - # order on numbers matters - handle most complex first - (r'\d+(\.\d*)?[eE][\+\-]?\d+', Number.Float, 'operator'), - (r'(\.\d+)[eE][\+\-]?\d+', Number.Float, 'operator'), - (r'(\.\d+|\d+\.\d*)', Number.Float, 'operator'), - (r'(\d+)', Number.Integer, 'operator'), - (r'(\.\.|\.|\))', Punctuation, 'operator'), - (r'(declare)(\s+)(construction)', - bygroups(Keyword, Text, Keyword), 'operator'), - (r'(declare)(\s+)(default)(\s+)(order)', - bygroups(Keyword, Text, Keyword, Text, Keyword), 'operator'), - (ncname + ':\*', Name, 'operator'), - ('\*:'+ncname, Name.Tag, 'operator'), - ('\*', Name.Tag, 'operator'), - (stringdouble, String.Double, 'operator'), - (stringsingle, String.Single, 'operator'), - - (r'(\})', popstate_callback), - - #NAMESPACE DECL - (r'(declare)(\s+)(default)(\s+)(collation)', - bygroups(Keyword, Text, Keyword, Text, Keyword)), - (r'(module|declare)(\s+)(namespace)', - bygroups(Keyword, Text, Keyword), 'namespacedecl'), - (r'(declare)(\s+)(base-uri)', - bygroups(Keyword, Text, Keyword), 'namespacedecl'), - - #NAMESPACE KEYWORD - (r'(declare)(\s+)(default)(\s+)(element|function)', - bygroups(Keyword, Text, Keyword, Text, Keyword), 'namespacekeyword'), - (r'(import)(\s+)(schema|module)', - bygroups(Keyword.Pseudo, Text, Keyword.Pseudo), 'namespacekeyword'), - (r'(declare)(\s+)(copy-namespaces)', - bygroups(Keyword, Text, Keyword), 'namespacekeyword'), - - #VARNAMEs - (r'(for|let|some|every)(\s+)(\$)', - bygroups(Keyword, Text, Name.Variable), 'varname'), - (r'\$', Name.Variable, 'varname'), - (r'(declare)(\s+)(variable)(\s+)(\$)', - bygroups(Keyword, Text, Keyword, Text, Name.Variable), 'varname'), - - #ITEMTYPE - (r'(\))(\s+)(as)', bygroups(Operator, Text, Keyword), 'itemtype'), - - (r'(element|attribute|schema-element|schema-attribute|comment|' - r'text|node|document-node|empty-sequence)(\s+)(\()', - pushstate_operator_kindtest_callback), - - (r'(processing-instruction)(\s+)(\()', - pushstate_operator_kindtestforpi_callback), - - (r'(<!--)', pushstate_operator_xmlcomment_callback), - - (r'(<\?)', pushstate_operator_processing_instruction_callback), - - (r'(<!\[CDATA\[)', pushstate_operator_cdata_section_callback), - - # (r'</', Name.Tag, 'end_tag'), - (r'(<)', pushstate_operator_starttag_callback), - - (r'(declare)(\s+)(boundary-space)', - bygroups(Keyword, Text, Keyword), 'xmlspace_decl'), - - (r'(validate)(\s+)(lax|strict)', - pushstate_operator_root_validate_withmode), - (r'(validate)(\s*)(\{)', pushstate_operator_root_validate), - (r'(typeswitch)(\s*)(\()', bygroups(Keyword, Text, Punctuation)), - (r'(element|attribute)(\s*)(\{)', - pushstate_operator_root_construct_callback), - - (r'(document|text|processing-instruction|comment)(\s*)(\{)', - pushstate_operator_root_construct_callback), - #ATTRIBUTE - (r'(attribute)(\s+)(?=' + qname + r')', - bygroups(Keyword, Text), 'attribute_qname'), - #ELEMENT - (r'(element)(\s+)(?=' +qname+ r')', - bygroups(Keyword, Text), 'element_qname'), - #PROCESSING_INSTRUCTION - (r'(processing-instruction)(\s+)(' + ncname + r')(\s*)(\{)', - bygroups(Keyword, Text, Name.Variable, Text, Punctuation), - 'operator'), - - (r'(declare|define)(\s+)(function)', - bygroups(Keyword, Text, Keyword)), - - (r'(\{)', pushstate_operator_root_callback), - - (r'(unordered|ordered)(\s*)(\{)', - pushstate_operator_order_callback), - - (r'(declare)(\s+)(ordering)', - bygroups(Keyword, Text, Keyword), 'declareordering'), - - (r'(xquery)(\s+)(version)', - bygroups(Keyword.Pseudo, Text, Keyword.Pseudo), 'xqueryversion'), - - (r'(\(#)', Punctuation, 'pragma'), - - # sometimes return can occur in root state - (r'return', Keyword), - - (r'(declare)(\s+)(option)', bygroups(Keyword, Text, Keyword), - 'option'), - - #URI LITERALS - single and double quoted - (r'(at)(\s+)('+stringdouble+')', String.Double, 'namespacedecl'), - (r'(at)(\s+)('+stringsingle+')', String.Single, 'namespacedecl'), - - (r'(ancestor-or-self|ancestor|attribute|child|descendant-or-self)(::)', - bygroups(Keyword, Punctuation)), - (r'(descendant|following-sibling|following|parent|preceding-sibling' - r'|preceding|self)(::)', bygroups(Keyword, Punctuation)), - - (r'(if)(\s*)(\()', bygroups(Keyword, Text, Punctuation)), - - (r'then|else', Keyword), - - # ML specific - (r'(try)(\s*)', bygroups(Keyword, Text), 'root'), - (r'(catch)(\s*)(\()(\$)', - bygroups(Keyword, Text, Punctuation, Name.Variable), 'varname'), - - (r'(@'+qname+')', Name.Attribute), - (r'(@'+ncname+')', Name.Attribute), - (r'@\*:'+ncname, Name.Attribute), - (r'(@)', Name.Attribute), - - (r'//|/|\+|-|;|,|\(|\)', Punctuation), - - # STANDALONE QNAMES - (qname + r'(?=\s*{)', Name.Tag, 'qname_braren'), - (qname + r'(?=\s*\([^:])', Name.Function, 'qname_braren'), - (qname, Name.Tag, 'operator'), - ] - } - - -class DartLexer(RegexLexer): - """ - For `Dart <http://dartlang.org/>`_ source code. - - .. versionadded:: 1.5 - """ - - name = 'Dart' - aliases = ['dart'] - filenames = ['*.dart'] - mimetypes = ['text/x-dart'] - - flags = re.MULTILINE | re.DOTALL - - tokens = { - 'root': [ - include('string_literal'), - (r'#!(.*?)$', Comment.Preproc), - (r'\b(import|export)\b', Keyword, 'import_decl'), - (r'\b(library|source|part of|part)\b', Keyword), - (r'[^\S\n]+', Text), - (r'//.*?\n', Comment.Single), - (r'/\*.*?\*/', Comment.Multiline), - (r'\b(class)\b(\s+)', - bygroups(Keyword.Declaration, Text), 'class'), - (r'\b(assert|break|case|catch|continue|default|do|else|finally|for|' - r'if|in|is|new|return|super|switch|this|throw|try|while)\b', - Keyword), - (r'\b(abstract|const|extends|factory|final|get|implements|' - r'native|operator|set|static|typedef|var)\b', Keyword.Declaration), - (r'\b(bool|double|Dynamic|int|num|Object|String|void)\b', Keyword.Type), - (r'\b(false|null|true)\b', Keyword.Constant), - (r'[~!%^&*+=|?:<>/-]|as\b', Operator), - (r'[a-zA-Z_$]\w*:', Name.Label), - (r'[a-zA-Z_$]\w*', Name), - (r'[(){}\[\],.;]', Punctuation), - (r'0[xX][0-9a-fA-F]+', Number.Hex), - # DIGIT+ (‘.’ DIGIT*)? EXPONENT? - (r'\d+(\.\d*)?([eE][+-]?\d+)?', Number), - (r'\.\d+([eE][+-]?\d+)?', Number), # ‘.’ DIGIT+ EXPONENT? - (r'\n', Text) - # pseudo-keyword negate intentionally left out - ], - 'class': [ - (r'[a-zA-Z_$]\w*', Name.Class, '#pop') - ], - 'import_decl': [ - include('string_literal'), - (r'\s+', Text), - (r'\b(as|show|hide)\b', Keyword), - (r'[a-zA-Z_$]\w*', Name), - (r'\,', Punctuation), - (r'\;', Punctuation, '#pop') - ], - 'string_literal': [ - # Raw strings. - (r'r"""([\s|\S]*?)"""', String.Double), - (r"r'''([\s|\S]*?)'''", String.Single), - (r'r"(.*?)"', String.Double), - (r"r'(.*?)'", String.Single), - # Normal Strings. - (r'"""', String.Double, 'string_double_multiline'), - (r"'''", String.Single, 'string_single_multiline'), - (r'"', String.Double, 'string_double'), - (r"'", String.Single, 'string_single') - ], - 'string_common': [ - (r"\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u\{[0-9A-Fa-f]*\}|[a-z\'\"$\\])", - String.Escape), - (r'(\$)([a-zA-Z_]\w*)', bygroups(String.Interpol, Name)), - (r'(\$\{)(.*?)(\})', - bygroups(String.Interpol, using(this), String.Interpol)) - ], - 'string_double': [ - (r'"', String.Double, '#pop'), - (r'[^\"$\\\n]+', String.Double), - include('string_common'), - (r'\$+', String.Double) - ], - 'string_double_multiline': [ - (r'"""', String.Double, '#pop'), - (r'[^\"$\\]+', String.Double), - include('string_common'), - (r'(\$|\")+', String.Double) - ], - 'string_single': [ - (r"'", String.Single, '#pop'), - (r"[^\'$\\\n]+", String.Single), - include('string_common'), - (r'\$+', String.Single) - ], - 'string_single_multiline': [ - (r"'''", String.Single, '#pop'), - (r'[^\'$\\]+', String.Single), - include('string_common'), - (r'(\$|\')+', String.Single) - ] - } - - -class TypeScriptLexer(RegexLexer): - """ - For `TypeScript <http://typescriptlang.org/>`_ source code. - - .. versionadded:: 1.6 - """ - - name = 'TypeScript' - aliases = ['ts'] - filenames = ['*.ts'] - mimetypes = ['text/x-typescript'] - - flags = re.DOTALL - tokens = { - 'commentsandwhitespace': [ - (r'\s+', Text), - (r'<!--', Comment), - (r'//.*?\n', Comment.Single), - (r'/\*.*?\*/', Comment.Multiline) - ], - 'slashstartsregex': [ - include('commentsandwhitespace'), - (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' - r'([gim]+\b|\B)', String.Regex, '#pop'), - (r'(?=/)', Text, ('#pop', 'badregex')), - default('#pop') - ], - 'badregex': [ - (r'\n', Text, '#pop') - ], - 'root': [ - (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), - include('commentsandwhitespace'), - (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' - r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'), - (r'[{(\[;,]', Punctuation, 'slashstartsregex'), - (r'[})\].]', Punctuation), - (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' - r'throw|try|catch|finally|new|delete|typeof|instanceof|void|' - r'this)\b', Keyword, 'slashstartsregex'), - (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), - (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' - r'extends|final|float|goto|implements|import|int|interface|long|native|' - r'package|private|protected|public|short|static|super|synchronized|throws|' - r'transient|volatile)\b', Keyword.Reserved), - (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), - (r'(Array|Boolean|Date|Error|Function|Math|netscape|' - r'Number|Object|Packages|RegExp|String|sun|decodeURI|' - r'decodeURIComponent|encodeURI|encodeURIComponent|' - r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' - r'window)\b', Name.Builtin), - # Match stuff like: module name {...} - (r'\b(module)(\s*)(\s*[\w?.$][\w?.$]*)(\s*)', - bygroups(Keyword.Reserved, Text, Name.Other, Text), 'slashstartsregex'), - # Match variable type keywords - (r'\b(string|bool|number)\b', Keyword.Type), - # Match stuff like: constructor - (r'\b(constructor|declare|interface|as|AS)\b', Keyword.Reserved), - # Match stuff like: super(argument, list) - (r'(super)(\s*)(\([a-zA-Z0-9,_?.$\s]+\s*\))', - bygroups(Keyword.Reserved, Text), 'slashstartsregex'), - # Match stuff like: function() {...} - (r'([a-zA-Z_?.$][\w?.$]*)\(\) \{', Name.Other, 'slashstartsregex'), - # Match stuff like: (function: return type) - (r'([\w?.$][\w?.$]*)(\s*:\s*)([\w?.$][\w?.$]*)', - bygroups(Name.Other, Text, Keyword.Type)), - (r'[$a-zA-Z_]\w*', Name.Other), - (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), - (r'0x[0-9a-fA-F]+', Number.Hex), - (r'[0-9]+', Number.Integer), - (r'"(\\\\|\\"|[^"])*"', String.Double), - (r"'(\\\\|\\'|[^'])*'", String.Single), - ] - } - - -class LassoLexer(RegexLexer): - """ - For `Lasso <http://www.lassosoft.com/>`_ source code, covering both Lasso 9 - syntax and LassoScript for Lasso 8.6 and earlier. For Lasso embedded in - HTML, use the `LassoHtmlLexer`. - - Additional options accepted: - - `builtinshighlighting` - If given and ``True``, highlight builtin types, traits, methods, and - members (default: ``True``). - `requiredelimiters` - If given and ``True``, only highlight code between delimiters as Lasso - (default: ``False``). - - .. versionadded:: 1.6 - """ - - name = 'Lasso' - aliases = ['lasso', 'lassoscript'] - filenames = ['*.lasso', '*.lasso[89]'] - alias_filenames = ['*.incl', '*.inc', '*.las'] - mimetypes = ['text/x-lasso'] - flags = re.IGNORECASE | re.DOTALL | re.MULTILINE - - tokens = { - 'root': [ - (r'^#!.+lasso9\b', Comment.Preproc, 'lasso'), - (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'), - (r'\[noprocess\]', Comment.Preproc, ('delimiters', 'noprocess')), - (r'\[', Comment.Preproc, ('delimiters', 'squarebrackets')), - (r'<\?(LassoScript|lasso|=)', Comment.Preproc, - ('delimiters', 'anglebrackets')), - (r'<(!--.*?-->)?', Other, 'delimiters'), - (r'\s+', Other), - default(('delimiters', 'lassofile')), - ], - 'delimiters': [ - (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'), - (r'\[noprocess\]', Comment.Preproc, 'noprocess'), - (r'\[', Comment.Preproc, 'squarebrackets'), - (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'), - (r'<(!--.*?-->)?', Other), - (r'[^[<]+', Other), - ], - 'nosquarebrackets': [ - (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'), - (r'<', Other), - (r'[^<]+', Other), - ], - 'noprocess': [ - (r'\[/noprocess\]', Comment.Preproc, '#pop'), - (r'\[', Other), - (r'[^[]', Other), - ], - 'squarebrackets': [ - (r'\]', Comment.Preproc, '#pop'), - include('lasso'), - ], - 'anglebrackets': [ - (r'\?>', Comment.Preproc, '#pop'), - include('lasso'), - ], - 'lassofile': [ - (r'\]|\?>', Comment.Preproc, '#pop'), - include('lasso'), - ], - 'whitespacecomments': [ - (r'\s+', Text), - (r'//.*?\n', Comment.Single), - (r'/\*\*!.*?\*/', String.Doc), - (r'/\*.*?\*/', Comment.Multiline), - ], - 'lasso': [ - # whitespace/comments - include('whitespacecomments'), - - # literals - (r'\d*\.\d+(e[+-]?\d+)?', Number.Float), - (r'0x[\da-f]+', Number.Hex), - (r'\d+', Number.Integer), - (r'([+-]?)(infinity|NaN)\b', bygroups(Operator, Number)), - (r"'", String.Single, 'singlestring'), - (r'"', String.Double, 'doublestring'), - (r'`[^`]*`', String.Backtick), - - # names - (r'\$[a-z_][\w.]*', Name.Variable), - (r'#([a-z_][\w.]*|\d+)', Name.Variable.Instance), - (r"(\.)('[a-z_][\w.]*')", - bygroups(Name.Builtin.Pseudo, Name.Variable.Class)), - (r"(self)(\s*->\s*)('[a-z_][\w.]*')", - bygroups(Name.Builtin.Pseudo, Operator, Name.Variable.Class)), - (r'(\.\.?)([a-z_][\w.]*(=(?!=))?)', - bygroups(Name.Builtin.Pseudo, Name.Other.Member)), - (r'(->\\?\s*|&\s*)([a-z_][\w.]*(=(?!=))?)', - bygroups(Operator, Name.Other.Member)), - (r'(self|inherited)\b', Name.Builtin.Pseudo), - (r'-[a-z_][\w.]*', Name.Attribute), - (r'::\s*[a-z_][\w.]*', Name.Label), - (r'(error_(code|msg)_\w+|Error_AddError|Error_ColumnRestriction|' - r'Error_DatabaseConnectionUnavailable|Error_DatabaseTimeout|' - r'Error_DeleteError|Error_FieldRestriction|Error_FileNotFound|' - r'Error_InvalidDatabase|Error_InvalidPassword|' - r'Error_InvalidUsername|Error_ModuleNotFound|' - r'Error_NoError|Error_NoPermission|Error_OutOfMemory|' - r'Error_ReqColumnMissing|Error_ReqFieldMissing|' - r'Error_RequiredColumnMissing|Error_RequiredFieldMissing|' - r'Error_UpdateError)\b', Name.Exception), - - # definitions - (r'(define)(\s+)([a-z_][\w.]*)(\s*=>\s*)(type|trait|thread)\b', - bygroups(Keyword.Declaration, Text, Name.Class, Operator, Keyword)), - (r'(define)(\s+)([a-z_][\w.]*)(\s*->\s*)([a-z_][\w.]*=?|[-+*/%])', - bygroups(Keyword.Declaration, Text, Name.Class, Operator, - Name.Function), 'signature'), - (r'(define)(\s+)([a-z_][\w.]*)', - bygroups(Keyword.Declaration, Text, Name.Function), 'signature'), - (r'(public|protected|private|provide)(\s+)(([a-z_][\w.]*=?|[-+*/%])' - r'(?=\s*\())', bygroups(Keyword, Text, Name.Function), - 'signature'), - (r'(public|protected|private|provide)(\s+)([a-z_][\w.]*)', - bygroups(Keyword, Text, Name.Function)), - - # keywords - (r'(true|false|none|minimal|full|all|void)\b', Keyword.Constant), - (r'(local|var|variable|global|data(?=\s))\b', Keyword.Declaration), - (r'(array|date|decimal|duration|integer|map|pair|string|tag|xml|' - r'null|bytes|list|queue|set|stack|staticarray|tie)\b', Keyword.Type), - (r'([a-z_][\w.]*)(\s+)(in)\b', bygroups(Name, Text, Keyword)), - (r'(let|into)(\s+)([a-z_][\w.]*)', bygroups(Keyword, Text, Name)), - (r'require\b', Keyword, 'requiresection'), - (r'(/?)(Namespace_Using)\b', bygroups(Punctuation, Keyword.Namespace)), - (r'(/?)(Cache|Database_Names|Database_SchemaNames|' - r'Database_TableNames|Define_Tag|Define_Type|Email_Batch|' - r'Encode_Set|HTML_Comment|Handle|Handle_Error|Header|If|Inline|' - r'Iterate|LJAX_Target|Link|Link_CurrentAction|Link_CurrentGroup|' - r'Link_CurrentRecord|Link_Detail|Link_FirstGroup|' - r'Link_FirstRecord|Link_LastGroup|Link_LastRecord|Link_NextGroup|' - r'Link_NextRecord|Link_PrevGroup|Link_PrevRecord|Log|Loop|' - r'NoProcess|Output_None|Portal|Private|Protect|Records|Referer|' - r'Referrer|Repeating|ResultSet|Rows|Search_Args|Search_Arguments|' - r'Select|Sort_Args|Sort_Arguments|Thread_Atomic|Value_List|While|' - r'Abort|Case|Else|If_Empty|If_False|If_Null|If_True|Loop_Abort|' - r'Loop_Continue|Loop_Count|Params|Params_Up|Return|Return_Value|' - r'Run_Children|SOAP_DefineTag|SOAP_LastRequest|SOAP_LastResponse|' - r'Tag_Name|ascending|average|by|define|descending|do|equals|' - r'frozen|group|handle_failure|import|in|into|join|let|match|max|' - r'min|on|order|parent|protected|provide|public|require|returnhome|' - r'skip|split_thread|sum|take|thread|to|trait|type|where|with|' - r'yield|yieldhome)\b', - bygroups(Punctuation, Keyword)), - - # other - (r',', Punctuation, 'commamember'), - (r'(and|or|not)\b', Operator.Word), - (r'([a-z_][\w.]*)(\s*::\s*[a-z_][\w.]*)?(\s*=(?!=))', - bygroups(Name, Name.Label, Operator)), - (r'(/?)([\w.]+)', bygroups(Punctuation, Name.Other)), - (r'(=)(n?bw|n?ew|n?cn|lte?|gte?|n?eq|n?rx|ft)\b', - bygroups(Operator, Operator.Word)), - (r':=|[-+*/%=<>&|!?\\]+', Operator), - (r'[{}():;,@^]', Punctuation), - ], - 'singlestring': [ - (r"'", String.Single, '#pop'), - (r"[^'\\]+", String.Single), - include('escape'), - (r"\\", String.Single), - ], - 'doublestring': [ - (r'"', String.Double, '#pop'), - (r'[^"\\]+', String.Double), - include('escape'), - (r'\\', String.Double), - ], - 'escape': [ - (r'\\(U[\da-f]{8}|u[\da-f]{4}|x[\da-f]{1,2}|[0-7]{1,3}|:[^:]+:|' - r'[abefnrtv?\"\'\\]|$)', String.Escape), - ], - 'signature': [ - (r'=>', Operator, '#pop'), - (r'\)', Punctuation, '#pop'), - (r'[(,]', Punctuation, 'parameter'), - include('lasso'), - ], - 'parameter': [ - (r'\)', Punctuation, '#pop'), - (r'-?[a-z_][\w.]*', Name.Attribute, '#pop'), - (r'\.\.\.', Name.Builtin.Pseudo), - include('lasso'), - ], - 'requiresection': [ - (r'(([a-z_][\w.]*=?|[-+*/%])(?=\s*\())', Name, 'requiresignature'), - (r'(([a-z_][\w.]*=?|[-+*/%])(?=(\s*::\s*[\w.]+)?\s*,))', Name), - (r'[a-z_][\w.]*=?|[-+*/%]', Name, '#pop'), - (r'::\s*[a-z_][\w.]*', Name.Label), - (r',', Punctuation), - include('whitespacecomments'), - ], - 'requiresignature': [ - (r'(\)(?=(\s*::\s*[\w.]+)?\s*,))', Punctuation, '#pop'), - (r'\)', Punctuation, '#pop:2'), - (r'-?[a-z_][\w.]*', Name.Attribute), - (r'::\s*[a-z_][\w.]*', Name.Label), - (r'\.\.\.', Name.Builtin.Pseudo), - (r'[(,]', Punctuation), - include('whitespacecomments'), - ], - 'commamember': [ - (r'(([a-z_][\w.]*=?|[-+*/%])' - r'(?=\s*(\(([^()]*\([^()]*\))*[^)]*\)\s*)?(::[\w.\s]+)?=>))', - Name.Function, 'signature'), - include('whitespacecomments'), - default('#pop'), - ], - } - - def __init__(self, **options): - self.builtinshighlighting = get_bool_opt( - options, 'builtinshighlighting', True) - self.requiredelimiters = get_bool_opt( - options, 'requiredelimiters', False) - - self._builtins = set() - self._members = set() - if self.builtinshighlighting: - from pygments.lexers._lassobuiltins import BUILTINS, MEMBERS - for key, value in iteritems(BUILTINS): - self._builtins.update(value) - for key, value in iteritems(MEMBERS): - self._members.update(value) - RegexLexer.__init__(self, **options) - - def get_tokens_unprocessed(self, text): - stack = ['root'] - if self.requiredelimiters: - stack.append('delimiters') - for index, token, value in \ - RegexLexer.get_tokens_unprocessed(self, text, stack): - if (token is Name.Other and value.lower() in self._builtins or - token is Name.Other.Member and - value.lower().rstrip('=') in self._members): - yield index, Name.Builtin, value - continue - yield index, token, value - - def analyse_text(text): - rv = 0.0 - if 'bin/lasso9' in text: - rv += 0.8 - if re.search(r'<\?(=|lasso)|\A\[', text, re.I): - rv += 0.4 - if re.search(r'local\(', text, re.I): - rv += 0.4 - if '?>' in text: - rv += 0.1 - return rv - - -class QmlLexer(RegexLexer): - """ - For QML files. See http://doc.qt.digia.com/4.7/qdeclarativeintroduction.html. - - .. versionadded:: 1.6 - """ - - # QML is based on javascript, so much of this is taken from the - # JavascriptLexer above. - - name = 'QML' - aliases = ['qml'] - filenames = ['*.qml',] - mimetypes = [ 'application/x-qml',] - - - # pasted from JavascriptLexer, with some additions - flags = re.DOTALL - tokens = { - 'commentsandwhitespace': [ - (r'\s+', Text), - (r'<!--', Comment), - (r'//.*?\n', Comment.Single), - (r'/\*.*?\*/', Comment.Multiline) - ], - 'slashstartsregex': [ - include('commentsandwhitespace'), - (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' - r'([gim]+\b|\B)', String.Regex, '#pop'), - (r'(?=/)', Text, ('#pop', 'badregex')), - default('#pop') - ], - 'badregex': [ - (r'\n', Text, '#pop') - ], - 'root' : [ - (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), - include('commentsandwhitespace'), - (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' - r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'), - (r'[{(\[;,]', Punctuation, 'slashstartsregex'), - (r'[})\].]', Punctuation), - - # QML insertions - (r'\bid\s*:\s*[A-Za-z][_A-Za-z.0-9]*',Keyword.Declaration, - 'slashstartsregex'), - (r'\b[A-Za-z][_A-Za-z.0-9]*\s*:',Keyword, 'slashstartsregex'), - - # the rest from JavascriptLexer - (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' - r'throw|try|catch|finally|new|delete|typeof|instanceof|void|' - r'this)\b', Keyword, 'slashstartsregex'), - (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), - (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' - r'extends|final|float|goto|implements|import|int|interface|long|native|' - r'package|private|protected|public|short|static|super|synchronized|throws|' - r'transient|volatile)\b', Keyword.Reserved), - (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), - (r'(Array|Boolean|Date|Error|Function|Math|netscape|' - r'Number|Object|Packages|RegExp|String|sun|decodeURI|' - r'decodeURIComponent|encodeURI|encodeURIComponent|' - r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' - r'window)\b', Name.Builtin), - (r'[$a-zA-Z_]\w*', Name.Other), - (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), - (r'0x[0-9a-fA-F]+', Number.Hex), - (r'[0-9]+', Number.Integer), - (r'"(\\\\|\\"|[^"])*"', String.Double), - (r"'(\\\\|\\'|[^'])*'", String.Single), - ] - } - - -class CirruLexer(RegexLexer): - """ - Syntax rules of Cirru can be found at: - http://grammar.cirru.org/ - - * using ``()`` to markup blocks, but limited in the same line - * using ``""`` to markup strings, allow ``\`` to escape - * using ``$`` as a shorthand for ``()`` till indentation end or ``)`` - * using indentations for create nesting - - .. versionadded:: 2.0 - """ - - name = 'Cirru' - aliases = ['cirru'] - filenames = ['*.cirru', '*.cr'] - mimetypes = ['text/x-cirru'] - flags = re.MULTILINE - - tokens = { - 'string': [ - (r'[^"\\\n]', String), - (r'\\', String.Escape, 'escape'), - (r'"', String, '#pop'), - ], - 'escape': [ - (r'.', String.Escape, '#pop'), - ], - 'function': [ - (r'[\w-][^\s\(\)\"]*', Name.Function, '#pop'), - (r'\)', Operator, '#pop'), - (r'(?=\n)', Text, '#pop'), - (r'\(', Operator, '#push'), - (r'"', String, ('#pop', 'string')), - (r'\s+', Text.Whitespace), - (r'\,', Operator, '#pop'), - ], - 'line': [ - (r'^\B', Text.Whitespace, 'function'), - (r'\$', Operator, 'function'), - (r'\(', Operator, 'function'), - (r'\)', Operator), - (r'(?=\n)', Text, '#pop'), - (r'\n', Text, '#pop'), - (r'"', String, 'string'), - (r'\s+', Text.Whitespace), - (r'[\d\.]+', Number), - (r'[\w-][^\"\(\)\s]*', Name.Variable), - (r'--', Comment.Single) - ], - 'root': [ - (r'^\s*', Text.Whitespace, ('line', 'function')), - (r'^\s+$', Text.Whitespace), - ] - } - - -class MaskLexer(RegexLexer): - """ - For `Mask <http://github.com/atmajs/MaskJS>`__ markup. - - .. versionadded:: 2.0 - """ - name = 'Mask' - aliases = ['mask'] - filenames = ['*.mask'] - mimetypes = ['text/x-mask'] - - flags = re.MULTILINE | re.IGNORECASE | re.DOTALL - tokens = { - 'root': [ - (r'\s+', Text), - (r'//.*?\n', Comment.Single), - (r'/\*.*?\*/', Comment.Multiline), - (r'[\{\};>]', Punctuation), - (r"'''", String, 'string-trpl-single'), - (r'"""', String, 'string-trpl-double'), - (r"'", String, 'string-single'), - (r'"', String, 'string-double'), - (r'([\w-]+)', Name.Tag, 'node'), - (r'([^\.#;{>\s]+)', Name.Class, 'node'), - (r'(#[\w-]+)', Name.Function, 'node'), - (r'(\.[\w-]+)', Name.Variable.Class, 'node') - ], - 'string-base': [ - (r'\\.', String.Escape), - (r'~\[', String.Interpol, 'interpolation'), - (r'.', String.Single), - ], - 'string-single':[ - (r"'", String.Single, '#pop'), - include('string-base') - ], - 'string-double':[ - (r'"', String.Single, '#pop'), - include('string-base') - ], - 'string-trpl-single':[ - (r"'''", String.Single, '#pop'), - include('string-base') - ], - 'string-trpl-double':[ - (r'"""', String.Single, '#pop'), - include('string-base') - ], - 'interpolation': [ - (r'\]', String.Interpol, '#pop'), - (r'\s*:', String.Interpol, 'expression'), - (r'\s*\w+:', Name.Other), - (r'[^\]]+', String.Interpol) - ], - 'expression': [ - (r'[^\]]+', using(JavascriptLexer), '#pop') - ], - 'node': [ - (r'\s+', Text), - (r'\.', Name.Variable.Class, 'node-class'), - (r'\#', Name.Function, 'node-id'), - (r'style[ \t]*=', Name.Attribute, 'node-attr-style-value'), - (r'[\w:-]+[ \t]*=', Name.Attribute, 'node-attr-value'), - (r'[\w:-]+', Name.Attribute), - (r'[>{;]', Punctuation, '#pop') - ], - 'node-class': [ - (r'[\w-]+', Name.Variable.Class), - (r'~\[', String.Interpol, 'interpolation'), - default('#pop') - ], - 'node-id': [ - (r'[\w-]+', Name.Function), - (r'~\[', String.Interpol, 'interpolation'), - default('#pop') - ], - 'node-attr-value':[ - (r'\s+', Text), - (r'\w+', Name.Variable, '#pop'), - (r"'", String, 'string-single-pop2'), - (r'"', String, 'string-double-pop2'), - default('#pop') - ], - 'node-attr-style-value':[ - (r'\s+', Text), - (r"'", String.Single, 'css-single-end'), - (r'"', String.Single, 'css-double-end'), - include('node-attr-value') - ], - 'css-base': [ - (r'\s+', Text), - (r";", Punctuation), - (r"[\w\-]+\s*:", Name.Builtin) - ], - 'css-single-end': [ - include('css-base'), - (r"'", String.Single, '#pop:2'), - (r"[^;']+", Name.Entity) - ], - 'css-double-end': [ - include('css-base'), - (r'"', String.Single, '#pop:2'), - (r"[^;\"]+", Name.Entity) - ], - 'string-single-pop2':[ - (r"'", String.Single, '#pop:2'), - include('string-base') - ], - 'string-double-pop2':[ - (r'"', String.Single, '#pop:2'), - include('string-base') - ], - } - - -class ZephirLexer(RegexLexer): - """ - For `Zephir language <http://zephir-lang.com/>`_ source code. - - Zephir is a compiled high level language aimed - to the creation of C-extensions for PHP. - - .. versionadded:: 2.0 - """ - - name = 'Zephir' - aliases = ['zephir'] - filenames = ['*.zep'] - - zephir_keywords = [ 'fetch', 'echo', 'isset', 'empty'] - zephir_type = [ 'bit', 'bits' , 'string' ] - - flags = re.DOTALL | re.MULTILINE - - tokens = { - 'commentsandwhitespace': [ - (r'\s+', Text), - (r'//.*?\n', Comment.Single), - (r'/\*.*?\*/', Comment.Multiline) - ], - 'slashstartsregex': [ - include('commentsandwhitespace'), - (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' - r'([gim]+\b|\B)', String.Regex, '#pop'), - default('#pop') - ], - 'badregex': [ - (r'\n', Text, '#pop') - ], - 'root': [ - (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), - include('commentsandwhitespace'), - (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' - r'(<<|>>>?|==?|!=?|->|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'), - (r'[{(\[;,]', Punctuation, 'slashstartsregex'), - (r'[})\].]', Punctuation), - (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|loop|' - r'require|inline|throw|try|catch|finally|new|delete|typeof|instanceof|void|' - r'namespace|use|extends|this|fetch|isset|unset|echo|fetch|likely|unlikely|' - r'empty)\b', Keyword, 'slashstartsregex'), - (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), - (r'(abstract|boolean|bool|char|class|const|double|enum|export|extends|final|' - r'native|goto|implements|import|int|string|interface|long|ulong|char|uchar|' - r'float|unsigned|private|protected|public|short|static|self|throws|reverse|' - r'transient|volatile)\b', Keyword.Reserved), - (r'(true|false|null|undefined)\b', Keyword.Constant), - (r'(Array|Boolean|Date|_REQUEST|_COOKIE|_SESSION|' - r'_GET|_POST|_SERVER|this|stdClass|range|count|iterator|' - r'window)\b', Name.Builtin), - (r'[$a-zA-Z_][\w\\]*', Name.Other), - (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), - (r'0x[0-9a-fA-F]+', Number.Hex), - (r'[0-9]+', Number.Integer), - (r'"(\\\\|\\"|[^"])*"', String.Double), - (r"'(\\\\|\\'|[^'])*'", String.Single), - ] - } - -class SlimLexer(ExtendedRegexLexer): - """ - For Slim markup. - """ - - name = 'Slim' - aliases = ['slim'] - filenames = ['*.slim'] - mimetypes = ['text/x-slim'] - - flags = re.IGNORECASE - _dot = r'(?: \|\n(?=.* \|)|.)' - tokens = { - 'root': [ - (r'[ \t]*\n', Text), - (r'[ \t]*', _indentation), - ], - - 'css': [ - (r'\.[\w:-]+', Name.Class, 'tag'), - (r'\#[\w:-]+', Name.Function, 'tag'), - ], - - 'eval-or-plain': [ - (r'([ \t]*==?)(.*\n)', - bygroups(Punctuation, using(RubyLexer)), - 'root'), - (r'[ \t]+[\w:-]+(?=[=])', Name.Attribute, 'html-attributes'), - (r'', Text, 'plain'), - ], - - 'content': [ - include('css'), - (r'[\w:-]+:[ \t]*\n', Text, 'plain'), - (r'(-)(.*\n)', - bygroups(Punctuation, using(RubyLexer)), - '#pop'), - (r'\|' + _dot + r'*\n', _starts_block(Text, 'plain'), '#pop'), - (r'/' + _dot + r'*\n', _starts_block(Comment.Preproc, 'slim-comment-block'), '#pop'), - (r'[\w:-]+', Name.Tag, 'tag'), - include('eval-or-plain'), - ], - - 'tag': [ - include('css'), - (r'[<>]{1,2}(?=[ \t=])', Punctuation), - (r'[ \t]+\n', Punctuation, '#pop:2'), - include('eval-or-plain'), - ], - - 'plain': [ - (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text), - (r'(#\{)(.*?)(\})', - bygroups(String.Interpol, using(RubyLexer), String.Interpol)), - (r'\n', Text, 'root'), - ], - - 'html-attributes': [ - (r'=', Punctuation), - (r'"[^\"]+"', using(RubyLexer), 'tag'), - (r'\'[^\']+\'', using(RubyLexer), 'tag'), - (r'[\w]+', Text, 'tag'), - ], - - 'slim-comment-block': [ - (_dot + '+', Comment.Preproc), - (r'\n', Text, 'root'), - ], - } +__all__ = [] diff --git a/pygments/lexers/webmisc.py b/pygments/lexers/webmisc.py new file mode 100644 index 00000000..5c6f2e86 --- /dev/null +++ b/pygments/lexers/webmisc.py @@ -0,0 +1,920 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.webmisc + ~~~~~~~~~~~~~~~~~~~~~~~ + + Lexers for misc. web stuff. + + :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import RegexLexer, ExtendedRegexLexer, include, bygroups, \ + default, using +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Punctuation, Literal +from pygments.util import unirange + +from pygments.lexers.css import _indentation, _starts_block +from pygments.lexers.html import HtmlLexer +from pygments.lexers.javascript import JavascriptLexer +from pygments.lexers.ruby import RubyLexer + +__all__ = ['DuelLexer', 'SlimLexer', 'XQueryLexer', 'QmlLexer', 'CirruLexer'] + + +class DuelLexer(RegexLexer): + """ + Lexer for Duel Views Engine (formerly JBST) markup with JavaScript code blocks. + See http://duelengine.org/. + See http://jsonml.org/jbst/. + + .. versionadded:: 1.4 + """ + + name = 'Duel' + aliases = ['duel', 'jbst', 'jsonml+bst'] + filenames = ['*.duel', '*.jbst'] + mimetypes = ['text/x-duel', 'text/x-jbst'] + + flags = re.DOTALL + + tokens = { + 'root': [ + (r'(<%[@=#!:]?)(.*?)(%>)', + bygroups(Name.Tag, using(JavascriptLexer), Name.Tag)), + (r'(<%\$)(.*?)(:)(.*?)(%>)', + bygroups(Name.Tag, Name.Function, Punctuation, String, Name.Tag)), + (r'(<%--)(.*?)(--%>)', + bygroups(Name.Tag, Comment.Multiline, Name.Tag)), + (r'(<script.*?>)(.*?)(</script>)', + bygroups(using(HtmlLexer), + using(JavascriptLexer), using(HtmlLexer))), + (r'(.+?)(?=<)', using(HtmlLexer)), + (r'.+', using(HtmlLexer)), + ], + } + + +class XQueryLexer(ExtendedRegexLexer): + """ + An XQuery lexer, parsing a stream and outputting the tokens needed to + highlight xquery code. + + .. versionadded:: 1.4 + """ + name = 'XQuery' + aliases = ['xquery', 'xqy', 'xq', 'xql', 'xqm'] + filenames = ['*.xqy', '*.xquery', '*.xq', '*.xql', '*.xqm'] + mimetypes = ['text/xquery', 'application/xquery'] + + xquery_parse_state = [] + + # FIX UNICODE LATER + # ncnamestartchar = ( + # ur"[A-Z]|_|[a-z]|[\u00C0-\u00D6]|[\u00D8-\u00F6]|[\u00F8-\u02FF]|" + # ur"[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|" + # ur"[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]|" + # ur"[\u10000-\uEFFFF]" + # ) + ncnamestartchar = r"(?:[A-Z]|_|[a-z])" + # FIX UNICODE LATER + # ncnamechar = ncnamestartchar + (ur"|-|\.|[0-9]|\u00B7|[\u0300-\u036F]|" + # ur"[\u203F-\u2040]") + ncnamechar = r"(?:" + ncnamestartchar + r"|-|\.|[0-9])" + ncname = "(?:%s+%s*)" % (ncnamestartchar, ncnamechar) + pitarget_namestartchar = r"(?:[A-KN-WY-Z]|_|:|[a-kn-wy-z])" + pitarget_namechar = r"(?:" + pitarget_namestartchar + r"|-|\.|[0-9])" + pitarget = "%s+%s*" % (pitarget_namestartchar, pitarget_namechar) + prefixedname = "%s:%s" % (ncname, ncname) + unprefixedname = ncname + qname = "(?:%s|%s)" % (prefixedname, unprefixedname) + + entityref = r'(?:&(?:lt|gt|amp|quot|apos|nbsp);)' + charref = r'(?:&#[0-9]+;|&#x[0-9a-fA-F]+;)' + + stringdouble = r'(?:"(?:' + entityref + r'|' + charref + r'|""|[^&"])*")' + stringsingle = r"(?:'(?:" + entityref + r"|" + charref + r"|''|[^&'])*')" + + # FIX UNICODE LATER + # elementcontentchar = (ur'\t|\r|\n|[\u0020-\u0025]|[\u0028-\u003b]|' + # ur'[\u003d-\u007a]|\u007c|[\u007e-\u007F]') + elementcontentchar = r'[A-Za-z]|\s|\d|[!"#$%\(\)\*\+,\-\./\:;=\?\@\[\\\]^_\'`\|~]' + # quotattrcontentchar = (ur'\t|\r|\n|[\u0020-\u0021]|[\u0023-\u0025]|' + # ur'[\u0027-\u003b]|[\u003d-\u007a]|\u007c|[\u007e-\u007F]') + quotattrcontentchar = r'[A-Za-z]|\s|\d|[!#$%\(\)\*\+,\-\./\:;=\?\@\[\\\]^_\'`\|~]' + # aposattrcontentchar = (ur'\t|\r|\n|[\u0020-\u0025]|[\u0028-\u003b]|' + # ur'[\u003d-\u007a]|\u007c|[\u007e-\u007F]') + aposattrcontentchar = r'[A-Za-z]|\s|\d|[!"#$%\(\)\*\+,\-\./\:;=\?\@\[\\\]^_`\|~]' + + # CHAR elements - fix the above elementcontentchar, quotattrcontentchar, + # aposattrcontentchar + # x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] + + flags = re.DOTALL | re.MULTILINE | re.UNICODE + + def punctuation_root_callback(lexer, match, ctx): + yield match.start(), Punctuation, match.group(1) + # transition to root always - don't pop off stack + ctx.stack = ['root'] + ctx.pos = match.end() + + def operator_root_callback(lexer, match, ctx): + yield match.start(), Operator, match.group(1) + # transition to root always - don't pop off stack + ctx.stack = ['root'] + ctx.pos = match.end() + + def popstate_tag_callback(lexer, match, ctx): + yield match.start(), Name.Tag, match.group(1) + ctx.stack.append(lexer.xquery_parse_state.pop()) + ctx.pos = match.end() + + def popstate_xmlcomment_callback(lexer, match, ctx): + yield match.start(), String.Doc, match.group(1) + ctx.stack.append(lexer.xquery_parse_state.pop()) + ctx.pos = match.end() + + def popstate_kindtest_callback(lexer, match, ctx): + yield match.start(), Punctuation, match.group(1) + next_state = lexer.xquery_parse_state.pop() + if next_state == 'occurrenceindicator': + if re.match("[?*+]+", match.group(2)): + yield match.start(), Punctuation, match.group(2) + ctx.stack.append('operator') + ctx.pos = match.end() + else: + ctx.stack.append('operator') + ctx.pos = match.end(1) + else: + ctx.stack.append(next_state) + ctx.pos = match.end(1) + + def popstate_callback(lexer, match, ctx): + yield match.start(), Punctuation, match.group(1) + # if we have run out of our state stack, pop whatever is on the pygments + # state stack + if len(lexer.xquery_parse_state) == 0: + ctx.stack.pop() + elif len(ctx.stack) > 1: + ctx.stack.append(lexer.xquery_parse_state.pop()) + else: + # i don't know if i'll need this, but in case, default back to root + ctx.stack = ['root'] + ctx.pos = match.end() + + def pushstate_element_content_starttag_callback(lexer, match, ctx): + yield match.start(), Name.Tag, match.group(1) + lexer.xquery_parse_state.append('element_content') + ctx.stack.append('start_tag') + ctx.pos = match.end() + + def pushstate_cdata_section_callback(lexer, match, ctx): + yield match.start(), String.Doc, match.group(1) + ctx.stack.append('cdata_section') + lexer.xquery_parse_state.append(ctx.state.pop) + ctx.pos = match.end() + + def pushstate_starttag_callback(lexer, match, ctx): + yield match.start(), Name.Tag, match.group(1) + lexer.xquery_parse_state.append(ctx.state.pop) + ctx.stack.append('start_tag') + ctx.pos = match.end() + + def pushstate_operator_order_callback(lexer, match, ctx): + yield match.start(), Keyword, match.group(1) + yield match.start(), Text, match.group(2) + yield match.start(), Punctuation, match.group(3) + ctx.stack = ['root'] + lexer.xquery_parse_state.append('operator') + ctx.pos = match.end() + + def pushstate_operator_root_validate(lexer, match, ctx): + yield match.start(), Keyword, match.group(1) + yield match.start(), Text, match.group(2) + yield match.start(), Punctuation, match.group(3) + ctx.stack = ['root'] + lexer.xquery_parse_state.append('operator') + ctx.pos = match.end() + + def pushstate_operator_root_validate_withmode(lexer, match, ctx): + yield match.start(), Keyword, match.group(1) + yield match.start(), Text, match.group(2) + yield match.start(), Keyword, match.group(3) + ctx.stack = ['root'] + lexer.xquery_parse_state.append('operator') + ctx.pos = match.end() + + def pushstate_operator_processing_instruction_callback(lexer, match, ctx): + yield match.start(), String.Doc, match.group(1) + ctx.stack.append('processing_instruction') + lexer.xquery_parse_state.append('operator') + ctx.pos = match.end() + + def pushstate_element_content_processing_instruction_callback(lexer, match, ctx): + yield match.start(), String.Doc, match.group(1) + ctx.stack.append('processing_instruction') + lexer.xquery_parse_state.append('element_content') + ctx.pos = match.end() + + def pushstate_element_content_cdata_section_callback(lexer, match, ctx): + yield match.start(), String.Doc, match.group(1) + ctx.stack.append('cdata_section') + lexer.xquery_parse_state.append('element_content') + ctx.pos = match.end() + + def pushstate_operator_cdata_section_callback(lexer, match, ctx): + yield match.start(), String.Doc, match.group(1) + ctx.stack.append('cdata_section') + lexer.xquery_parse_state.append('operator') + ctx.pos = match.end() + + def pushstate_element_content_xmlcomment_callback(lexer, match, ctx): + yield match.start(), String.Doc, match.group(1) + ctx.stack.append('xml_comment') + lexer.xquery_parse_state.append('element_content') + ctx.pos = match.end() + + def pushstate_operator_xmlcomment_callback(lexer, match, ctx): + yield match.start(), String.Doc, match.group(1) + ctx.stack.append('xml_comment') + lexer.xquery_parse_state.append('operator') + ctx.pos = match.end() + + def pushstate_kindtest_callback(lexer, match, ctx): + yield match.start(), Keyword, match.group(1) + yield match.start(), Text, match.group(2) + yield match.start(), Punctuation, match.group(3) + lexer.xquery_parse_state.append('kindtest') + ctx.stack.append('kindtest') + ctx.pos = match.end() + + def pushstate_operator_kindtestforpi_callback(lexer, match, ctx): + yield match.start(), Keyword, match.group(1) + yield match.start(), Text, match.group(2) + yield match.start(), Punctuation, match.group(3) + lexer.xquery_parse_state.append('operator') + ctx.stack.append('kindtestforpi') + ctx.pos = match.end() + + def pushstate_operator_kindtest_callback(lexer, match, ctx): + yield match.start(), Keyword, match.group(1) + yield match.start(), Text, match.group(2) + yield match.start(), Punctuation, match.group(3) + lexer.xquery_parse_state.append('operator') + ctx.stack.append('kindtest') + ctx.pos = match.end() + + def pushstate_occurrenceindicator_kindtest_callback(lexer, match, ctx): + yield match.start(), Name.Tag, match.group(1) + yield match.start(), Text, match.group(2) + yield match.start(), Punctuation, match.group(3) + lexer.xquery_parse_state.append('occurrenceindicator') + ctx.stack.append('kindtest') + ctx.pos = match.end() + + def pushstate_operator_starttag_callback(lexer, match, ctx): + yield match.start(), Name.Tag, match.group(1) + lexer.xquery_parse_state.append('operator') + ctx.stack.append('start_tag') + ctx.pos = match.end() + + def pushstate_operator_root_callback(lexer, match, ctx): + yield match.start(), Punctuation, match.group(1) + lexer.xquery_parse_state.append('operator') + ctx.stack = ['root'] + ctx.pos = match.end() + + def pushstate_operator_root_construct_callback(lexer, match, ctx): + yield match.start(), Keyword, match.group(1) + yield match.start(), Text, match.group(2) + yield match.start(), Punctuation, match.group(3) + lexer.xquery_parse_state.append('operator') + ctx.stack = ['root'] + ctx.pos = match.end() + + def pushstate_root_callback(lexer, match, ctx): + yield match.start(), Punctuation, match.group(1) + cur_state = ctx.stack.pop() + lexer.xquery_parse_state.append(cur_state) + ctx.stack = ['root'] + ctx.pos = match.end() + + def pushstate_operator_attribute_callback(lexer, match, ctx): + yield match.start(), Name.Attribute, match.group(1) + ctx.stack.append('operator') + ctx.pos = match.end() + + def pushstate_operator_callback(lexer, match, ctx): + yield match.start(), Keyword, match.group(1) + yield match.start(), Text, match.group(2) + yield match.start(), Punctuation, match.group(3) + lexer.xquery_parse_state.append('operator') + ctx.pos = match.end() + + tokens = { + 'comment': [ + # xquery comments + (r'(:\))', Comment, '#pop'), + (r'(\(:)', Comment, '#push'), + (r'[^:)]', Comment), + (r'([^:)]|:|\))', Comment), + ], + 'whitespace': [ + (r'\s+', Text), + ], + 'operator': [ + include('whitespace'), + (r'(\})', popstate_callback), + (r'\(:', Comment, 'comment'), + + (r'(\{)', pushstate_root_callback), + (r'then|else|external|at|div|except', Keyword, 'root'), + (r'order by', Keyword, 'root'), + (r'is|mod|order\s+by|stable\s+order\s+by', Keyword, 'root'), + (r'and|or', Operator.Word, 'root'), + (r'(eq|ge|gt|le|lt|ne|idiv|intersect|in)(?=\b)', + Operator.Word, 'root'), + (r'return|satisfies|to|union|where|preserve\s+strip', + Keyword, 'root'), + (r'(>=|>>|>|<=|<<|<|-|\*|!=|\+|\||:=|=)', + operator_root_callback), + (r'(::|;|\[|//|/|,)', + punctuation_root_callback), + (r'(castable|cast)(\s+)(as)\b', + bygroups(Keyword, Text, Keyword), 'singletype'), + (r'(instance)(\s+)(of)\b', + bygroups(Keyword, Text, Keyword), 'itemtype'), + (r'(treat)(\s+)(as)\b', + bygroups(Keyword, Text, Keyword), 'itemtype'), + (r'(case|as)\b', Keyword, 'itemtype'), + (r'(\))(\s*)(as)', + bygroups(Punctuation, Text, Keyword), 'itemtype'), + (r'\$', Name.Variable, 'varname'), + (r'(for|let)(\s+)(\$)', + bygroups(Keyword, Text, Name.Variable), 'varname'), + # (r'\)|\?|\]', Punctuation, '#push'), + (r'\)|\?|\]', Punctuation), + (r'(empty)(\s+)(greatest|least)', bygroups(Keyword, Text, Keyword)), + (r'ascending|descending|default', Keyword, '#push'), + (r'external', Keyword), + (r'collation', Keyword, 'uritooperator'), + # finally catch all string literals and stay in operator state + (stringdouble, String.Double), + (stringsingle, String.Single), + + (r'(catch)(\s*)', bygroups(Keyword, Text), 'root'), + ], + 'uritooperator': [ + (stringdouble, String.Double, '#pop'), + (stringsingle, String.Single, '#pop'), + ], + 'namespacedecl': [ + include('whitespace'), + (r'\(:', Comment, 'comment'), + (r'(at)(\s+)('+stringdouble+')', bygroups(Keyword, Text, String.Double)), + (r"(at)(\s+)("+stringsingle+')', bygroups(Keyword, Text, String.Single)), + (stringdouble, String.Double), + (stringsingle, String.Single), + (r',', Punctuation), + (r'=', Operator), + (r';', Punctuation, 'root'), + (ncname, Name.Namespace), + ], + 'namespacekeyword': [ + include('whitespace'), + (r'\(:', Comment, 'comment'), + (stringdouble, String.Double, 'namespacedecl'), + (stringsingle, String.Single, 'namespacedecl'), + (r'inherit|no-inherit', Keyword, 'root'), + (r'namespace', Keyword, 'namespacedecl'), + (r'(default)(\s+)(element)', bygroups(Keyword, Text, Keyword)), + (r'preserve|no-preserve', Keyword), + (r',', Punctuation), + ], + 'varname': [ + (r'\(:', Comment, 'comment'), + (qname, Name.Variable, 'operator'), + ], + 'singletype': [ + (r'\(:', Comment, 'comment'), + (ncname + r'(:\*)', Name.Variable, 'operator'), + (qname, Name.Variable, 'operator'), + ], + 'itemtype': [ + include('whitespace'), + (r'\(:', Comment, 'comment'), + (r'\$', Punctuation, 'varname'), + (r'(void)(\s*)(\()(\s*)(\))', + bygroups(Keyword, Text, Punctuation, Text, Punctuation), 'operator'), + (r'(element|attribute|schema-element|schema-attribute|comment|text|' + r'node|binary|document-node|empty-sequence)(\s*)(\()', + pushstate_occurrenceindicator_kindtest_callback), + # Marklogic specific type? + (r'(processing-instruction)(\s*)(\()', + bygroups(Keyword, Text, Punctuation), + ('occurrenceindicator', 'kindtestforpi')), + (r'(item)(\s*)(\()(\s*)(\))(?=[*+?])', + bygroups(Keyword, Text, Punctuation, Text, Punctuation), + 'occurrenceindicator'), + (r'\(\#', Punctuation, 'pragma'), + (r';', Punctuation, '#pop'), + (r'then|else', Keyword, '#pop'), + (r'(at)(\s+)(' + stringdouble + ')', + bygroups(Keyword, Text, String.Double), 'namespacedecl'), + (r'(at)(\s+)(' + stringsingle + ')', + bygroups(Keyword, Text, String.Single), 'namespacedecl'), + (r'except|intersect|in|is|return|satisfies|to|union|where', + Keyword, 'root'), + (r'and|div|eq|ge|gt|le|lt|ne|idiv|mod|or', Operator.Word, 'root'), + (r':=|=|,|>=|>>|>|\[|\(|<=|<<|<|-|!=|\|', Operator, 'root'), + (r'external|at', Keyword, 'root'), + (r'(stable)(\s+)(order)(\s+)(by)', + bygroups(Keyword, Text, Keyword, Text, Keyword), 'root'), + (r'(castable|cast)(\s+)(as)', + bygroups(Keyword, Text, Keyword), 'singletype'), + (r'(treat)(\s+)(as)', bygroups(Keyword, Text, Keyword)), + (r'(instance)(\s+)(of)', bygroups(Keyword, Text, Keyword)), + (r'case|as', Keyword, 'itemtype'), + (r'(\))(\s*)(as)', bygroups(Operator, Text, Keyword), 'itemtype'), + (ncname + r':\*', Keyword.Type, 'operator'), + (qname, Keyword.Type, 'occurrenceindicator'), + ], + 'kindtest': [ + (r'\(:', Comment, 'comment'), + (r'{', Punctuation, 'root'), + (r'(\))([*+?]?)', popstate_kindtest_callback), + (r'\*', Name, 'closekindtest'), + (qname, Name, 'closekindtest'), + (r'(element|schema-element)(\s*)(\()', pushstate_kindtest_callback), + ], + 'kindtestforpi': [ + (r'\(:', Comment, 'comment'), + (r'\)', Punctuation, '#pop'), + (ncname, Name.Variable), + (stringdouble, String.Double), + (stringsingle, String.Single), + ], + 'closekindtest': [ + (r'\(:', Comment, 'comment'), + (r'(\))', popstate_callback), + (r',', Punctuation), + (r'(\{)', pushstate_operator_root_callback), + (r'\?', Punctuation), + ], + 'xml_comment': [ + (r'(-->)', popstate_xmlcomment_callback), + (r'[^-]{1,2}', Literal), + (u'\\t|\\r|\\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + + unirange(0x10000, 0x10ffff), Literal), + ], + 'processing_instruction': [ + (r'\s+', Text, 'processing_instruction_content'), + (r'\?>', String.Doc, '#pop'), + (pitarget, Name), + ], + 'processing_instruction_content': [ + (r'\?>', String.Doc, '#pop'), + (u'\\t|\\r|\\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + + unirange(0x10000, 0x10ffff), Literal), + ], + 'cdata_section': [ + (r']]>', String.Doc, '#pop'), + (u'\\t|\\r|\\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + + unirange(0x10000, 0x10ffff), Literal), + ], + 'start_tag': [ + include('whitespace'), + (r'(/>)', popstate_tag_callback), + (r'>', Name.Tag, 'element_content'), + (r'"', Punctuation, 'quot_attribute_content'), + (r"'", Punctuation, 'apos_attribute_content'), + (r'=', Operator), + (qname, Name.Tag), + ], + 'quot_attribute_content': [ + (r'"', Punctuation, 'start_tag'), + (r'(\{)', pushstate_root_callback), + (r'""', Name.Attribute), + (quotattrcontentchar, Name.Attribute), + (entityref, Name.Attribute), + (charref, Name.Attribute), + (r'\{\{|\}\}', Name.Attribute), + ], + 'apos_attribute_content': [ + (r"'", Punctuation, 'start_tag'), + (r'\{', Punctuation, 'root'), + (r"''", Name.Attribute), + (aposattrcontentchar, Name.Attribute), + (entityref, Name.Attribute), + (charref, Name.Attribute), + (r'\{\{|\}\}', Name.Attribute), + ], + 'element_content': [ + (r'</', Name.Tag, 'end_tag'), + (r'(\{)', pushstate_root_callback), + (r'(<!--)', pushstate_element_content_xmlcomment_callback), + (r'(<\?)', pushstate_element_content_processing_instruction_callback), + (r'(<!\[CDATA\[)', pushstate_element_content_cdata_section_callback), + (r'(<)', pushstate_element_content_starttag_callback), + (elementcontentchar, Literal), + (entityref, Literal), + (charref, Literal), + (r'\{\{|\}\}', Literal), + ], + 'end_tag': [ + include('whitespace'), + (r'(>)', popstate_tag_callback), + (qname, Name.Tag), + ], + 'xmlspace_decl': [ + (r'\(:', Comment, 'comment'), + (r'preserve|strip', Keyword, '#pop'), + ], + 'declareordering': [ + (r'\(:', Comment, 'comment'), + include('whitespace'), + (r'ordered|unordered', Keyword, '#pop'), + ], + 'xqueryversion': [ + include('whitespace'), + (r'\(:', Comment, 'comment'), + (stringdouble, String.Double), + (stringsingle, String.Single), + (r'encoding', Keyword), + (r';', Punctuation, '#pop'), + ], + 'pragma': [ + (qname, Name.Variable, 'pragmacontents'), + ], + 'pragmacontents': [ + (r'#\)', Punctuation, 'operator'), + (u'\\t|\\r|\\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + + unirange(0x10000, 0x10ffff), Literal), + (r'(\s+)', Text), + ], + 'occurrenceindicator': [ + include('whitespace'), + (r'\(:', Comment, 'comment'), + (r'\*|\?|\+', Operator, 'operator'), + (r':=', Operator, 'root'), + default('operator'), + ], + 'option': [ + include('whitespace'), + (qname, Name.Variable, '#pop'), + ], + 'qname_braren': [ + include('whitespace'), + (r'(\{)', pushstate_operator_root_callback), + (r'(\()', Punctuation, 'root'), + ], + 'element_qname': [ + (qname, Name.Variable, 'root'), + ], + 'attribute_qname': [ + (qname, Name.Variable, 'root'), + ], + 'root': [ + include('whitespace'), + (r'\(:', Comment, 'comment'), + + # handle operator state + # order on numbers matters - handle most complex first + (r'\d+(\.\d*)?[eE][\+\-]?\d+', Number.Float, 'operator'), + (r'(\.\d+)[eE][\+\-]?\d+', Number.Float, 'operator'), + (r'(\.\d+|\d+\.\d*)', Number.Float, 'operator'), + (r'(\d+)', Number.Integer, 'operator'), + (r'(\.\.|\.|\))', Punctuation, 'operator'), + (r'(declare)(\s+)(construction)', + bygroups(Keyword, Text, Keyword), 'operator'), + (r'(declare)(\s+)(default)(\s+)(order)', + bygroups(Keyword, Text, Keyword, Text, Keyword), 'operator'), + (ncname + ':\*', Name, 'operator'), + ('\*:'+ncname, Name.Tag, 'operator'), + ('\*', Name.Tag, 'operator'), + (stringdouble, String.Double, 'operator'), + (stringsingle, String.Single, 'operator'), + + (r'(\})', popstate_callback), + + # NAMESPACE DECL + (r'(declare)(\s+)(default)(\s+)(collation)', + bygroups(Keyword, Text, Keyword, Text, Keyword)), + (r'(module|declare)(\s+)(namespace)', + bygroups(Keyword, Text, Keyword), 'namespacedecl'), + (r'(declare)(\s+)(base-uri)', + bygroups(Keyword, Text, Keyword), 'namespacedecl'), + + # NAMESPACE KEYWORD + (r'(declare)(\s+)(default)(\s+)(element|function)', + bygroups(Keyword, Text, Keyword, Text, Keyword), 'namespacekeyword'), + (r'(import)(\s+)(schema|module)', + bygroups(Keyword.Pseudo, Text, Keyword.Pseudo), 'namespacekeyword'), + (r'(declare)(\s+)(copy-namespaces)', + bygroups(Keyword, Text, Keyword), 'namespacekeyword'), + + # VARNAMEs + (r'(for|let|some|every)(\s+)(\$)', + bygroups(Keyword, Text, Name.Variable), 'varname'), + (r'\$', Name.Variable, 'varname'), + (r'(declare)(\s+)(variable)(\s+)(\$)', + bygroups(Keyword, Text, Keyword, Text, Name.Variable), 'varname'), + + # ITEMTYPE + (r'(\))(\s+)(as)', bygroups(Operator, Text, Keyword), 'itemtype'), + + (r'(element|attribute|schema-element|schema-attribute|comment|' + r'text|node|document-node|empty-sequence)(\s+)(\()', + pushstate_operator_kindtest_callback), + + (r'(processing-instruction)(\s+)(\()', + pushstate_operator_kindtestforpi_callback), + + (r'(<!--)', pushstate_operator_xmlcomment_callback), + + (r'(<\?)', pushstate_operator_processing_instruction_callback), + + (r'(<!\[CDATA\[)', pushstate_operator_cdata_section_callback), + + # (r'</', Name.Tag, 'end_tag'), + (r'(<)', pushstate_operator_starttag_callback), + + (r'(declare)(\s+)(boundary-space)', + bygroups(Keyword, Text, Keyword), 'xmlspace_decl'), + + (r'(validate)(\s+)(lax|strict)', + pushstate_operator_root_validate_withmode), + (r'(validate)(\s*)(\{)', pushstate_operator_root_validate), + (r'(typeswitch)(\s*)(\()', bygroups(Keyword, Text, Punctuation)), + (r'(element|attribute)(\s*)(\{)', + pushstate_operator_root_construct_callback), + + (r'(document|text|processing-instruction|comment)(\s*)(\{)', + pushstate_operator_root_construct_callback), + # ATTRIBUTE + (r'(attribute)(\s+)(?=' + qname + r')', + bygroups(Keyword, Text), 'attribute_qname'), + # ELEMENT + (r'(element)(\s+)(?=' + qname + r')', + bygroups(Keyword, Text), 'element_qname'), + # PROCESSING_INSTRUCTION + (r'(processing-instruction)(\s+)(' + ncname + r')(\s*)(\{)', + bygroups(Keyword, Text, Name.Variable, Text, Punctuation), + 'operator'), + + (r'(declare|define)(\s+)(function)', + bygroups(Keyword, Text, Keyword)), + + (r'(\{)', pushstate_operator_root_callback), + + (r'(unordered|ordered)(\s*)(\{)', + pushstate_operator_order_callback), + + (r'(declare)(\s+)(ordering)', + bygroups(Keyword, Text, Keyword), 'declareordering'), + + (r'(xquery)(\s+)(version)', + bygroups(Keyword.Pseudo, Text, Keyword.Pseudo), 'xqueryversion'), + + (r'(\(#)', Punctuation, 'pragma'), + + # sometimes return can occur in root state + (r'return', Keyword), + + (r'(declare)(\s+)(option)', bygroups(Keyword, Text, Keyword), + 'option'), + + # URI LITERALS - single and double quoted + (r'(at)(\s+)('+stringdouble+')', String.Double, 'namespacedecl'), + (r'(at)(\s+)('+stringsingle+')', String.Single, 'namespacedecl'), + + (r'(ancestor-or-self|ancestor|attribute|child|descendant-or-self)(::)', + bygroups(Keyword, Punctuation)), + (r'(descendant|following-sibling|following|parent|preceding-sibling' + r'|preceding|self)(::)', bygroups(Keyword, Punctuation)), + + (r'(if)(\s*)(\()', bygroups(Keyword, Text, Punctuation)), + + (r'then|else', Keyword), + + # ML specific + (r'(try)(\s*)', bygroups(Keyword, Text), 'root'), + (r'(catch)(\s*)(\()(\$)', + bygroups(Keyword, Text, Punctuation, Name.Variable), 'varname'), + + (r'(@'+qname+')', Name.Attribute), + (r'(@'+ncname+')', Name.Attribute), + (r'@\*:'+ncname, Name.Attribute), + (r'(@)', Name.Attribute), + + (r'//|/|\+|-|;|,|\(|\)', Punctuation), + + # STANDALONE QNAMES + (qname + r'(?=\s*{)', Name.Tag, 'qname_braren'), + (qname + r'(?=\s*\([^:])', Name.Function, 'qname_braren'), + (qname, Name.Tag, 'operator'), + ] + } + + +class QmlLexer(RegexLexer): + """ + For QML files. See http://doc.qt.digia.com/4.7/qdeclarativeintroduction.html. + + .. versionadded:: 1.6 + """ + + # QML is based on javascript, so much of this is taken from the + # JavascriptLexer above. + + name = 'QML' + aliases = ['qml'] + filenames = ['*.qml'] + mimetypes = ['application/x-qml'] + + # pasted from JavascriptLexer, with some additions + flags = re.DOTALL + tokens = { + 'commentsandwhitespace': [ + (r'\s+', Text), + (r'<!--', Comment), + (r'//.*?\n', Comment.Single), + (r'/\*.*?\*/', Comment.Multiline) + ], + 'slashstartsregex': [ + include('commentsandwhitespace'), + (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' + r'([gim]+\b|\B)', String.Regex, '#pop'), + (r'(?=/)', Text, ('#pop', 'badregex')), + default('#pop') + ], + 'badregex': [ + (r'\n', Text, '#pop') + ], + 'root': [ + (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), + include('commentsandwhitespace'), + (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' + r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'), + (r'[{(\[;,]', Punctuation, 'slashstartsregex'), + (r'[})\].]', Punctuation), + + # QML insertions + (r'\bid\s*:\s*[A-Za-z][_A-Za-z.0-9]*', Keyword.Declaration, + 'slashstartsregex'), + (r'\b[A-Za-z][_A-Za-z.0-9]*\s*:', Keyword, 'slashstartsregex'), + + # the rest from JavascriptLexer + (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' + r'throw|try|catch|finally|new|delete|typeof|instanceof|void|' + r'this)\b', Keyword, 'slashstartsregex'), + (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), + (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' + r'extends|final|float|goto|implements|import|int|interface|long|native|' + r'package|private|protected|public|short|static|super|synchronized|throws|' + r'transient|volatile)\b', Keyword.Reserved), + (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), + (r'(Array|Boolean|Date|Error|Function|Math|netscape|' + r'Number|Object|Packages|RegExp|String|sun|decodeURI|' + r'decodeURIComponent|encodeURI|encodeURIComponent|' + r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' + r'window)\b', Name.Builtin), + (r'[$a-zA-Z_]\w*', Name.Other), + (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), + (r'0x[0-9a-fA-F]+', Number.Hex), + (r'[0-9]+', Number.Integer), + (r'"(\\\\|\\"|[^"])*"', String.Double), + (r"'(\\\\|\\'|[^'])*'", String.Single), + ] + } + + +class CirruLexer(RegexLexer): + """ + Syntax rules of Cirru can be found at: + http://grammar.cirru.org/ + + * using ``()`` to markup blocks, but limited in the same line + * using ``""`` to markup strings, allow ``\`` to escape + * using ``$`` as a shorthand for ``()`` till indentation end or ``)`` + * using indentations for create nesting + + .. versionadded:: 2.0 + """ + + name = 'Cirru' + aliases = ['cirru'] + filenames = ['*.cirru', '*.cr'] + mimetypes = ['text/x-cirru'] + flags = re.MULTILINE + + tokens = { + 'string': [ + (r'[^"\\\n]', String), + (r'\\', String.Escape, 'escape'), + (r'"', String, '#pop'), + ], + 'escape': [ + (r'.', String.Escape, '#pop'), + ], + 'function': [ + (r'[\w-][^\s\(\)\"]*', Name.Function, '#pop'), + (r'\)', Operator, '#pop'), + (r'(?=\n)', Text, '#pop'), + (r'\(', Operator, '#push'), + (r'"', String, ('#pop', 'string')), + (r'\s+', Text.Whitespace), + (r'\,', Operator, '#pop'), + ], + 'line': [ + (r'^\B', Text.Whitespace, 'function'), + (r'\$', Operator, 'function'), + (r'\(', Operator, 'function'), + (r'\)', Operator), + (r'(?=\n)', Text, '#pop'), + (r'\n', Text, '#pop'), + (r'"', String, 'string'), + (r'\s+', Text.Whitespace), + (r'[\d\.]+', Number), + (r'[\w-][^\"\(\)\s]*', Name.Variable), + (r'--', Comment.Single) + ], + 'root': [ + (r'^\s*', Text.Whitespace, ('line', 'function')), + (r'^\s+$', Text.Whitespace), + ] + } + + +class SlimLexer(ExtendedRegexLexer): + """ + For Slim markup. + """ + + name = 'Slim' + aliases = ['slim'] + filenames = ['*.slim'] + mimetypes = ['text/x-slim'] + + flags = re.IGNORECASE + _dot = r'(?: \|\n(?=.* \|)|.)' + tokens = { + 'root': [ + (r'[ \t]*\n', Text), + (r'[ \t]*', _indentation), + ], + + 'css': [ + (r'\.[\w:-]+', Name.Class, 'tag'), + (r'\#[\w:-]+', Name.Function, 'tag'), + ], + + 'eval-or-plain': [ + (r'([ \t]*==?)(.*\n)', + bygroups(Punctuation, using(RubyLexer)), + 'root'), + (r'[ \t]+[\w:-]+(?=[=])', Name.Attribute, 'html-attributes'), + (r'', Text, 'plain'), + ], + + 'content': [ + include('css'), + (r'[\w:-]+:[ \t]*\n', Text, 'plain'), + (r'(-)(.*\n)', + bygroups(Punctuation, using(RubyLexer)), + '#pop'), + (r'\|' + _dot + r'*\n', _starts_block(Text, 'plain'), '#pop'), + (r'/' + _dot + r'*\n', _starts_block(Comment.Preproc, 'slim-comment-block'), '#pop'), + (r'[\w:-]+', Name.Tag, 'tag'), + include('eval-or-plain'), + ], + + 'tag': [ + include('css'), + (r'[<>]{1,2}(?=[ \t=])', Punctuation), + (r'[ \t]+\n', Punctuation, '#pop:2'), + include('eval-or-plain'), + ], + + 'plain': [ + (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text), + (r'(#\{)(.*?)(\})', + bygroups(String.Interpol, using(RubyLexer), String.Interpol)), + (r'\n', Text, 'root'), + ], + + 'html-attributes': [ + (r'=', Punctuation), + (r'"[^\"]+"', using(RubyLexer), 'tag'), + (r'\'[^\']+\'', using(RubyLexer), 'tag'), + (r'[\w]+', Text, 'tag'), + ], + + 'slim-comment-block': [ + (_dot + '+', Comment.Preproc), + (r'\n', Text, 'root'), + ], + } |