97 'root': [ |
97 'root': [ |
98 (r'\s+', Text), |
98 (r'\s+', Text), |
99 # keywords :: |
99 # keywords :: |
100 (r'(?i)(select|construct|describe|ask|where|filter|group\s+by|minus|' |
100 (r'(?i)(select|construct|describe|ask|where|filter|group\s+by|minus|' |
101 r'distinct|reduced|from\s+named|from|order\s+by|desc|asc|limit|' |
101 r'distinct|reduced|from\s+named|from|order\s+by|desc|asc|limit|' |
102 r'offset|bindings|load|clear|drop|create|add|move|copy|' |
102 r'offset|values|bindings|load|into|clear|drop|create|add|move|copy|' |
103 r'insert\s+data|delete\s+data|delete\s+where|delete|insert|' |
103 r'insert\s+data|delete\s+data|delete\s+where|with|delete|insert|' |
104 r'using\s+named|using|graph|default|named|all|optional|service|' |
104 r'using\s+named|using|graph|default|named|all|optional|service|' |
105 r'silent|bind|union|not\s+in|in|as|having|to|prefix|base)\b', Keyword), |
105 r'silent|bind|undef|union|not\s+in|in|as|having|to|prefix|base)\b', Keyword), |
106 (r'(a)\b', Keyword), |
106 (r'(a)\b', Keyword), |
107 # IRIs :: |
107 # IRIs :: |
108 ('(' + IRIREF + ')', Name.Label), |
108 ('(' + IRIREF + ')', Name.Label), |
109 # blank nodes :: |
109 # blank nodes :: |
110 ('(' + BLANK_NODE_LABEL + ')', Name.Label), |
110 ('(' + BLANK_NODE_LABEL + ')', Name.Label), |
115 bygroups(Name.Namespace, Punctuation, Name.Tag)), |
115 bygroups(Name.Namespace, Punctuation, Name.Tag)), |
116 # function names :: |
116 # function names :: |
117 (r'(?i)(str|lang|langmatches|datatype|bound|iri|uri|bnode|rand|abs|' |
117 (r'(?i)(str|lang|langmatches|datatype|bound|iri|uri|bnode|rand|abs|' |
118 r'ceil|floor|round|concat|strlen|ucase|lcase|encode_for_uri|' |
118 r'ceil|floor|round|concat|strlen|ucase|lcase|encode_for_uri|' |
119 r'contains|strstarts|strends|strbefore|strafter|year|month|day|' |
119 r'contains|strstarts|strends|strbefore|strafter|year|month|day|' |
120 r'hours|minutes|seconds|timezone|tz|now|md5|sha1|sha256|sha384|' |
120 r'hours|minutes|seconds|timezone|tz|now|uuid|struuid|md5|sha1|sha256|sha384|' |
121 r'sha512|coalesce|if|strlang|strdt|sameterm|isiri|isuri|isblank|' |
121 r'sha512|coalesce|if|strlang|strdt|sameterm|isiri|isuri|isblank|' |
122 r'isliteral|isnumeric|regex|substr|replace|exists|not\s+exists|' |
122 r'isliteral|isnumeric|regex|substr|replace|exists|not\s+exists|' |
123 r'count|sum|min|max|avg|sample|group_concat|separator)\b', |
123 r'count|sum|min|max|avg|sample|group_concat|separator)\b', |
124 Name.Function), |
124 Name.Function), |
125 # boolean literals :: |
125 # boolean literals :: |
185 name = 'Turtle' |
185 name = 'Turtle' |
186 aliases = ['turtle'] |
186 aliases = ['turtle'] |
187 filenames = ['*.ttl'] |
187 filenames = ['*.ttl'] |
188 mimetypes = ['text/turtle', 'application/x-turtle'] |
188 mimetypes = ['text/turtle', 'application/x-turtle'] |
189 |
189 |
190 flags = re.IGNORECASE |
190 # character group definitions :: |
|
191 PN_CHARS_BASE_GRP = ('a-zA-Z' |
|
192 '\u00c0-\u00d6' |
|
193 '\u00d8-\u00f6' |
|
194 '\u00f8-\u02ff' |
|
195 '\u0370-\u037d' |
|
196 '\u037f-\u1fff' |
|
197 '\u200c-\u200d' |
|
198 '\u2070-\u218f' |
|
199 '\u2c00-\u2fef' |
|
200 '\u3001-\ud7ff' |
|
201 '\uf900-\ufdcf' |
|
202 '\ufdf0-\ufffd') |
|
203 |
|
204 PN_CHARS_U_GRP = (PN_CHARS_BASE_GRP + '_') |
|
205 |
|
206 PN_CHARS_GRP = (PN_CHARS_U_GRP + |
|
207 r'\-' + |
|
208 r'0-9' + |
|
209 '\u00b7' + |
|
210 '\u0300-\u036f' + |
|
211 '\u203f-\u2040') |
|
212 |
|
213 PN_CHARS = '[' + PN_CHARS_GRP + ']' |
|
214 |
|
215 PN_CHARS_BASE = '[' + PN_CHARS_BASE_GRP + ']' |
|
216 |
|
217 PN_PREFIX = PN_CHARS_BASE + '(?:[' + PN_CHARS_GRP + '.]*' + PN_CHARS + ')?' |
|
218 |
|
219 HEX_GRP = '0-9A-Fa-f' |
|
220 |
|
221 HEX = '[' + HEX_GRP + ']' |
|
222 |
|
223 PERCENT = '%' + HEX + HEX |
|
224 |
|
225 PN_LOCAL_ESC_CHARS_GRP = r' _~.\-!$&"()*+,;=/?#@%' |
|
226 |
|
227 PN_LOCAL_ESC_CHARS = '[' + PN_LOCAL_ESC_CHARS_GRP + ']' |
|
228 |
|
229 PN_LOCAL_ESC = r'\\' + PN_LOCAL_ESC_CHARS |
|
230 |
|
231 PLX = '(?:' + PERCENT + ')|(?:' + PN_LOCAL_ESC + ')' |
|
232 |
|
233 PN_LOCAL = ('(?:[' + PN_CHARS_U_GRP + ':0-9' + ']|' + PLX + ')' + |
|
234 '(?:(?:[' + PN_CHARS_GRP + '.:]|' + PLX + ')*(?:[' + |
|
235 PN_CHARS_GRP + ':]|' + PLX + '))?') |
191 |
236 |
192 patterns = { |
237 patterns = { |
193 'PNAME_NS': r'((?:[a-z][\w-]*)?\:)', # Simplified character range |
238 'PNAME_NS': r'((?:[a-zA-Z][\w-]*)?\:)', # Simplified character range |
194 'IRIREF': r'(<[^<>"{}|^`\\\x00-\x20]*>)' |
239 'IRIREF': r'(<[^<>"{}|^`\\\x00-\x20]*>)' |
195 } |
240 } |
196 |
241 |
197 # PNAME_NS PN_LOCAL (with simplified character range) |
|
198 patterns['PrefixedName'] = r'%(PNAME_NS)s([a-z][\w-]*)' % patterns |
|
199 |
|
200 tokens = { |
242 tokens = { |
201 'root': [ |
243 'root': [ |
202 (r'\s+', Whitespace), |
244 (r'\s+', Text), |
203 |
245 |
204 # Base / prefix |
246 # Base / prefix |
205 (r'(@base|BASE)(\s+)%(IRIREF)s(\s*)(\.?)' % patterns, |
247 (r'(@base|BASE)(\s+)%(IRIREF)s(\s*)(\.?)' % patterns, |
206 bygroups(Keyword, Whitespace, Name.Variable, Whitespace, |
248 bygroups(Keyword, Whitespace, Name.Variable, Whitespace, |
207 Punctuation)), |
249 Punctuation)), |
214 |
256 |
215 # IRIREF |
257 # IRIREF |
216 (r'%(IRIREF)s' % patterns, Name.Variable), |
258 (r'%(IRIREF)s' % patterns, Name.Variable), |
217 |
259 |
218 # PrefixedName |
260 # PrefixedName |
219 (r'%(PrefixedName)s' % patterns, |
261 (r'(' + PN_PREFIX + r')?(\:)(' + PN_LOCAL + r')?', |
220 bygroups(Name.Namespace, Name.Tag)), |
262 bygroups(Name.Namespace, Punctuation, Name.Tag)), |
221 |
263 |
222 # Comment |
264 # Comment |
223 (r'#[^\n]+', Comment), |
265 (r'#[^\n]+', Comment), |
224 |
266 |
225 (r'\b(true|false)\b', Literal), |
267 (r'\b(true|false)\b', Literal), |
255 ], |
297 ], |
256 'string-escape': [ |
298 'string-escape': [ |
257 (r'.', String, '#pop'), |
299 (r'.', String, '#pop'), |
258 ], |
300 ], |
259 'end-of-string': [ |
301 'end-of-string': [ |
260 (r'(@)([a-z]+(:?-[a-z0-9]+)*)', |
302 (r'(@)([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)', |
261 bygroups(Operator, Generic.Emph), '#pop:2'), |
303 bygroups(Operator, Generic.Emph), '#pop:2'), |
262 |
304 |
263 (r'(\^\^)%(IRIREF)s' % patterns, bygroups(Operator, Generic.Emph), '#pop:2'), |
305 (r'(\^\^)%(IRIREF)s' % patterns, bygroups(Operator, Generic.Emph), '#pop:2'), |
264 (r'(\^\^)%(PrefixedName)s' % patterns, |
|
265 bygroups(Operator, Generic.Emph, Generic.Emph), '#pop:2'), |
|
266 |
306 |
267 default('#pop:2'), |
307 default('#pop:2'), |
268 |
308 |
269 ], |
309 ], |
270 } |
310 } |