-
Notifications
You must be signed in to change notification settings - Fork 2
/
grammar.lark
79 lines (61 loc) · 1.82 KB
/
grammar.lark
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Following https://www.w3.org/TR/turtle/#sec-grammar-grammar
start: statement*
statement: directive
| triples "."
directive: prefixid
prefixid: "@prefix" prefixname_ns iri "."
prefixname_ns: PREFIXNAME_PREFIX? ":"
triples: subject predicateobjectlist
subject: iri
iri: "<" uriref ">"
| prefixedname
uriref: URIREF
predicateobjectlist: verb objectlist (";" (verb objectlist)?)*
objectlist: object ("," object)*
object: iri
| literal
| blanknodepropertylist
literal: rdfliteral
rdfliteral: string
| string langtag
| rdfliteralformat
rdfliteralformat: string FORMATCONNECTOR iri
string: ESCAPED_STRING
| "true" -> true
| "false" -> false
verb: predicate
| VERB
predicate: iri
prefixedname: PNAME_LN
| PNAME_NS
blanknodepropertylist: "[" predicateobjectlist "]"
langtag: LANGTAG
// Tokens
PREFIXNAME_PREFIX: PREFIXNAME_CHARS_BASE ((PREFIXNAME_CHARS | ".")* PREFIXNAME_CHARS)?
PREFIXNAME_CHARS_BASE: LETTER
PREFIXNAME_CHARS: PREFIXNAME_CHARS_U
| "-"
| DIGIT
PREFIXNAME_CHARS_U: PREFIXNAME_CHARS_BASE
| "_"
PNAME_LN: PNAME_NS PN_LOCAL
PNAME_NS: PREFIXNAME_PREFIX? ":"
PN_LOCAL: (PREFIXNAME_CHARS_U | ":" | DIGIT | PLX) ((PREFIXNAME_CHARS | "." | ":" | PLX)* (PREFIXNAME_CHARS | ":" | PLX))?
PLX: PERCENT
PERCENT: "%" HEXDIGIT HEXDIGIT
LANGTAG: "@" [LCASE_LETTER
| UCASE_LETTER]+ ("-" [LCASE_LETTER | UCASE_LETTER | DIGIT]+)*
URIREF: /[^<>{}]+/
COMMENT: /#[^\n]*/
VERB: "a"
FORMATCONNECTOR: "^^"
%import common.WS -> WS
%import common.LCASE_LETTER -> LCASE_LETTER
%import common.UCASE_LETTER -> UCASE_LETTER
%import common.DIGIT -> DIGIT
%import common.HEXDIGIT -> HEXDIGIT
%import common.ESCAPED_STRING -> ESCAPED_STRING
%import common.LETTER -> LETTER
// Disregard spaces in text and comments
%ignore WS
%ignore COMMENT