ThirdParty/Pygments/pygments/lexers/scripting.py

changeset 5713
6762afd9f963
parent 4697
c2e9bf425554
child 6651
e8f3b5568b21
equal deleted inserted replaced
5712:f0d08bdeacf4 5713:6762afd9f963
3 pygments.lexers.scripting 3 pygments.lexers.scripting
4 ~~~~~~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexer for scripting and embedded languages. 6 Lexer for scripting and embedded languages.
7 7
8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 import re 12 import re
13 13
48 name = 'Lua' 48 name = 'Lua'
49 aliases = ['lua'] 49 aliases = ['lua']
50 filenames = ['*.lua', '*.wlua'] 50 filenames = ['*.lua', '*.wlua']
51 mimetypes = ['text/x-lua', 'application/x-lua'] 51 mimetypes = ['text/x-lua', 'application/x-lua']
52 52
53 _comment_multiline = r'(?:--\[(?P<level>=*)\[[\w\W]*?\](?P=level)\])'
54 _comment_single = r'(?:--.*$)'
55 _space = r'(?:\s+)'
56 _s = r'(?:%s|%s|%s)' % (_comment_multiline, _comment_single, _space)
57 _name = r'(?:[^\W\d]\w*)'
58
53 tokens = { 59 tokens = {
54 'root': [ 60 'root': [
55 # lua allows a file to start with a shebang 61 # Lua allows a file to start with a shebang.
56 (r'#!(.*?)$', Comment.Preproc), 62 (r'#!.*', Comment.Preproc),
57 default('base'), 63 default('base'),
58 ], 64 ],
65 'ws': [
66 (_comment_multiline, Comment.Multiline),
67 (_comment_single, Comment.Single),
68 (_space, Text),
69 ],
59 'base': [ 70 'base': [
60 (r'(?s)--\[(=*)\[.*?\]\1\]', Comment.Multiline), 71 include('ws'),
61 ('--.*$', Comment.Single), 72
62 73 (r'(?i)0x[\da-f]*(\.[\da-f]*)?(p[+-]?\d+)?', Number.Hex),
63 (r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number.Float), 74 (r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number.Float),
64 (r'(?i)\d+e[+-]?\d+', Number.Float), 75 (r'(?i)\d+e[+-]?\d+', Number.Float),
65 ('(?i)0x[0-9a-f]*', Number.Hex),
66 (r'\d+', Number.Integer), 76 (r'\d+', Number.Integer),
67 77
68 (r'\n', Text),
69 (r'[^\S\n]', Text),
70 # multiline strings 78 # multiline strings
71 (r'(?s)\[(=*)\[.*?\]\1\]', String), 79 (r'(?s)\[(=*)\[.*?\]\1\]', String),
72 80
73 (r'(==|~=|<=|>=|\.\.\.|\.\.|[=+\-*/%^<>#])', Operator), 81 (r'::', Punctuation, 'label'),
82 (r'\.{3}', Punctuation),
83 (r'[=<>|~&+\-*/%#^]+|\.\.', Operator),
74 (r'[\[\]{}().,:;]', Punctuation), 84 (r'[\[\]{}().,:;]', Punctuation),
75 (r'(and|or|not)\b', Operator.Word), 85 (r'(and|or|not)\b', Operator.Word),
76 86
77 ('(break|do|else|elseif|end|for|if|in|repeat|return|then|until|' 87 ('(break|do|else|elseif|end|for|if|in|repeat|return|then|until|'
78 r'while)\b', Keyword), 88 r'while)\b', Keyword.Reserved),
89 (r'goto\b', Keyword.Reserved, 'goto'),
79 (r'(local)\b', Keyword.Declaration), 90 (r'(local)\b', Keyword.Declaration),
80 (r'(true|false|nil)\b', Keyword.Constant), 91 (r'(true|false|nil)\b', Keyword.Constant),
81 92
82 (r'(function)\b', Keyword, 'funcname'), 93 (r'(function)\b', Keyword.Reserved, 'funcname'),
83 94
84 (r'[A-Za-z_]\w*(\.[A-Za-z_]\w*)?', Name), 95 (r'[A-Za-z_]\w*(\.[A-Za-z_]\w*)?', Name),
85 96
86 ("'", String.Single, combined('stringescape', 'sqs')), 97 ("'", String.Single, combined('stringescape', 'sqs')),
87 ('"', String.Double, combined('stringescape', 'dqs')) 98 ('"', String.Double, combined('stringescape', 'dqs'))
88 ], 99 ],
89 100
90 'funcname': [ 101 'funcname': [
91 (r'\s+', Text), 102 include('ws'),
92 ('(?:([A-Za-z_]\w*)(\.))?([A-Za-z_]\w*)', 103 (r'[.:]', Punctuation),
93 bygroups(Name.Class, Punctuation, Name.Function), '#pop'), 104 (r'%s(?=%s*[.:])' % (_name, _s), Name.Class),
105 (_name, Name.Function, '#pop'),
94 # inline function 106 # inline function
95 ('\(', Punctuation, '#pop'), 107 ('\(', Punctuation, '#pop'),
96 ], 108 ],
97 109
98 # if I understand correctly, every character is valid in a lua string, 110 'goto': [
99 # so this state is only for later corrections 111 include('ws'),
100 'string': [ 112 (_name, Name.Label, '#pop'),
101 ('.', String) 113 ],
114
115 'label': [
116 include('ws'),
117 (r'::', Punctuation, '#pop'),
118 (_name, Name.Label),
102 ], 119 ],
103 120
104 'stringescape': [ 121 'stringescape': [
105 (r'''\\([abfnrtv\\"']|\d{1,3})''', String.Escape) 122 (r'\\([abfnrtv\\"\']|[\r\n]{1,2}|z\s*|x[0-9a-fA-F]{2}|\d{1,3}|'
123 r'u\{[0-9a-fA-F]+\})', String.Escape),
106 ], 124 ],
107 125
108 'sqs': [ 126 'sqs': [
109 ("'", String, '#pop'), 127 (r"'", String.Single, '#pop'),
110 include('string') 128 (r"[^\\']+", String.Single),
111 ], 129 ],
112 130
113 'dqs': [ 131 'dqs': [
114 ('"', String, '#pop'), 132 (r'"', String.Double, '#pop'),
115 include('string') 133 (r'[^\\"]+', String.Double),
116 ] 134 ]
117 } 135 }
118 136
119 def __init__(self, **options): 137 def __init__(self, **options):
120 self.func_name_highlighting = get_bool_opt( 138 self.func_name_highlighting = get_bool_opt(
1018 (r'[0-9]+\.[0-9]*', Number.Float), 1036 (r'[0-9]+\.[0-9]*', Number.Float),
1019 (r'[0-9]+', Number.Integer), 1037 (r'[0-9]+', Number.Integer),
1020 (r"'(''|[^'])*'", String), 1038 (r"'(''|[^'])*'", String),
1021 (r'\s+', Whitespace), 1039 (r'\s+', Whitespace),
1022 # Everything else just belongs to a name 1040 # Everything else just belongs to a name
1023 (_NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name) 1041 (_NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name),
1024 ], 1042 ],
1025 'after_declaration': [ 1043 'after_declaration': [
1026 (_NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name.Function), 1044 (_NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name.Function),
1027 ('', Whitespace, '#pop') 1045 default('#pop'),
1028 ], 1046 ],
1029 'after_macro_argument': [ 1047 'after_macro_argument': [
1030 (r'\*.*\n', Comment.Single, '#pop'), 1048 (r'\*.*\n', Comment.Single, '#pop'),
1031 (r'\s+', Whitespace, '#pop'), 1049 (r'\s+', Whitespace, '#pop'),
1032 (_OPERATORS_PATTERN, Operator, '#pop'), 1050 (_OPERATORS_PATTERN, Operator, '#pop'),
1033 (r"'(''|[^'])*'", String, '#pop'), 1051 (r"'(''|[^'])*'", String, '#pop'),
1034 # Everything else just belongs to a name 1052 # Everything else just belongs to a name
1035 (_NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name) 1053 (_NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name),
1036 ], 1054 ],
1037 } 1055 }
1038 _COMMENT_LINE_REGEX = re.compile(r'^\s*\*') 1056 _COMMENT_LINE_REGEX = re.compile(r'^\s*\*')
1039 _MACRO_HEADER_REGEX = re.compile(r'^\s*MACRO') 1057 _MACRO_HEADER_REGEX = re.compile(r'^\s*MACRO')
1040 1058
1120 return result 1138 return result
1121 1139
1122 1140
1123 class JclLexer(RegexLexer): 1141 class JclLexer(RegexLexer):
1124 """ 1142 """
1125 `Job Control Language (JCL) <http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IEA2B570/CCONTENTS>`_ 1143 `Job Control Language (JCL)
1144 <http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IEA2B570/CCONTENTS>`_
1126 is a scripting language used on mainframe platforms to instruct the system 1145 is a scripting language used on mainframe platforms to instruct the system
1127 on how to run a batch job or start a subsystem. It is somewhat 1146 on how to run a batch job or start a subsystem. It is somewhat
1128 comparable to MS DOS batch and Unix shell scripts. 1147 comparable to MS DOS batch and Unix shell scripts.
1129 1148
1130 .. versionadded:: 2.1 1149 .. versionadded:: 2.1
1143 # TODO: JES3 statement 1162 # TODO: JES3 statement
1144 (r'.*\n', Other) # Input text or inline code in any language. 1163 (r'.*\n', Other) # Input text or inline code in any language.
1145 ], 1164 ],
1146 'statement': [ 1165 'statement': [
1147 (r'\s*\n', Whitespace, '#pop'), 1166 (r'\s*\n', Whitespace, '#pop'),
1148 (r'([a-z][a-z_0-9]*)(\s+)(exec|job)(\s*)', 1167 (r'([a-z]\w*)(\s+)(exec|job)(\s*)',
1149 bygroups(Name.Label, Whitespace, Keyword.Reserved, Whitespace), 1168 bygroups(Name.Label, Whitespace, Keyword.Reserved, Whitespace),
1150 'option'), 1169 'option'),
1151 (r'[a-z][a-z_0-9]*', Name.Variable, 'statement_command'), 1170 (r'[a-z]\w*', Name.Variable, 'statement_command'),
1152 (r'\s+', Whitespace, 'statement_command'), 1171 (r'\s+', Whitespace, 'statement_command'),
1153 ], 1172 ],
1154 'statement_command': [ 1173 'statement_command': [
1155 (r'\s+(command|cntl|dd|endctl|endif|else|include|jcllib|' 1174 (r'\s+(command|cntl|dd|endctl|endif|else|include|jcllib|'
1156 r'output|pend|proc|set|then|xmit)\s+', Keyword.Reserved, 'option'), 1175 r'output|pend|proc|set|then|xmit)\s+', Keyword.Reserved, 'option'),
1165 'option': [ 1184 'option': [
1166 # (r'\n', Text, 'root'), 1185 # (r'\n', Text, 'root'),
1167 (r'\*', Name.Builtin), 1186 (r'\*', Name.Builtin),
1168 (r'[\[\](){}<>;,]', Punctuation), 1187 (r'[\[\](){}<>;,]', Punctuation),
1169 (r'[-+*/=&%]', Operator), 1188 (r'[-+*/=&%]', Operator),
1170 (r'[a-z_][a-z_0-9]*', Name), 1189 (r'[a-z_]\w*', Name),
1171 (r'[0-9]+\.[0-9]*', Number.Float), 1190 (r'\d+\.\d*', Number.Float),
1172 (r'\.[0-9]+', Number.Float), 1191 (r'\.\d+', Number.Float),
1173 (r'[0-9]+', Number.Integer), 1192 (r'\d+', Number.Integer),
1174 (r"'", String, 'option_string'), 1193 (r"'", String, 'option_string'),
1175 (r'[ \t]+', Whitespace, 'option_comment'), 1194 (r'[ \t]+', Whitespace, 'option_comment'),
1176 (r'\.', Punctuation), 1195 (r'\.', Punctuation),
1177 ], 1196 ],
1178 'option_string': [ 1197 'option_string': [

eric ide

mercurial