ThirdParty/Pygments/pygments/lexers/rdf.py

changeset 4172
4f20dba37ab6
child 4697
c2e9bf425554
equal deleted inserted replaced
4170:8bc578136279 4172:4f20dba37ab6
1 # -*- coding: utf-8 -*-
2 """
3 pygments.lexers.rdf
4 ~~~~~~~~~~~~~~~~~~~
5
6 Lexers for semantic web and RDF query languages and markup.
7
8 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details.
10 """
11
12 import re
13
14 from pygments.lexer import RegexLexer, bygroups, default
15 from pygments.token import Keyword, Punctuation, String, Number, Operator, \
16 Whitespace, Name, Literal, Comment, Text
17
18 __all__ = ['SparqlLexer']
19
20
21 class SparqlLexer(RegexLexer):
22 """
23 Lexer for `SPARQL <http://www.w3.org/TR/rdf-sparql-query/>`_ query language.
24
25 .. versionadded:: 2.0
26 """
27 name = 'SPARQL'
28 aliases = ['sparql']
29 filenames = ['*.rq', '*.sparql']
30 mimetypes = ['application/sparql-query']
31
32 flags = re.IGNORECASE
33
34 tokens = {
35 'root': [
36 (r'\s+', Whitespace),
37 (r'(select|construct|describe|ask|where|filter|group\s+by|minus|'
38 r'distinct|reduced|from named|from|order\s+by|limit|'
39 r'offset|bindings|load|clear|drop|create|add|move|copy|'
40 r'insert\s+data|delete\s+data|delete\s+where|delete|insert|'
41 r'using named|using|graph|default|named|all|optional|service|'
42 r'silent|bind|union|not in|in|as|a)', Keyword),
43 (r'(prefix|base)(\s+)([a-z][\w-]*)(\s*)(\:)',
44 bygroups(Keyword, Whitespace, Name.Namespace, Whitespace,
45 Punctuation)),
46 (r'\?[a-z_]\w*', Name.Variable),
47 (r'<[^>]+>', Name.Label),
48 (r'([a-z][\w-]*)(\:)([a-z][\w-]*)',
49 bygroups(Name.Namespace, Punctuation, Name.Tag)),
50 (r'(str|lang|langmatches|datatype|bound|iri|uri|bnode|rand|abs|'
51 r'ceil|floor|round|concat|strlen|ucase|lcase|encode_for_uri|'
52 r'contains|strstarts|strends|strbefore|strafter|year|month|day|'
53 r'hours|minutes|seconds|timezone|tz|now|md5|sha1|sha256|sha384|'
54 r'sha512|coalesce|if|strlang|strdt|sameterm|isiri|isuri|isblank|'
55 r'isliteral|isnumeric|regex|substr|replace|exists|not exists|'
56 r'count|sum|min|max|avg|sample|group_concat|separator)\b',
57 Name.Function),
58 (r'(true|false)', Literal),
59 (r'[+\-]?\d*\.\d+', Number.Float),
60 (r'[+\-]?\d*(:?\.\d+)?E[+\-]?\d+', Number.Float),
61 (r'[+\-]?\d+', Number.Integer),
62 (r'(\|\||&&|=|\*|\-|\+|/)', Operator),
63 (r'[(){}.;,:^]', Punctuation),
64 (r'#[^\n]+', Comment),
65 (r'"""', String, 'triple-double-quoted-string'),
66 (r'"', String, 'single-double-quoted-string'),
67 (r"'''", String, 'triple-single-quoted-string'),
68 (r"'", String, 'single-single-quoted-string'),
69 ],
70 'triple-double-quoted-string': [
71 (r'"""', String, 'end-of-string'),
72 (r'[^\\]+', String),
73 (r'\\', String, 'string-escape'),
74 ],
75 'single-double-quoted-string': [
76 (r'"', String, 'end-of-string'),
77 (r'[^"\\\n]+', String),
78 (r'\\', String, 'string-escape'),
79 ],
80 'triple-single-quoted-string': [
81 (r"'''", String, 'end-of-string'),
82 (r'[^\\]+', String),
83 (r'\\', String, 'string-escape'),
84 ],
85 'single-single-quoted-string': [
86 (r"'", String, 'end-of-string'),
87 (r"[^'\\\n]+", String),
88 (r'\\', String, 'string-escape'),
89 ],
90 'string-escape': [
91 (r'.', String, '#pop'),
92 ],
93 'end-of-string': [
94 (r'(@)([a-z]+(:?-[a-z0-9]+)*)',
95 bygroups(Operator, Name.Function), '#pop:2'),
96 (r'\^\^', Operator, '#pop:2'),
97 default('#pop:2'),
98 ],
99 }

eric ide

mercurial