diff options
author | Anteru <bitbucket@ca.sh13.net> | 2019-04-30 15:40:47 +0000 |
---|---|---|
committer | Anteru <bitbucket@ca.sh13.net> | 2019-04-30 15:40:47 +0000 |
commit | a0fc52727aaed41c8e09c87996de842117872afb (patch) | |
tree | 42e2f38a86a2839160e96dcb1472f362d363103a /pygments | |
parent | 665f287849402bdf05ef636e77989104e6cf8e9e (diff) | |
parent | 323d10920c579054c861ee0cfdd9a30d012a4d0a (diff) | |
download | pygments-a0fc52727aaed41c8e09c87996de842117872afb.tar.gz |
Merged in gerph/pygments-main (pull request #806)
Create a Lexer class for BBC Basic files.
Diffstat (limited to 'pygments')
-rw-r--r-- | pygments/lexers/_mapping.py | 7 | ||||
-rw-r--r-- | pygments/lexers/_stata_builtins.py | 8 | ||||
-rw-r--r-- | pygments/lexers/asm.py | 108 | ||||
-rw-r--r-- | pygments/lexers/configs.py | 96 | ||||
-rw-r--r-- | pygments/lexers/jvm.py | 33 | ||||
-rw-r--r-- | pygments/lexers/markup.py | 5 | ||||
-rw-r--r-- | pygments/lexers/slash.py | 187 | ||||
-rw-r--r-- | pygments/lexers/stata.py | 143 | ||||
-rw-r--r-- | pygments/lexers/unicon.py | 390 | ||||
-rw-r--r-- | pygments/styles/__init__.py | 4 | ||||
-rw-r--r-- | pygments/styles/stata_dark.py | 41 | ||||
-rw-r--r-- | pygments/styles/stata_light.py (renamed from pygments/styles/stata.py) | 27 |
12 files changed, 987 insertions, 62 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index e57124db..3fbb1df8 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -44,6 +44,7 @@ LEXERS = { 'ArduinoLexer': ('pygments.lexers.c_like', 'Arduino', ('arduino',), ('*.ino',), ('text/x-arduino',)), 'AspectJLexer': ('pygments.lexers.jvm', 'AspectJ', ('aspectj',), ('*.aj',), ('text/x-aspectj',)), 'AsymptoteLexer': ('pygments.lexers.graphics', 'Asymptote', ('asy', 'asymptote'), ('*.asy',), ('text/x-asymptote',)), + 'AugeasLexer': ('pygments.lexers.configs', 'Augeas', ('augeas',), ('*.aug',), ()), 'AutoItLexer': ('pygments.lexers.automation', 'AutoIt', ('autoit',), ('*.au3',), ('text/x-autoit',)), 'AutohotkeyLexer': ('pygments.lexers.automation', 'autohotkey', ('ahk', 'autohotkey'), ('*.ahk', '*.ahkl'), ('text/x-autohotkey',)), 'AwkLexer': ('pygments.lexers.textedit', 'Awk', ('awk', 'gawk', 'mawk', 'nawk'), ('*.awk',), ('application/x-awk',)), @@ -122,6 +123,7 @@ LEXERS = { '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.javascript', 'Dart', ('dart',), ('*.dart',), ('text/x-dart',)), + 'Dasm16Lexer': ('pygments.lexers.asm', 'DASM16', ('dasm16',), ('*.dasm16', '*.dasm'), ('text/x-dasm16',)), 'DebianControlLexer': ('pygments.lexers.installers', 'Debian Control file', ('control', 'debcontrol'), ('control',), ()), 'DelphiLexer': ('pygments.lexers.pascal', 'Delphi', ('delphi', 'pas', 'pascal', 'objectpascal'), ('*.pas', '*.dpr'), ('text/x-pascal',)), 'DgLexer': ('pygments.lexers.python', 'dg', ('dg',), ('*.dg',), ('text/x-dg',)), @@ -197,6 +199,7 @@ LEXERS = { '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.idl', 'IDL', ('idl',), ('*.pro',), ('text/idl',)), + 'IconLexer': ('pygments.lexers.unicon', 'Icon', ('icon',), ('*.icon', '*.ICON'), ()), 'IdrisLexer': ('pygments.lexers.haskell', 'Idris', ('idris', 'idr'), ('*.idr',), ('text/x-idris',)), 'IgorLexer': ('pygments.lexers.igor', 'Igor', ('igor', 'igorpro'), ('*.ipf',), ('text/ipf',)), 'Inform6Lexer': ('pygments.lexers.int_fiction', 'Inform 6', ('inform6', 'i6'), ('*.inf',), ()), @@ -386,6 +389,7 @@ LEXERS = { 'ScssLexer': ('pygments.lexers.css', 'SCSS', ('scss',), ('*.scss',), ('text/x-scss',)), 'ShenLexer': ('pygments.lexers.lisp', 'Shen', ('shen',), ('*.shen',), ('text/x-shen', 'application/x-shen')), 'SilverLexer': ('pygments.lexers.verification', 'Silver', ('silver',), ('*.sil', '*.vpr'), ()), + 'SlashLexer': ('pygments.lexers.slash', 'Slash', ('slash',), ('*.sl',), ()), 'SlimLexer': ('pygments.lexers.webmisc', 'Slim', ('slim',), ('*.slim',), ('text/x-slim',)), 'SlurmBashLexer': ('pygments.lexers.shell', 'Slurm', ('slurm', 'sbatch'), ('*.sl',), ()), 'SmaliLexer': ('pygments.lexers.dalvik', 'Smali', ('smali',), ('*.smali',), ('text/smali',)), @@ -408,6 +412,7 @@ LEXERS = { 'SwigLexer': ('pygments.lexers.c_like', 'SWIG', ('swig',), ('*.swg', '*.i'), ('text/swig',)), 'SystemVerilogLexer': ('pygments.lexers.hdl', 'systemverilog', ('systemverilog', 'sv'), ('*.sv', '*.svh'), ('text/x-systemverilog',)), 'TAPLexer': ('pygments.lexers.testing', 'TAP', ('tap',), ('*.tap',), ()), + 'TOMLLexer': ('pygments.lexers.configs', 'TOML', ('toml',), ('*.toml',), ()), 'Tads3Lexer': ('pygments.lexers.int_fiction', 'TADS 3', ('tads3',), ('*.t',), ()), 'TasmLexer': ('pygments.lexers.asm', 'TASM', ('tasm',), ('*.asm', '*.ASM', '*.tasm'), ('text/x-tasm',)), 'TclLexer': ('pygments.lexers.tcl', 'Tcl', ('tcl',), ('*.tcl', '*.rvt'), ('text/x-tcl', 'text/x-script.tcl', 'application/x-tcl')), @@ -430,6 +435,8 @@ LEXERS = { 'TypoScriptCssDataLexer': ('pygments.lexers.typoscript', 'TypoScriptCssData', ('typoscriptcssdata',), (), ()), 'TypoScriptHtmlDataLexer': ('pygments.lexers.typoscript', 'TypoScriptHtmlData', ('typoscripthtmldata',), (), ()), 'TypoScriptLexer': ('pygments.lexers.typoscript', 'TypoScript', ('typoscript',), ('*.typoscript',), ('text/x-typoscript',)), + 'UcodeLexer': ('pygments.lexers.unicon', 'ucode', ('ucode',), ('*.u', '*.u1', '*.u2'), ()), + 'UniconLexer': ('pygments.lexers.unicon', 'Unicon', ('unicon',), ('*.icn',), ('text/unicon',)), 'UrbiscriptLexer': ('pygments.lexers.urbi', 'UrbiScript', ('urbiscript',), ('*.u',), ('application/x-urbiscript',)), 'VBScriptLexer': ('pygments.lexers.basic', 'VBScript', (), ('*.vbs', '*.VBS'), ()), 'VCLLexer': ('pygments.lexers.varnish', 'VCL', ('vcl',), ('*.vcl',), ('text/x-vclsrc',)), diff --git a/pygments/lexers/_stata_builtins.py b/pygments/lexers/_stata_builtins.py index 5f5f72a9..3e5e75b2 100644 --- a/pygments/lexers/_stata_builtins.py +++ b/pygments/lexers/_stata_builtins.py @@ -10,6 +10,10 @@ """ +builtins_special = ( + "if", "in", "using", "replace", "by", "gen", "generate" +) + builtins_base = ( "if", "else", "in", "foreach", "for", "forv", "forva", "forval", "forvalu", "forvalue", "forvalues", "by", "bys", @@ -66,7 +70,7 @@ builtins_base = ( "doedit", "dotplot", "dotplot_7", "dprobit", "drawnorm", "drop", "ds", "ds_util", "dstdize", "duplicates", "durbina", "dwstat", "dydx", "e", "ed", "edi", "edit", "egen", - "eivreg", "emdef", "en", "enc", "enco", "encod", "encode", + "eivreg", "emdef", "end", "en", "enc", "enco", "encod", "encode", "eq", "erase", "ereg", "ereg_lf", "ereg_p", "ereg_sw", "ereghet", "ereghet_glf", "ereghet_glf_sh", "ereghet_gp", "ereghet_ilf", "ereghet_ilf_sh", "ereghet_ip", "eret", @@ -415,5 +419,3 @@ builtins_functions = ( "weekly", "wofd", "word", "wordcount", "year", "yearly", "yh", "ym", "yofd", "yq", "yw" ) - - diff --git a/pygments/lexers/asm.py b/pygments/lexers/asm.py index 2f08d510..7100868c 100644 --- a/pygments/lexers/asm.py +++ b/pygments/lexers/asm.py @@ -20,7 +20,7 @@ from pygments.token import Text, Name, Number, String, Comment, Punctuation, \ __all__ = ['GasLexer', 'ObjdumpLexer', 'DObjdumpLexer', 'CppObjdumpLexer', 'CObjdumpLexer', 'HsailLexer', 'LlvmLexer', 'NasmLexer', - 'NasmObjdumpLexer', 'TasmLexer', 'Ca65Lexer'] + 'NasmObjdumpLexer', 'TasmLexer', 'Ca65Lexer', 'Dasm16Lexer'] class GasLexer(RegexLexer): @@ -650,3 +650,109 @@ class Ca65Lexer(RegexLexer): # comments in GAS start with "#" if re.match(r'^\s*;', text, re.MULTILINE): return 0.9 + + +class Dasm16Lexer(RegexLexer): + """ + Simple lexer for DCPU-16 Assembly + + Check http://0x10c.com/doc/dcpu-16.txt + + .. versionadded:: 2.4 + """ + name = 'DASM16' + aliases = ['dasm16'] + filenames = ['*.dasm16', '*.dasm'] + mimetypes = ['text/x-dasm16'] + + INSTRUCTIONS = [ + 'SET', + 'ADD', 'SUB', + 'MUL', 'MLI', + 'DIV', 'DVI', + 'MOD', 'MDI', + 'AND', 'BOR', 'XOR', + 'SHR', 'ASR', 'SHL', + 'IFB', 'IFC', 'IFE', 'IFN', 'IFG', 'IFA', 'IFL', 'IFU', + 'ADX', 'SBX', + 'STI', 'STD', + 'JSR', + 'INT', 'IAG', 'IAS', 'RFI', 'IAQ', 'HWN', 'HWQ', 'HWI', + ] + + REGISTERS = [ + 'A', 'B', 'C', + 'X', 'Y', 'Z', + 'I', 'J', + 'SP', 'PC', 'EX', + 'POP', 'PEEK', 'PUSH' + ] + + # Regexes yo + char = r'[a-zA-Z$._0-9@]' + identifier = r'(?:[a-zA-Z$_]' + char + '*|\.' + char + '+)' + number = r'[+-]?(?:0[xX][a-zA-Z0-9]+|\d+)' + binary_number = r'0b[01_]+' + instruction = r'(?i)(' + '|'.join(INSTRUCTIONS) + ')' + single_char = r"'\\?" + char + "'" + string = r'"(\\"|[^"])*"' + + def guess_identifier(lexer, match): + ident = match.group(0) + klass = Name.Variable if ident.upper() in lexer.REGISTERS else Name.Label + yield match.start(), klass, ident + + tokens = { + 'root': [ + include('whitespace'), + (':' + identifier, Name.Label), + (identifier + ':', Name.Label), + (instruction, Name.Function, 'instruction-args'), + (r'\.' + identifier, Name.Function, 'data-args'), + (r'[\r\n]+', Text) + ], + + 'numeric' : [ + (binary_number, Number.Integer), + (number, Number.Integer), + (single_char, String), + ], + + 'arg' : [ + (identifier, guess_identifier), + include('numeric') + ], + + 'deref' : [ + (r'\+', Punctuation), + (r'\]', Punctuation, '#pop'), + include('arg'), + include('whitespace') + ], + + 'instruction-line' : [ + (r'[\r\n]+', Text, '#pop'), + (r';.*?$', Comment, '#pop'), + include('whitespace') + ], + + 'instruction-args': [ + (r',', Punctuation), + (r'\[', Punctuation, 'deref'), + include('arg'), + include('instruction-line') + ], + + 'data-args' : [ + (r',', Punctuation), + include('numeric'), + (string, String), + include('instruction-line') + ], + + 'whitespace': [ + (r'\n', Text), + (r'\s+', Text), + (r';.*?\n', Comment) + ], + } diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py index 206ec360..6f2c7c76 100644 --- a/pygments/lexers/configs.py +++ b/pygments/lexers/configs.py @@ -21,7 +21,7 @@ __all__ = ['IniLexer', 'RegeditLexer', 'PropertiesLexer', 'KconfigLexer', 'Cfengine3Lexer', 'ApacheConfLexer', 'SquidConfLexer', 'NginxConfLexer', 'LighttpdConfLexer', 'DockerLexer', 'TerraformLexer', 'TermcapLexer', 'TerminfoLexer', - 'PkgConfigLexer', 'PacmanConfLexer'] + 'PkgConfigLexer', 'PacmanConfLexer', 'AugeasLexer', 'TOMLLexer'] class IniLexer(RegexLexer): @@ -838,3 +838,97 @@ class PacmanConfLexer(RegexLexer): (r'.', Text), ], } + + +class AugeasLexer(RegexLexer): + """ + Lexer for `Augeas <http://augeas.net>`_. + + .. versionadded:: 2.4 + """ + name = 'Augeas' + aliases = ['augeas'] + filenames = ['*.aug'] + + tokens = { + 'root': [ + (r'(module)(\s*)([^\s=]+)', bygroups(Keyword.Namespace, Text, Name.Namespace)), + (r'(let)(\s*)([^\s=]+)', bygroups(Keyword.Declaration, Text, Name.Variable)), + (r'(del|store|value|counter|seq|key|label|autoload|incl|excl|transform|test|get|put)(\s+)', bygroups(Name.Builtin, Text)), + (r'(\()([^:]+)(\:)(unit|string|regexp|lens|tree|filter)(\))', bygroups(Punctuation, Name.Variable, Punctuation, Keyword.Type, Punctuation)), + (r'\(\*', Comment.Multiline, 'comment'), + (r'[*+\-.;=?|]', Operator), + (r'[()\[\]{}]', Operator), + (r'"', String.Double, 'string'), + (r'\/', String.Regex, 'regex'), + (r'([A-Z]\w*)(\.)(\w+)', bygroups(Name.Namespace, Punctuation, Name.Variable)), + (r'.', Name.Variable), + (r'\s', Text), + ], + 'string': [ + (r'\\.', String.Escape), + (r'[^"]', String.Double), + (r'"', String.Double, '#pop'), + ], + 'regex': [ + (r'\\.', String.Escape), + (r'[^/]', String.Regex), + (r'\/', String.Regex, '#pop'), + ], + 'comment': [ + (r'[^*)]', Comment.Multiline), + (r'\(\*', Comment.Multiline, '#push'), + (r'\*\)', Comment.Multiline, '#pop'), + (r'[)*]', Comment.Multiline) + ], + } + + +class TOMLLexer(RegexLexer): + """ + Lexer for `TOML <https://github.com/toml-lang/toml>`_, a simple language + for config files. + + .. versionadded:: 2.4 + """ + + name = 'TOML' + aliases = ['toml'] + filenames = ['*.toml'] + + tokens = { + 'root': [ + + # Basics, comments, strings + (r'\s+', Text), + (r'#.*?$', Comment.Single), + # Basic string + (r'"(\\\\|\\"|[^"])*"', String), + # Literal string + (r'\'\'\'(.*)\'\'\'', String), + (r'\'[^\']*\'', String), + (r'(true|false)$', Keyword.Constant), + (r'[a-zA-Z_][\w\-]*', Name), + + (r'\[.*?\]$', Keyword), + # Datetime + # TODO this needs to be expanded, as TOML is rather flexible: + # https://github.com/toml-lang/toml#offset-date-time + (r'\d{4}-\d{2}-\d{2}(?:T| )\d{2}:\d{2}:\d{2}(?:Z|[-+]\d{2}:\d{2})', Number.Integer), + + # Numbers + (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?', Number.Float), + (r'\d+[eE][+-]?[0-9]+j?', Number.Float), + # Handle +-inf, +-infinity, +-nan + (r'[+-]?(?:(inf(?:inity)?)|nan)', Number.Float), + (r'[+-]?\d+', Number.Integer), + + # Punctuation + (r'[]{}:(),;[]', Punctuation), + (r'\.', Punctuation), + + # Operators + (r'=', Operator) + + ] + } diff --git a/pygments/lexers/jvm.py b/pygments/lexers/jvm.py index 5a9a74a9..8de6e9f2 100644 --- a/pygments/lexers/jvm.py +++ b/pygments/lexers/jvm.py @@ -1006,7 +1006,7 @@ class KotlinLexer(RegexLexer): .. versionadded:: 1.5 """ - + name = 'Kotlin' aliases = ['kotlin'] filenames = ['*.kt'] @@ -1017,15 +1017,22 @@ class KotlinLexer(RegexLexer): kt_name = ('@?[_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl') + ']' + '[' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl', 'Nd', 'Pc', 'Cf', 'Mn', 'Mc') + ']*') - kt_id = '(' + kt_name + '|`' + kt_name + '`)' + + kt_space_name = ('@?[_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl') + ']' + + '[' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl', 'Nd', 'Pc', 'Cf', + 'Mn', 'Mc', 'Zs') + ',-]*') + + kt_id = '(' + kt_name + '|`' + kt_space_name + '`)' tokens = { 'root': [ (r'^\s*\[.*?\]', Name.Attribute), (r'[^\S\n]+', Text), + (r'\s+', Text), (r'\\\n', Text), # line continuation (r'//.*?\n', Comment.Single), (r'/[*].*?[*]/', Comment.Multiline), + (r'""".*?"""', String), (r'\n', Text), (r'::|!!|\?[:.]', Operator), (r'[~!%^&*()+=|\[\]:;,.<>/?-]', Punctuation), @@ -1035,11 +1042,14 @@ class KotlinLexer(RegexLexer): (r"'\\.'|'[^\\]'", String.Char), (r"[0-9](\.[0-9]*)?([eE][+-][0-9]+)?[flFL]?|" r"0[xX][0-9a-fA-F]+[Ll]?", Number), - (r'(class)(\s+)(object)', bygroups(Keyword, Text, Keyword)), + (r'(object)(\s+)(:)(\s+)', bygroups(Keyword, Text, Punctuation, Text), 'class'), + (r'(companion)(\s+)(object)', bygroups(Keyword, Text, Keyword)), (r'(class|interface|object)(\s+)', bygroups(Keyword, Text), 'class'), (r'(package|import)(\s+)', bygroups(Keyword, Text), 'package'), + (r'(val|var)(\s+)([(])', bygroups(Keyword, Text, Punctuation), 'property_dec'), (r'(val|var)(\s+)', bygroups(Keyword, Text), 'property'), (r'(fun)(\s+)', bygroups(Keyword, Text), 'function'), + (r'(inline fun)(\s+)', bygroups(Keyword, Text), 'function'), (r'(abstract|annotation|as|break|by|catch|class|companion|const|' r'constructor|continue|crossinline|data|do|dynamic|else|enum|' r'external|false|final|finally|for|fun|get|if|import|in|infix|' @@ -1058,9 +1068,26 @@ class KotlinLexer(RegexLexer): 'property': [ (kt_id, Name.Property, '#pop') ], + 'property_dec': [ + (r'(,)(\s*)', bygroups(Punctuation, Text)), + (r'(:)(\s*)', bygroups(Punctuation, Text)), + (r'<', Punctuation, 'generic'), + (r'([)])', Punctuation, '#pop'), + (kt_id, Name.Property) + ], 'function': [ + (r'<', Punctuation, 'generic'), + (r''+kt_id+'([.])'+kt_id, bygroups(Name.Class, Punctuation, Name.Function), '#pop'), (kt_id, Name.Function, '#pop') ], + 'generic': [ + (r'(>)(\s*)', bygroups(Punctuation, Text), '#pop'), + (r':',Punctuation), + (r'(reified|out|in)\b', Keyword), + (r',',Text), + (r'\s+',Text), + (kt_id,Name) + ] } diff --git a/pygments/lexers/markup.py b/pygments/lexers/markup.py index e6265f40..6eb55fc4 100644 --- a/pygments/lexers/markup.py +++ b/pygments/lexers/markup.py @@ -582,6 +582,11 @@ class MarkdownLexer(RegexLexer): (r'[@#][\w/:]+', Name.Entity), # (image?) links eg: ![Image of Yaktocat](https://octodex.github.com/images/yaktocat.png) (r'(!?\[)([^]]+)(\])(\()([^)]+)(\))', bygroups(Text, Name.Tag, Text, Text, Name.Attribute, Text)), + # reference-style links, e.g.: + # [an example][id] + # [id]: http://example.com/ + (r'(\[)([^]]+)(\])(\[)([^]]*)(\])', bygroups(Text, Name.Tag, Text, Text, Name.Label, Text)), + (r'^(\s*\[)([^]]*)(\]:\s*)(.+)', bygroups(Text, Name.Label, Text, Name.Attribute)), # general text, must come last! (r'[^\\\s]+', Text), diff --git a/pygments/lexers/slash.py b/pygments/lexers/slash.py new file mode 100644 index 00000000..bd73d463 --- /dev/null +++ b/pygments/lexers/slash.py @@ -0,0 +1,187 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.slash + ~~~~~~~~~~~~~~~~~~~~~ + + Lexer for the `Slash <https://github.com/arturadib/Slash-A>`_ programming + language. + + :copyright: Copyright 2012 by GitHub, Inc + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import ExtendedRegexLexer, bygroups, DelegatingLexer +from pygments.token import Name, Number, String, Comment, Punctuation, \ + Other, Keyword, Operator, Whitespace + +__all__ = ['SlashLexer'] + + +class SlashLanguageLexer(ExtendedRegexLexer): + _nkw = r'(?=[^a-zA-Z_0-9])' + + def move_state(new_state): + return ("#pop", new_state) + + def right_angle_bracket(lexer, match, ctx): + if len(ctx.stack) > 1 and ctx.stack[-2] == "string": + ctx.stack.pop() + yield match.start(), String.Interpol, "}" + ctx.pos = match.end() + pass + + tokens = { + "root": [ + (r"<%=", Comment.Preproc, move_state("slash")), + (r"<%!!", Comment.Preproc, move_state("slash")), + (r"<%#.*?%>", Comment.Multiline), + (r"<%", Comment.Preproc, move_state("slash")), + (r".|\n", Other), + ], + "string": [ + (r"\\", String.Escape, move_state("string_e")), + (r"\"", String, move_state("slash")), + (r"#\{", String.Interpol, "slash"), + (r'.|\n', String), + ], + "string_e": [ + (r'n', String.Escape, move_state("string")), + (r't', String.Escape, move_state("string")), + (r'r', String.Escape, move_state("string")), + (r'e', String.Escape, move_state("string")), + (r'x[a-fA-F0-9]{2}', String.Escape, move_state("string")), + (r'.', String.Escape, move_state("string")), + ], + "regexp": [ + (r'}[a-z]*', String.Regex, move_state("slash")), + (r'\\(.|\n)', String.Regex), + (r'{', String.Regex, "regexp_r"), + (r'.|\n', String.Regex), + ], + "regexp_r": [ + (r'}[a-z]*', String.Regex, "#pop"), + (r'\\(.|\n)', String.Regex), + (r'{', String.Regex, "regexp_r"), + ], + "slash": [ + (r"%>", Comment.Preproc, move_state("root")), + (r"\"", String, move_state("string")), + (r"'[a-zA-Z0-9_]+", String), + (r'%r{', String.Regex, move_state("regexp")), + (r'/\*.*?\*/', Comment.Multiline), + (r"(#|//).*?\n", Comment.Single), + (r'-?[0-9]+e[+-]?[0-9]+', Number.Float), + (r'-?[0-9]+\.[0-9]+(e[+-]?[0-9]+)?', Number.Float), + (r'-?[0-9]+', Number.Integer), + (r'nil'+_nkw, Name.Builtin), + (r'true'+_nkw, Name.Builtin), + (r'false'+_nkw, Name.Builtin), + (r'self'+_nkw, Name.Builtin), + (r'(class)(\s+)([A-Z][a-zA-Z0-9_\']*)', + bygroups(Keyword, Whitespace, Name.Class)), + (r'class'+_nkw, Keyword), + (r'extends'+_nkw, Keyword), + (r'(def)(\s+)(self)(\s*)(\.)(\s*)([a-z_][a-zA-Z0-9_\']*=?|<<|>>|==|<=>|<=|<|>=|>|\+|-(self)?|~(self)?|\*|/|%|^|&&|&|\||\[\]=?)', + bygroups(Keyword, Whitespace, Name.Builtin, Whitespace, Punctuation, Whitespace, Name.Function)), + (r'(def)(\s+)([a-z_][a-zA-Z0-9_\']*=?|<<|>>|==|<=>|<=|<|>=|>|\+|-(self)?|~(self)?|\*|/|%|^|&&|&|\||\[\]=?)', + bygroups(Keyword, Whitespace, Name.Function)), + (r'def'+_nkw, Keyword), + (r'if'+_nkw, Keyword), + (r'elsif'+_nkw, Keyword), + (r'else'+_nkw, Keyword), + (r'unless'+_nkw, Keyword), + (r'for'+_nkw, Keyword), + (r'in'+_nkw, Keyword), + (r'while'+_nkw, Keyword), + (r'until'+_nkw, Keyword), + (r'and'+_nkw, Keyword), + (r'or'+_nkw, Keyword), + (r'not'+_nkw, Keyword), + (r'lambda'+_nkw, Keyword), + (r'try'+_nkw, Keyword), + (r'catch'+_nkw, Keyword), + (r'return'+_nkw, Keyword), + (r'next'+_nkw, Keyword), + (r'last'+_nkw, Keyword), + (r'throw'+_nkw, Keyword), + (r'use'+_nkw, Keyword), + (r'switch'+_nkw, Keyword), + (r'\\', Keyword), + (r'λ', Keyword), + (r'__FILE__'+_nkw, Name.Builtin.Pseudo), + (r'__LINE__'+_nkw, Name.Builtin.Pseudo), + (r'[A-Z][a-zA-Z0-9_\']*'+_nkw, Name.Constant), + (r'[a-z_][a-zA-Z0-9_\']*'+_nkw, Name), + (r'@[a-z_][a-zA-Z0-9_\']*'+_nkw, Name.Variable.Instance), + (r'@@[a-z_][a-zA-Z0-9_\']*'+_nkw, Name.Variable.Class), + (r'\(', Punctuation), + (r'\)', Punctuation), + (r'\[', Punctuation), + (r'\]', Punctuation), + (r'\{', Punctuation), + (r'\}', right_angle_bracket), + (r';', Punctuation), + (r',', Punctuation), + (r'<<=', Operator), + (r'>>=', Operator), + (r'<<', Operator), + (r'>>', Operator), + (r'==', Operator), + (r'!=', Operator), + (r'=>', Operator), + (r'=', Operator), + (r'<=>', Operator), + (r'<=', Operator), + (r'>=', Operator), + (r'<', Operator), + (r'>', Operator), + (r'\+\+', Operator), + (r'\+=', Operator), + (r'-=', Operator), + (r'\*\*=', Operator), + (r'\*=', Operator), + (r'\*\*', Operator), + (r'\*', Operator), + (r'/=', Operator), + (r'\+', Operator), + (r'-', Operator), + (r'/', Operator), + (r'%=', Operator), + (r'%', Operator), + (r'^=', Operator), + (r'&&=', Operator), + (r'&=', Operator), + (r'&&', Operator), + (r'&', Operator), + (r'\|\|=', Operator), + (r'\|=', Operator), + (r'\|\|', Operator), + (r'\|', Operator), + (r'!', Operator), + (r'\.\.\.', Operator), + (r'\.\.', Operator), + (r'\.', Operator), + (r'::', Operator), + (r':', Operator), + (r'(\s|\n)+', Whitespace), + (r'[a-z_][a-zA-Z0-9_\']*', Name.Variable), + ], + } + + +class SlashLexer(DelegatingLexer): + """ + Lexer for the Slash programming language. + + .. versionadded:: 2.4 + """ + + name = 'Slash' + aliases = ['slash'] + filenames = ['*.sl'] + + def __init__(self, **options): + from pygments.lexers.web import HtmlLexer + super(SlashLexer, self).__init__(HtmlLexer, SlashLanguageLexer, **options) diff --git a/pygments/lexers/stata.py b/pygments/lexers/stata.py index a015a23e..9566d12a 100644 --- a/pygments/lexers/stata.py +++ b/pygments/lexers/stata.py @@ -9,6 +9,7 @@ :license: BSD, see LICENSE for details. """ +import re from pygments.lexer import RegexLexer, include, words from pygments.token import Comment, Keyword, Name, Number, \ String, Text, Operator @@ -33,56 +34,118 @@ class StataLexer(RegexLexer): aliases = ['stata', 'do'] filenames = ['*.do', '*.ado'] mimetypes = ['text/x-stata', 'text/stata', 'application/x-stata'] + flags = re.MULTILINE | re.DOTALL tokens = { 'root': [ include('comments'), - include('vars-strings'), + include('strings'), + include('macros'), include('numbers'), include('keywords'), + include('operators'), + include('format'), (r'.', Text), ], - # Global and local macros; regular and special strings - 'vars-strings': [ - (r'\$[\w{]', Name.Variable.Global, 'var_validglobal'), - (r'`\w{0,31}\'', Name.Variable), - (r'"', String, 'string_dquote'), - (r'`"', String, 'string_mquote'), - ], - # For either string type, highlight macros as macros - 'string_dquote': [ - (r'"', String, '#pop'), - (r'\\\\|\\"|\\\n', String.Escape), - (r'\$', Name.Variable.Global, 'var_validglobal'), - (r'`', Name.Variable, 'var_validlocal'), - (r'[^$`"\\]+', String), - (r'[$"\\]', String), - ], - 'string_mquote': [ + # Comments are a complicated beast in Stata because they can be + # nested and there are a few corner cases with that. See: + # - github.com/kylebarron/language-stata/issues/90 + # - statalist.org/forums/forum/general-stata-discussion/general/1448244 + 'comments': [ + (r'(^//|(?<=\s)//)(?!/)', Comment.Single, 'comments-double-slash'), + (r'^\s*\*', Comment.Single, 'comments-star'), + (r'/\*', Comment.Multiline, 'comments-block'), + (r'(^///|(?<=\s)///)', Comment.Special, 'comments-triple-slash') + ], + 'comments-block': [ + (r'/\*', Comment.Multiline, '#push'), + # this ends and restarts a comment block. but need to catch this so + # that it doesn\'t start _another_ level of comment blocks + (r'\*/\*', Comment.Multiline), + (r'(\*/\s+\*(?!/)[^\n]*)|(\*/)', Comment.Multiline, '#pop'), + # Match anything else as a character inside the comment + (r'.', Comment.Multiline), + ], + 'comments-star': [ + (r'///.*?\n', Comment.Single, + ('#pop', 'comments-triple-slash')), + (r'(^//|(?<=\s)//)(?!/)', Comment.Single, + ('#pop', 'comments-double-slash')), + (r'/\*', Comment.Multiline, 'comments-block'), + (r'.(?=\n)', Comment.Single, '#pop'), + (r'.', Comment.Single), + ], + 'comments-triple-slash': [ + (r'\n', Comment.Special, '#pop'), + # A // breaks out of a comment for the rest of the line + (r'//.*?(?=\n)', Comment.Single, '#pop'), + (r'.', Comment.Special), + ], + 'comments-double-slash': [ + (r'\n', Text, '#pop'), + (r'.', Comment.Single), + ], + # `"compound string"' and regular "string"; note the former are + # nested. + 'strings': [ + (r'`"', String, 'string-compound'), + (r'(?<!`)"', String, 'string-regular'), + ], + 'string-compound': [ + (r'`"', String, '#push'), (r'"\'', String, '#pop'), - (r'\\\\|\\"|\\\n', String.Escape), - (r'\$', Name.Variable.Global, 'var_validglobal'), - (r'`', Name.Variable, 'var_validlocal'), - (r'[^$`"\\]+', String), - (r'[$"\\]', String), - ], - 'var_validglobal': [ - (r'\{\w{0,32}\}', Name.Variable.Global, '#pop'), - (r'\w{1,32}', Name.Variable.Global, '#pop'), + (r'\\\\|\\"|\\\$|\\`|\\\n', String.Escape), + include('macros'), + (r'.', String) ], - 'var_validlocal': [ - (r'\w{0,31}\'', Name.Variable, '#pop'), + 'string-regular': [ + (r'(")(?!\')|(?=\n)', String, '#pop'), + (r'\\\\|\\"|\\\$|\\`|\\\n', String.Escape), + include('macros'), + (r'.', String) ], - # * only OK at line start, // OK anywhere - 'comments': [ - (r'^\s*\*.*$', Comment), - (r'//.*', Comment.Single), - (r'/\*.*?\*/', Comment.Multiline), - (r'/[*](.|\n)*?[*]/', Comment.Multiline), + # A local is usually + # `\w{0,31}' + # `:extended macro' + # `=expression' + # `[rsen](results)' + # `(++--)scalar(++--)' + # + # However, there are all sorts of weird rules wrt edge + # cases. Instead of writing 27 exceptions, anything inside + # `' is a local. + # + # A global is more restricted, so we do follow rules. Note only + # locals explicitly enclosed ${} can be nested. + 'macros': [ + (r'\$(\{|(?=[\$`]))', Name.Variable.Global, 'macro-global-nested'), + (r'\$', Name.Variable.Global, 'macro-global-name'), + (r'`', Name.Variable, 'macro-local'), + ], + 'macro-local': [ + (r'`', Name.Variable, '#push'), + (r"'", Name.Variable, '#pop'), + (r'\$(\{|(?=[\$`]))', Name.Variable.Global, 'macro-global-nested'), + (r'\$', Name.Variable.Global, 'macro-global-name'), + (r'.', Name.Variable), # fallback + ], + 'macro-global-nested': [ + (r'\$(\{|(?=[\$`]))', Name.Variable.Global, '#push'), + (r'\}', Name.Variable.Global, '#pop'), + (r'\$', Name.Variable.Global, 'macro-global-name'), + (r'`', Name.Variable, 'macro-local'), + (r'\w', Name.Variable.Global), # fallback + (r'(?!\w)', Name.Variable.Global, '#pop'), + ], + 'macro-global-name': [ + (r'\$(\{|(?=[\$`]))', Name.Variable.Global, 'macro-global-nested', '#pop'), + (r'\$', Name.Variable.Global, 'macro-global-name', '#pop'), + (r'`', Name.Variable, 'macro-local', '#pop'), + (r'\w{1,32}', Name.Variable.Global, '#pop'), ], # Built in functions and statements 'keywords': [ - (words(builtins_functions, prefix = r'\b', suffix = r'\('), + (words(builtins_functions, prefix = r'\b', suffix = r'(?=\()'), Name.Function), (words(builtins_base, prefix = r'(^\s*|\s)', suffix = r'\b'), Keyword), @@ -100,9 +163,9 @@ class StataLexer(RegexLexer): ], # Stata formats 'format': [ - (r'%-?\d{1,2}(\.\d{1,2})?[gfe]c?', Name.Variable), - (r'%(21x|16H|16L|8H|8L)', Name.Variable), - (r'%-?(tc|tC|td|tw|tm|tq|th|ty|tg).{0,32}', Name.Variable), - (r'%[-~]?\d{1,4}s', Name.Variable), + (r'%-?\d{1,2}(\.\d{1,2})?[gfe]c?', Name.Other), + (r'%(21x|16H|16L|8H|8L)', Name.Other), + (r'%-?(tc|tC|td|tw|tm|tq|th|ty|tg)\S{0,32}', Name.Other), + (r'%[-~]?\d{1,4}s', Name.Other), ] } diff --git a/pygments/lexers/unicon.py b/pygments/lexers/unicon.py new file mode 100644 index 00000000..6301a88b --- /dev/null +++ b/pygments/lexers/unicon.py @@ -0,0 +1,390 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.icon + ~~~~~~~~~~~~~~~~~~~~ + + Lexers for the Icon and Unicon languages, including ucode VM. + + :copyright: Copyright 2006-2016 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import Lexer, RegexLexer, include, bygroups, words, \ + using, this, default +from pygments.util import get_bool_opt, get_list_opt +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Punctuation, Error +from pygments.scanner import Scanner + +__all__ = ['IconLexer', 'UcodeLexer', 'UniconLexer'] + +class UniconLexer(RegexLexer): + """ + For Unicon source code. + + .. versionadded:: 2.4 + """ + + name = 'Unicon' + aliases = ['unicon'] + filenames = ['*.icn'] + mimetypes = ['text/unicon'] + + flags = re.MULTILINE + + tokens = { + 'root': [ + (r'[^\S\n]+', Text), + (r'#.*?\n', Comment.Single), + (r'[^\S\n]+', Text), + (r'class|method|procedure', Keyword.Declaration, 'subprogram'), + (r'(record)(\s+)(\w+)', + bygroups(Keyword.Declaration, Text, Keyword.Type), 'type_def'), + (r'(#line|\$C|\$Cend|\$define|\$else|\$endif|\$error|\$ifdef|' + r'\$ifndef|\$include|\$line|\$undef)\b', Keyword.PreProc), + (r'(&null|&fail)\b', Keyword.Constant), + (r'&allocated|&ascii|&clock|&collections|&column|&col|&control|' + r'&cset|¤t|&dateline|&date|&digits|&dump|' + r'&errno|&errornumber|&errortext|&errorvalue|&error|&errout|' + r'&eventcode|&eventvalue|&eventsource|&e|' + r'&features|&file|&host|&input|&interval|&lcase|&letters|' + r'&level|&line|&ldrag|&lpress|&lrelease|' + r'&main|&mdrag|&meta|&mpress|&mrelease|&now|&output|' + r'&phi|&pick|&pi|&pos|&progname|' + r'&random|&rdrag|®ions|&resize|&row|&rpress|&rrelease|' + r'&shift|&source|&storage|&subject|' + r'&time|&trace|&ucase|&version|' + r'&window|&x|&y', Keyword.Reserved), + (r'(by|of|not|to)\b', Keyword.Reserved), + (r'(global|local|static|abstract)\b', Keyword.Reserved), + (r'package|link|import', Keyword.Declaration), + (words(( + 'break', 'case', 'create', 'critical', 'default', 'end', 'all', + 'do', 'else', 'every', 'fail', 'if', 'import', 'initial', + 'initially', 'invocable', 'next', + 'repeat', 'return', 'suspend', + 'then', 'thread', 'until', 'while'), prefix=r'\b', suffix=r'\b'), + Keyword.Reserved), + (words(( + 'Abort', 'abs', 'acos', 'Active', 'Alert', 'any', 'Any', 'Arb', + 'Arbno', 'args', 'array', 'asin', 'atan', 'atanh', 'Attrib', + 'Bal', 'bal', 'Bg', 'Break', 'Breakx', + 'callout', 'center', 'char', 'chdir', 'chmod', 'chown', 'chroot', + 'classname', 'Clip', 'Clone', 'close', 'cofail', 'collect', + 'Color', 'ColorValue', 'condvar', 'constructor', 'copy', + 'CopyArea', 'cos', 'Couple', 'crypt', 'cset', 'ctime', + 'dbcolumns', 'dbdriver', 'dbkeys', 'dblimits', 'dbproduct', + 'dbtables', 'delay', 'delete', 'detab', 'display', 'DrawArc', + 'DrawCircle', 'DrawCube', 'DrawCurve', 'DrawCylinder', + 'DrawDisk', 'DrawImage', 'DrawLine', 'DrawPoint', 'DrawPolygon', + 'DrawRectangle', 'DrawSegment', 'DrawSphere', 'DrawString', + 'DrawTorus', 'dtor', + 'entab', 'EraseArea', 'errorclear', 'Event', 'eventmask', + 'EvGet', 'EvSend', 'exec', 'exit', 'exp', 'Eye', + 'Fail', 'fcntl', 'fdup', 'Fence', 'fetch', 'Fg', 'fieldnames', + 'filepair', 'FillArc', 'FillCircle', 'FillPolygon', + 'FillRectangle', 'find', 'flock', 'flush', 'Font', 'fork', + 'FreeColor', 'FreeSpace', 'function', + 'get', 'getch', 'getche', 'getegid', 'getenv', 'geteuid', + 'getgid', 'getgr', 'gethost', 'getpgrp', 'getpid', 'getppid', + 'getpw', 'getrusage', 'getserv', 'GetSpace', 'gettimeofday', + 'getuid', 'globalnames', 'GotoRC', 'GotoXY', 'gtime', 'hardlink', + 'iand', 'icom', 'IdentityMatrix', 'image', 'InPort', 'insert', + 'Int86', 'integer', 'ioctl', 'ior', 'ishift', 'istate', 'ixor', + 'kbhit', 'key', 'keyword', 'kill', + 'left', 'Len', 'list', 'load', 'loadfunc', 'localnames', + 'lock', 'log', 'Lower', 'lstat', + 'many', 'map', 'match', 'MatrixMode', 'max', 'member', + 'membernames', 'methodnames', 'methods', 'min', 'mkdir', 'move', + 'MultMatrix', 'mutex', + 'name', 'NewColor', 'Normals', 'NotAny', 'numeric', + 'open', 'opencl', 'oprec', 'ord', 'OutPort', + 'PaletteChars', 'PaletteColor', 'PaletteKey', 'paramnames', + 'parent', 'Pattern', 'Peek', 'Pending', 'pipe', 'Pixel', + 'PlayAudio', 'Poke', 'pop', 'PopMatrix', 'Pos', 'pos', + 'proc', 'pull', 'push', 'PushMatrix', 'PushRotate', 'PushScale', + 'PushTranslate', 'put', + 'QueryPointer', + 'Raise', 'read', 'ReadImage', 'readlink', 'reads', 'ready', + 'real', 'receive', 'Refresh', 'Rem', 'remove', 'rename', + 'repl', 'reverse', 'right', 'rmdir', 'Rotate', 'Rpos', + 'Rtab', 'rtod', 'runerr', + 'save', 'Scale', 'seek', 'select', 'send', 'seq', + 'serial', 'set', 'setenv', 'setgid', 'setgrent', + 'sethostent', 'setpgrp', 'setpwent', 'setservent', + 'setuid', 'signal', 'sin', 'sort', 'sortf', 'Span', + 'spawn', 'sql', 'sqrt', 'stat', 'staticnames', 'stop', + 'StopAudio', 'string', 'structure', 'Succeed', 'Swi', + 'symlink', 'sys_errstr', 'system', 'syswrite', + 'Tab', 'tab', 'table', 'tan', + 'Texcoord', 'Texture', 'TextWidth', 'Translate', + 'trap', 'trim', 'truncate', 'trylock', 'type', + 'umask', 'Uncouple', 'unlock', 'upto', 'utime', + 'variable', 'VAttrib', + 'wait', 'WAttrib', 'WDefault', 'WFlush', 'where', + 'WinAssociate', 'WinButton', 'WinColorDialog', 'WindowContents', + 'WinEditRegion', 'WinFontDialog', 'WinMenuBar', 'WinOpenDialog', + 'WinPlayMedia', 'WinSaveDialog', 'WinScrollBar', 'WinSelectDialog', + 'write', 'WriteImage', 'writes', 'WSection', + 'WSync'), prefix=r'\b', suffix=r'\b'), + Name.Function), + include('numbers'), + (r'<@|<<@|>@|>>@|\.>|\->', Operator), + (r'\*\*|\+\+|\-\-|\.|\=|\~\=|<\=|>\=|\=\=|\~\=\=|<<|<<\=|>>|>>\=', Operator), + (r':\=|:\=:|\->|<\->|\+:\=|\|', Operator), + (r'\=\=\=|\~\=\=\=', Operator), + (r'"(?:[^\\"]|\\.)*"', String), + (r"'(?:[^\\']|\\.)*'", String.Character), + (r'[*<>+=/&!?@~\\-]', Operator), + (r'\^', Operator), + (r'(\w+)(\s*|[(,])', bygroups(Name, using(this))), + (r"([\[\]])", Punctuation), + (r"(<>|=>|[()|:;,.'`]|[{}]|[%]|[&?])", Punctuation), + (r'\n+', Text), + ], + 'numbers': [ + (r'\b([+-]?([2-9]|[12][0-9]|3[0-6])[rR][0-9a-zA-Z]+)\b', Number.Hex), + (r'[+-]?[0-9]*\.([0-9]*)([Ee][+-]?[0-9]*)?', Number.Float), + (r'\b([+-]?[0-9]+[KMGTPkmgtp]?)\b', Number.Integer), + ], + 'subprogram': [ + (r'\(', Punctuation, ('#pop', 'formal_part')), + (r';', Punctuation, '#pop'), + (r'"[^"]+"|\w+', Name.Function), + include('root'), + ], + 'type_def': [ + (r'\(', Punctuation, 'formal_part'), + ], + 'formal_part': [ + (r'\)', Punctuation, '#pop'), + (r'\w+', Name.Variable), + (r',', Punctuation), + (r'(:string|:integer|:real)\b', Keyword.Reserved), + include('root'), + ], + } + +class IconLexer(RegexLexer): + """ + Lexer for Icon + + .. versionadded:: 1.6 + """ + name = 'Icon' + aliases = ['icon'] + filenames = ['*.icon', '*.ICON'] + mimetypes = [] + flags = re.MULTILINE + + tokens = { + 'root': [ + (r'[^\S\n]+', Text), + (r'#.*?\n', Comment.Single), + (r'[^\S\n]+', Text), + (r'class|method|procedure', Keyword.Declaration, 'subprogram'), + (r'(record)(\s+)(\w+)', + bygroups(Keyword.Declaration, Text, Keyword.Type), 'type_def'), + (r'(#line|\$C|\$Cend|\$define|\$else|\$endif|\$error|\$ifdef|' + r'\$ifndef|\$include|\$line|\$undef)\b', Keyword.PreProc), + (r'(&null|&fail)\b', Keyword.Constant), + (r'&allocated|&ascii|&clock|&collections|&column|&col|&control|' + r'&cset|¤t|&dateline|&date|&digits|&dump|' + r'&errno|&errornumber|&errortext|&errorvalue|&error|&errout|' + r'&eventcode|&eventvalue|&eventsource|&e|' + r'&features|&file|&host|&input|&interval|&lcase|&letters|' + r'&level|&line|&ldrag|&lpress|&lrelease|' + r'&main|&mdrag|&meta|&mpress|&mrelease|&now|&output|' + r'&phi|&pick|&pi|&pos|&progname|' + r'&random|&rdrag|®ions|&resize|&row|&rpress|&rrelease|' + r'&shift|&source|&storage|&subject|' + r'&time|&trace|&ucase|&version|' + r'&window|&x|&y', Keyword.Reserved), + (r'(by|of|not|to)\b', Keyword.Reserved), + (r'(global|local|static)\b', Keyword.Reserved), + (r'link', Keyword.Declaration), + (words(( + 'break', 'case', 'create', 'default', 'end', 'all', + 'do', 'else', 'every', 'fail', 'if', 'initial', + 'invocable', 'next', + 'repeat', 'return', 'suspend', + 'then', 'until', 'while'), prefix=r'\b', suffix=r'\b'), + Keyword.Reserved), + (words(( + 'abs', 'acos', 'Active', 'Alert', 'any', + 'args', 'array', 'asin', 'atan', 'atanh', 'Attrib', + 'bal', 'Bg', + 'callout', 'center', 'char', 'chdir', 'chmod', 'chown', 'chroot', + 'Clip', 'Clone', 'close', 'cofail', 'collect', + 'Color', 'ColorValue', 'condvar', 'copy', + 'CopyArea', 'cos', 'Couple', 'crypt', 'cset', 'ctime', + 'delay', 'delete', 'detab', 'display', 'DrawArc', + 'DrawCircle', 'DrawCube', 'DrawCurve', 'DrawCylinder', + 'DrawDisk', 'DrawImage', 'DrawLine', 'DrawPoint', 'DrawPolygon', + 'DrawRectangle', 'DrawSegment', 'DrawSphere', 'DrawString', + 'DrawTorus', 'dtor', + 'entab', 'EraseArea', 'errorclear', 'Event', 'eventmask', + 'EvGet', 'EvSend', 'exec', 'exit', 'exp', 'Eye', + 'fcntl', 'fdup', 'fetch', 'Fg', 'fieldnames', + 'FillArc', 'FillCircle', 'FillPolygon', + 'FillRectangle', 'find', 'flock', 'flush', 'Font', + 'FreeColor', 'FreeSpace', 'function', + 'get', 'getch', 'getche', 'getenv', + 'GetSpace', 'gettimeofday', + 'getuid', 'globalnames', 'GotoRC', 'GotoXY', 'gtime', 'hardlink', + 'iand', 'icom', 'IdentityMatrix', 'image', 'InPort', 'insert', + 'Int86', 'integer', 'ioctl', 'ior', 'ishift', 'istate', 'ixor', + 'kbhit', 'key', 'keyword', 'kill', + 'left', 'Len', 'list', 'load', 'loadfunc', 'localnames', + 'lock', 'log', 'Lower', 'lstat', + 'many', 'map', 'match', 'MatrixMode', 'max', 'member', + 'membernames', 'methodnames', 'methods', 'min', 'mkdir', 'move', + 'MultMatrix', 'mutex', + 'name', 'NewColor', 'Normals', 'numeric', + 'open', 'opencl', 'oprec', 'ord', 'OutPort', + 'PaletteChars', 'PaletteColor', 'PaletteKey', 'paramnames', + 'parent', 'Pattern', 'Peek', 'Pending', 'pipe', 'Pixel', + 'Poke', 'pop', 'PopMatrix', 'Pos', 'pos', + 'proc', 'pull', 'push', 'PushMatrix', 'PushRotate', 'PushScale', + 'PushTranslate', 'put', + 'QueryPointer', + 'Raise', 'read', 'ReadImage', 'readlink', 'reads', 'ready', + 'real', 'receive', 'Refresh', 'Rem', 'remove', 'rename', + 'repl', 'reverse', 'right', 'rmdir', 'Rotate', 'Rpos', + 'rtod', 'runerr', + 'save', 'Scale', 'seek', 'select', 'send', 'seq', + 'serial', 'set', 'setenv', + 'setuid', 'signal', 'sin', 'sort', 'sortf', + 'spawn', 'sql', 'sqrt', 'stat', 'staticnames', 'stop', + 'string', 'structure', 'Swi', + 'symlink', 'sys_errstr', 'system', 'syswrite', + 'tab', 'table', 'tan', + 'Texcoord', 'Texture', 'TextWidth', 'Translate', + 'trap', 'trim', 'truncate', 'trylock', 'type', + 'umask', 'Uncouple', 'unlock', 'upto', 'utime', + 'variable', + 'wait', 'WAttrib', 'WDefault', 'WFlush', 'where', + 'WinAssociate', 'WinButton', 'WinColorDialog', 'WindowContents', + 'WinEditRegion', 'WinFontDialog', 'WinMenuBar', 'WinOpenDialog', + 'WinPlayMedia', 'WinSaveDialog', 'WinScrollBar', 'WinSelectDialog', + 'write', 'WriteImage', 'writes', 'WSection', + 'WSync'), prefix=r'\b', suffix=r'\b'), + Name.Function), + include('numbers'), + (r'\*\*|\+\+|\-\-|\.|\=|\~\=|<\=|>\=|\=\=|\~\=\=|<<|<<\=|>>|>>\=', Operator), + (r':\=|:\=:|<\-|<\->|\+:\=|\||\|\|', Operator), + (r'\=\=\=|\~\=\=\=', Operator), + (r'"(?:[^\\"]|\\.)*"', String), + (r"'(?:[^\\']|\\.)*'", String.Character), + (r'[*<>+=/&!?@~\\-]', Operator), + (r'(\w+)(\s*|[(,])', bygroups(Name, using(this))), + (r"([\[\]])", Punctuation), + (r"(<>|=>|[()|:;,.'`]|[{}]|[%^]|[&?])", Punctuation), + (r'\n+', Text), + ], + 'numbers': [ + (r'\b([+-]?([2-9]|[12][0-9]|3[0-6])[rR][0-9a-zA-Z]+)\b', Number.Hex), + (r'[+-]?[0-9]*\.([0-9]*)([Ee][+-]?[0-9]*)?', Number.Float), + (r'\b([+-]?[0-9]+[KMGTPkmgtp]?)\b', Number.Integer), + ], + 'subprogram': [ + (r'\(', Punctuation, ('#pop', 'formal_part')), + (r';', Punctuation, '#pop'), + (r'"[^"]+"|\w+', Name.Function), + include('root'), + ], + 'type_def': [ + (r'\(', Punctuation, 'formal_part'), + ], + 'formal_part': [ + (r'\)', Punctuation, '#pop'), + (r'\w+', Name.Variable), + (r',', Punctuation), + (r'(:string|:integer|:real)\b', Keyword.Reserved), + include('root'), + ], + } + +class UcodeLexer(RegexLexer): + """ + Lexer for Icon ucode files + + .. versionadded:: 2.4 + """ + name = 'ucode' + aliases = ['ucode'] + filenames = ['*.u', '*.u1', '*.u2'] + mimetypes = [] + flags = re.MULTILINE + + tokens = { + 'root': [ + (r'(#.*\n)', Comment), + (words(( + 'con', 'declend', 'end', + 'global', + 'impl', 'invocable', + 'lab', 'link', 'local', + 'record', + 'uid', 'unions', + 'version'), + prefix=r'\b', suffix=r'\b'), + Name.Function), + (words(( + 'colm', 'filen', 'line', 'synt'), + prefix=r'\b', suffix=r'\b'), + Comment), + (words(( + 'asgn', + 'bang', 'bscan', + 'cat', 'ccase', 'chfail', + 'coact', 'cofail', 'compl', + 'coret', 'create', 'cset', + 'diff', 'div', 'dup', + 'efail', 'einit', 'end', 'eqv', 'eret', + 'error', 'escan', 'esusp', + 'field', + 'goto', + 'init', 'int', 'inter', + 'invoke', + 'keywd', + 'lconcat', 'lexeq', 'lexge', + 'lexgt', 'lexle', 'lexlt', 'lexne', + 'limit', 'llist', 'lsusp', + 'mark', 'mark0', 'minus', 'mod', 'mult', + 'neg', 'neqv', 'nonnull', 'noop', 'null', + 'number', 'numeq', 'numge', 'numgt', + 'numle', 'numlt', 'numne', + 'pfail', 'plus', 'pnull', 'pop', 'power', + 'pret', 'proc', 'psusp', 'push1', 'pushn1', + 'random', 'rasgn', 'rcv', 'rcvbk', 'real', + 'refresh', 'rswap', + 'sdup', 'sect', 'size', 'snd', 'sndbk', + 'str', 'subsc', 'swap', + 'tabmat', 'tally', 'toby', 'trace', + 'unmark', + 'value', 'var'), prefix=r'\b', suffix=r'\b'), + Keyword.Declaration), + (words(( + 'any', + 'case', + 'endcase', 'endevery', 'endif', + 'endifelse', 'endrepeat', 'endsuspend', + 'enduntil', 'endwhile', 'every', + 'if', 'ifelse', + 'repeat', + 'suspend', + 'until', + 'while'), + prefix=r'\b', suffix=r'\b'), + Name.Constant), + (r'\d+(\s*|\.$|$)', Number.Integer), + (r'[+-]?\d*\.\d+(E[-+]?\d+)?', Number.Float), + (r'[+-]?\d+\.\d*(E[-+]?\d+)?', Number.Float), + (r"(<>|=>|[()|:;,.'`]|[{}]|[%^]|[&?])", Punctuation), + (r'\s+\b', Text), + (r'[\w-]+', Text), + ], +} diff --git a/pygments/styles/__init__.py b/pygments/styles/__init__.py index 1f39c692..c7050a18 100644 --- a/pygments/styles/__init__.py +++ b/pygments/styles/__init__.py @@ -46,6 +46,10 @@ STYLE_MAP = { 'abap': 'abap::AbapStyle', 'solarized-dark': 'solarized::SolarizedDarkStyle', 'solarized-light': 'solarized::SolarizedLightStyle', + 'sas': 'sas::SasStyle', + 'stata': 'stata_light::StataLightStyle', + 'stata-light': 'stata_light::StataLightStyle', + 'stata-dark': 'stata_dark::StataDarkStyle', } diff --git a/pygments/styles/stata_dark.py b/pygments/styles/stata_dark.py new file mode 100644 index 00000000..851a9a8d --- /dev/null +++ b/pygments/styles/stata_dark.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +""" + pygments.styles.stata_dark + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Dark style inspired by Stata's do-file editor. Note this is not + meant to be a complete style, just for Stata's file formats. + + + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from pygments.style import Style +from pygments.token import Keyword, Name, Comment, String, Error, \ + Number, Operator, Whitespace, Generic, Text + + +class StataDarkStyle(Style): + + default_style = '' + + background_color = "#232629" + highlight_color = "#49483e" + + styles = { + Whitespace: '#bbbbbb', + Error: 'bg:#e3d2d2 #a61717', + Text: '#cccccc', + String: '#51cc99', + Number: '#4FB8CC', + Operator: '', + Name.Function: '#6a6aff', + Name.Other: '#e2828e', + Keyword: 'bold #7686bb', + Keyword.Constant: '', + Comment: 'italic #777777', + Name.Variable: 'bold #7AB4DB', + Name.Variable.Global: 'bold #BE646C', + Generic.Prompt: '#ffffff', + } diff --git a/pygments/styles/stata.py b/pygments/styles/stata_light.py index 2b5f5edd..fcca85e5 100644 --- a/pygments/styles/stata.py +++ b/pygments/styles/stata_light.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- """ - pygments.styles.stata - ~~~~~~~~~~~~~~~~~~~~~ + pygments.styles.stata_light + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Style inspired by Stata's do-file editor. Note this is not meant - to be a complete style. It's merely meant to mimic Stata's do file - editor syntax highlighting. + Light Style inspired by Stata's do-file editor. Note this is not + meant to be a complete style, just for Stata's file formats. :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. @@ -13,28 +12,28 @@ from pygments.style import Style from pygments.token import Keyword, Name, Comment, String, Error, \ - Number, Operator, Whitespace + Number, Operator, Whitespace, Text -class StataStyle(Style): +class StataLightStyle(Style): """ - Style inspired by Stata's do-file editor. Note this is not meant - to be a complete style. It's merely meant to mimic Stata's do file - editor syntax highlighting. + Light mode style inspired by Stata's do-file editor. This is not + meant to be a complete style, just for use with Stata. """ default_style = '' - styles = { + Text: '#111111', Whitespace: '#bbbbbb', - Comment: 'italic #008800', + Error: 'bg:#e3d2d2 #a61717', String: '#7a2424', Number: '#2c2cff', Operator: '', + Name.Function: '#2c2cff', + Name.Other: '#be646c', Keyword: 'bold #353580', Keyword.Constant: '', - Name.Function: '#2c2cff', + Comment: 'italic #008800', Name.Variable: 'bold #35baba', Name.Variable.Global: 'bold #b5565e', - Error: 'bg:#e3d2d2 #a61717' } |