-
Notifications
You must be signed in to change notification settings - Fork 2
/
tree-sitter-prolog.ebnf
127 lines (96 loc) · 3.2 KB
/
tree-sitter-prolog.ebnf
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//
// From tree-sitter-prolog/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
source_file ::=
_topLevel*
_topLevel ::=
predicate_definition
| dcg_definition
| directive
| query
directive ::=
':-' values '.'
query ::=
'?-' values '.'
predicate_definition ::=
( atom ':' )? ( atom | term ) ( ':-' values )? '.'
dcg_definition ::=
( atom ':' )? ( atom | term ) ( ',' _value )? ( '-->' | '-->>' ) values '.'
values ::=
( _value ',' )* _value
term ::=
atom '(' values ')'
_simple_value ::=
atom | term | string | list | number | var | char_code | dict | codes | quasiquote | '.'
quasiquote ::=
'{|' ( atom | term ) '||' ([^|]|('\'|[^}]))* '|}'
dict_op_term ::=
( '.' ( [a-z][a-zA-Z0-9_]* | "'"([^'\]|("\."))*"'" | ( '!' | '=' | '-' | '/' | '+' | '*' | '#' | '>' | '<' | ':' | ';' | '?' | '\\' | '^' | '@' | '$' )+ | '..' ) '(' ) values ')'
dict_operator ::=
( var | dict | dict_operator ) ( dict_op_term | ( '.' ( [a-z][a-zA-Z0-9_]* | "'"([^'\]|("\."))*"'" | ( '!' | '=' | '-' | '/' | '+' | '*' | '#' | '>' | '<' | ':' | ';' | '?' | '\\' | '^' | '@' | '$' )+ | '..' ) ) | ( '.' [_A-Z][a-zA-Z0-9_]* ) )
_value ::=
dict_operator
| _simple_value
| curly_braced
| parenthesized
| binary_op
| unary_op
curly_braced ::=
'{' values? '}'
parenthesized ::=
'(' values ')'
atom ::=
[a-z][a-zA-Z0-9_]*
| "'"([^'\]|("\."))*"'"
| _sym_atom
| '..'
_sym_atom ::=
( '!' | '=' | '-' | '/' | '+' | '*' | '#' | '>' | '<' | ':' | ';' | '?' | '\\' | '^' | '@' | '$' )+
var ::=
[_A-Z][a-zA-Z0-9_]*
unary_op ::=
( '\\' ) _value | ( '\+' ) _value | ( 'dynamic' | 'discontiguous' | 'initialization' | 'meta_predicate' | 'module_transparent' | 'multifile' | 'public' | 'thread_local' | 'thread_initialization' | 'volatile' ) _value | atom _value
binary_op ::=
_value ( '^' | '**' ) _value
| _value ( '*' | '/' | '//' | 'div' | 'rdiv' | '<<' | '>>' | 'mod' | 'rem' ) _value
| _value ( '+' | '-' | '/\' | '\/' | 'xor' ) _value
| _value ( ':' ) _value
| _value ( '<' | '=' | '=..' | '=@=' | '\=@=' | '=:=' | '=<' | '==' | '=\=' | '>' | '>=' | '@<' | '@=<' | '@>' | '@>=' | '\=' | '\==' | 'as' | 'is' | '>:<' | ':<' | '..' ) _value
| _value ( ':=' ) _value
| _value ( '->' | '*->' ) _value
| _value ( ';' | '|' ) _value
| _value atom _value
string ::=
'"'(([^"\])|('\'([^xu0-7]|[0-7]'{1,3}'|'x'[0-9a-fA-F]'{2}'|'u'[0-9a-fA-F]'{4}')))*'"'
codes ::=
'`'(([^`\])|('\'([^xu0-7]|[0-7]'{1,3}'|'x'[0-9a-fA-F]'{2}'|'u'[0-9a-fA-F]'{4}')))*'`'
comment ::=
'%' '.'* | '/*' ([^*]|('\'*+[^/*]))*'\'*+ '/'
escape_sequence ::=
( '\\' ( [^xu0-7] | [0-7]'{1,3}' | 'x'[0-9a-fA-F]'{2}' | 'u'[0-9a-fA-F]'{4}' ) )
char_code ::=
"0'" ( '.' | escape_sequence )
number ::=
[-+]?[_0-9]+
| [-+]?[_0-9]+'.'[_0-9]+
| [-+]?'0b'[01_]+
| [-+]?'0x'[0-9a-fA-F_]+
| [-+]?'0c'[0-7_]+
| [-+]?([1-9]|[1-2][0-9]|'3'[0-6])"'"[_0-9a-zA-Z]+
| [-+]?[0-9_]+[/][1-9_]+
| [-+]?[0-9_]+'r'[1-9_]+
| [-+]?([0-9_]('.'[0-9_]+)?)+'e'[0-9_]+
| [-+]?[0-9]+[.][0-9]+'Inf'
list ::=
'[' values? ( '|' _value )? ']'
dict ::=
( atom | var ) '{' dict_entries? '}'
dict_entries ::=
( dict_entry ',' )* dict_entry
dict_entry ::=
atom ':' _value