diff options
author | Tim Hatch <tim@timhatch.com> | 2012-10-06 18:07:46 -0700 |
---|---|---|
committer | Tim Hatch <tim@timhatch.com> | 2012-10-06 18:07:46 -0700 |
commit | f8c85345af939357e58c22cceb91a57578ff9e36 (patch) | |
tree | c57a17af05d45727ff87a53ca95174a951cb7251 /pygments | |
parent | 45e4d8e91c7ad29af745a82182f173bd096fc612 (diff) | |
download | pygments-f8c85345af939357e58c22cceb91a57578ff9e36.tar.gz |
Move SourcePawn lexer from compiled to other
Diffstat (limited to 'pygments')
-rw-r--r-- | pygments/lexers/_mapping.py | 2 | ||||
-rw-r--r-- | pygments/lexers/compiled.py | 109 | ||||
-rw-r--r-- | pygments/lexers/other.py | 109 |
3 files changed, 110 insertions, 110 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index d0c90ec2..5c20f28a 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -238,7 +238,7 @@ LEXERS = { 'SmalltalkLexer': ('pygments.lexers.other', 'Smalltalk', ('smalltalk', 'squeak'), ('*.st',), ('text/x-smalltalk',)), 'SmartyLexer': ('pygments.lexers.templates', 'Smarty', ('smarty',), ('*.tpl',), ('application/x-smarty',)), 'SnobolLexer': ('pygments.lexers.other', 'Snobol', ('snobol',), ('*.snobol',), ('text/x-snobol',)), - 'SourcePawnLexer': ('pygments.lexers.compiled', 'SourcePawn', ('sp',), ('*.sp', '*.inc'), ('text/x-sourcepawn',)), + 'SourcePawnLexer': ('pygments.lexers.other', 'SourcePawn', ('sp',), ('*.sp',), ('text/x-sourcepawn',)), 'SourcesListLexer': ('pygments.lexers.text', 'Debian Sourcelist', ('sourceslist', 'sources.list'), ('sources.list',), ()), 'SqlLexer': ('pygments.lexers.sql', 'SQL', ('sql',), ('*.sql',), ('text/x-sql',)), 'SqliteConsoleLexer': ('pygments.lexers.sql', 'sqlite3con', ('sqlite3',), ('*.sqlite3-console',), ('text/x-sqlite3-console',)), diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py index 1465c6c3..450a9c4d 100644 --- a/pygments/lexers/compiled.py +++ b/pygments/lexers/compiled.py @@ -27,8 +27,7 @@ __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'ECLexer', 'DylanLexer', 'ObjectiveCLexer', 'FortranLexer', 'GLShaderLexer', 'PrologLexer', 'CythonLexer', 'ValaLexer', 'OocLexer', 'GoLexer', 'FelixLexer', 'AdaLexer', 'Modula2Lexer', 'BlitzMaxLexer', - 'NimrodLexer', 'FantomLexer', 'RustLexer', 'CUDALexer', - 'SourcePawnLexer'] + 'NimrodLexer', 'FantomLexer', 'RustLexer', 'CUDALexer'] class CLexer(RegexLexer): @@ -3051,109 +3050,3 @@ class CUDALexer(CLexer): elif value in self.functions: token = Name.Function yield index, token, value - - -class SourcePawnLexer(RegexLexer): - """ - For SourcePawn source code with preprocessor directives. - """ - name = 'SourcePawn' - aliases = ['sp'] - filenames = ['*.sp'] - mimetypes = ['text/x-sourcepawn'] - - #: optional Comment or Whitespace - _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' - - tokens = { - 'root': [ - # preprocessor directives: without whitespace - ('^#if\s+0', Comment.Preproc, 'if0'), - ('^#', Comment.Preproc, 'macro'), - # or with whitespace - ('^' + _ws + r'#if\s+0', Comment.Preproc, 'if0'), - ('^' + _ws + '#', Comment.Preproc, 'macro'), - (r'\n', Text), - (r'\s+', Text), - (r'\\\n', Text), # line continuation - (r'/(\\\n)?/(\n|(.|\n)*?[^\\]\n)', Comment.Single), - (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), - (r'[{}]', Punctuation), - (r'L?"', String, 'string'), - (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char), - (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*', Number.Float), - (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), - (r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex), - (r'0[0-7]+[LlUu]*', Number.Oct), - (r'\d+[LlUu]*', Number.Integer), - (r'\*/', Error), - (r'[~!%^&*+=|?:<>/-]', Operator), - (r'[()\[\],.;]', Punctuation), - (r'(case|const|continue|native|' - r'default|else|enum|for|if|new|operator|' - r'public|return|sizeof|static|decl|struct|switch)\b', Keyword), - (r'(bool|Float)\b', Keyword.Type), - (r'(true|false)\b', Keyword.Constant), - ('[a-zA-Z_][a-zA-Z0-9_]*', Name), - ], - '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), - ] - } - - sm_types = ['Action', 'bool', 'Float', 'Plugin', 'String', 'any', - 'AdminFlag','OverrideType','OverrideRule','ImmunityType', - 'GroupId','AdminId','AdmAccessMode','AdminCachePart', - 'CookieAccess','CookieMenu','CookieMenuAction','NetFlow', - 'ConVarBounds','QueryCookie','ReplySource','ConVarQueryResult', - 'ConVarQueryFinished','Function','Action','Identity','PluginStatus', - 'PluginInfo','DBResult','DBBindType','DBPriority','PropType', - 'PropFieldType', 'MoveType','RenderMode','RenderFx','EventHookMode', - 'EventHook','FileType', 'FileTimeMode','PathType','ParamType', - 'ExecType','DialogType','Handle', 'KvDataTypes','NominateResult', - 'MapChange','MenuStyle','MenuAction', 'MenuSource','RegexError', - 'SDKCallType','SDKLibrary','SDKFuncConfSource','SDKType', - 'SDKPassMethod','RayType','TraceEntityFilter','ListenOverride', - 'SortOrder','SortType','SortFunc2D','APLRes','FeatureType', - 'FeatureStatus','SMCResult','SMCError','TFClassType','TFTeam', - 'TFCond','TFResourceType','Timer','TopMenuAction','TopMenuObjectType', - 'TopMenuPosition','TopMenuObject','UserMsg'] - - def __init__(self, **options): - self.smhighlighting = get_bool_opt(options, - 'sourcemod', True) - - self._functions = list() - if self.smhighlighting: - from pygments.lexers._sourcemodbuiltins import FUNCTIONS - for func in FUNCTIONS: - self._functions.append(func) - RegexLexer.__init__(self, **options) - - def get_tokens_unprocessed(self, text): - for index, token, value in \ - RegexLexer.get_tokens_unprocessed(self, text): - if token is Name: - if self.smhighlighting: - if value in self.sm_types: - token = Keyword.Type - elif value in self._functions: - tokens = Name.Builtin - yield index, token, value diff --git a/pygments/lexers/other.py b/pygments/lexers/other.py index 49d432e3..90b4ac8f 100644 --- a/pygments/lexers/other.py +++ b/pygments/lexers/other.py @@ -15,6 +15,7 @@ from pygments.lexer import RegexLexer, include, bygroups, using, \ this, combined, ExtendedRegexLexer from pygments.token import Error, Punctuation, Literal, Token, \ Text, Comment, Operator, Keyword, Name, String, Number, Generic +from pygments.util import get_bool_opt from pygments.lexers.web import HtmlLexer @@ -30,7 +31,7 @@ __all__ = ['BrainfuckLexer', 'BefungeLexer', 'RedcodeLexer', 'MOOCodeLexer', 'AutohotkeyLexer', 'GoodDataCLLexer', 'MaqlLexer', 'ProtoBufLexer', 'HybrisLexer', 'AwkLexer', 'Cfengine3Lexer', 'SnobolLexer', 'ECLLexer', 'UrbiscriptLexer', 'OpenEdgeLexer', 'BroLexer', - 'MscgenLexer', 'KconfigLexer', 'VGLLexer'] + 'MscgenLexer', 'KconfigLexer', 'VGLLexer', 'SourcePawnLexer'] class ECLLexer(RegexLexer): @@ -3515,3 +3516,109 @@ class VGLLexer(RegexLexer): (r'\s+', Text) ] } + + +class SourcePawnLexer(RegexLexer): + """ + For SourcePawn source code with preprocessor directives. + """ + name = 'SourcePawn' + aliases = ['sp'] + filenames = ['*.sp'] + mimetypes = ['text/x-sourcepawn'] + + #: optional Comment or Whitespace + _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' + + tokens = { + 'root': [ + # preprocessor directives: without whitespace + ('^#if\s+0', Comment.Preproc, 'if0'), + ('^#', Comment.Preproc, 'macro'), + # or with whitespace + ('^' + _ws + r'#if\s+0', Comment.Preproc, 'if0'), + ('^' + _ws + '#', Comment.Preproc, 'macro'), + (r'\n', Text), + (r'\s+', Text), + (r'\\\n', Text), # line continuation + (r'/(\\\n)?/(\n|(.|\n)*?[^\\]\n)', Comment.Single), + (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), + (r'[{}]', Punctuation), + (r'L?"', String, 'string'), + (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char), + (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*', Number.Float), + (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), + (r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex), + (r'0[0-7]+[LlUu]*', Number.Oct), + (r'\d+[LlUu]*', Number.Integer), + (r'\*/', Error), + (r'[~!%^&*+=|?:<>/-]', Operator), + (r'[()\[\],.;]', Punctuation), + (r'(case|const|continue|native|' + r'default|else|enum|for|if|new|operator|' + r'public|return|sizeof|static|decl|struct|switch)\b', Keyword), + (r'(bool|Float)\b', Keyword.Type), + (r'(true|false)\b', Keyword.Constant), + ('[a-zA-Z_][a-zA-Z0-9_]*', Name), + ], + '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), + ] + } + + sm_types = ['Action', 'bool', 'Float', 'Plugin', 'String', 'any', + 'AdminFlag','OverrideType','OverrideRule','ImmunityType', + 'GroupId','AdminId','AdmAccessMode','AdminCachePart', + 'CookieAccess','CookieMenu','CookieMenuAction','NetFlow', + 'ConVarBounds','QueryCookie','ReplySource','ConVarQueryResult', + 'ConVarQueryFinished','Function','Action','Identity','PluginStatus', + 'PluginInfo','DBResult','DBBindType','DBPriority','PropType', + 'PropFieldType', 'MoveType','RenderMode','RenderFx','EventHookMode', + 'EventHook','FileType', 'FileTimeMode','PathType','ParamType', + 'ExecType','DialogType','Handle', 'KvDataTypes','NominateResult', + 'MapChange','MenuStyle','MenuAction', 'MenuSource','RegexError', + 'SDKCallType','SDKLibrary','SDKFuncConfSource','SDKType', + 'SDKPassMethod','RayType','TraceEntityFilter','ListenOverride', + 'SortOrder','SortType','SortFunc2D','APLRes','FeatureType', + 'FeatureStatus','SMCResult','SMCError','TFClassType','TFTeam', + 'TFCond','TFResourceType','Timer','TopMenuAction','TopMenuObjectType', + 'TopMenuPosition','TopMenuObject','UserMsg'] + + def __init__(self, **options): + self.smhighlighting = get_bool_opt(options, + 'sourcemod', True) + + self._functions = list() + if self.smhighlighting: + from pygments.lexers._sourcemodbuiltins import FUNCTIONS + for func in FUNCTIONS: + self._functions.append(func) + RegexLexer.__init__(self, **options) + + def get_tokens_unprocessed(self, text): + for index, token, value in \ + RegexLexer.get_tokens_unprocessed(self, text): + if token is Name: + if self.smhighlighting: + if value in self.sm_types: + token = Keyword.Type + elif value in self._functions: + tokens = Name.Builtin + yield index, token, value |