-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
source.ebnf.js
153 lines (151 loc) · 5.52 KB
/
source.ebnf.js
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// This is a TextMate grammar distributed by `starry-night`.
// This grammar is developed at
// <https://github.com/Alhadis/language-grammars>
// and licensed `isc`.
// See <https://github.com/wooorm/starry-night> for more info.
/**
* @import {Grammar} from '@wooorm/starry-night'
*/
/** @type {Grammar} */
const grammar = {
dependencies: ['source.lex.regexp'],
extensions: ['.ebnf'],
names: ['ebnf'],
patterns: [{include: '#main'}],
repository: {
brackets: {
patterns: [
{
match: '\\[',
name: 'punctuation.definition.square.bracket.begin.ebnf'
},
{match: '\\]', name: 'punctuation.definition.square.bracket.end.ebnf'},
{match: '{', name: 'punctuation.definition.curly.bracket.begin.ebnf'},
{match: '}', name: 'punctuation.definition.curly.bracket.end.ebnf'},
{match: '\\(', name: 'punctuation.definition.round.bracket.begin.ebnf'},
{match: '\\)', name: 'punctuation.definition.round.bracket.end.ebnf'}
]
},
comment: {
patterns: [
{
begin: '\\(\\*',
beginCaptures: {
0: {name: 'punctuation.definition.comment.begin.ebnf'}
},
end: '\\*\\)',
endCaptures: {0: {name: 'punctuation.definition.comment.end.ebnf'}},
name: 'comment.block.iso14977.ebnf'
},
{
begin: '^[ \\t]*((/\\*))',
beginCaptures: {
1: {name: 'comment.block.w3c.ebnf'},
2: {name: 'punctuation.definition.comment.begin.ebnf'}
},
end: '\\*/',
endCaptures: {0: {name: 'punctuation.definition.comment.end.ebnf'}},
name: 'comment.block.w3c.ebnf'
}
]
},
lhs: {
patterns: [
{
captures: {1: {name: 'entity.name.rule.identifier.ebnf'}},
match:
'(?x)\n(?: \\s++\n| ^|\\G\n| (?= ^|\\G )\n| (?<= ;|\\*\\) )\n)\n\n# Exclude leading whitespace\n\\s*\n\n([A-Za-z][A-Za-z0-9_-]*+)',
name: 'meta.lhs.ebnf'
},
{
begin:
"(?x)\n(?: \\s++\n| ^|\\G\n| (?= ^|\\G )\n| (?<= \\*\\) )\n)\n\n# Exclude leading whitespace\n\\s*\n\n# Check for at least one “invalid” character\n(?=\n\t# Starts with a digit\n\t[0-9]\n\t|\n\t\n\t# Contains at least one non-“word” character\n\t[A-Za-z0-9_-]* # Skip any legal characters\n\t(?: [^:;=()] # Don't swallow symbols for comments, terminators, or assignments\n\t| \\((?!\\*) # Permit open brackets if they don't introduce a comment\n\t)\n)",
contentName: 'entity.name.rule.identifier.non-standard.ebnf',
end: '(?x)\n# Exclude trailing whitespace\n\\s*\n\n# Stop before an...\n(?= :*= # Assignment operator separating `#lhs` from `#rhs`\n| ; # Unexpected terminator\n| \\(\\* # Embedded comment\n)',
name: 'meta.lhs.non-standard.ebnf',
patterns: [{include: '#comment'}]
},
{include: '#comment'}
]
},
main: {
patterns: [
{include: '#comment'},
{include: '#semicolon'},
{include: '#lhs'},
{include: '#rhs'},
{include: '#special'}
]
},
rhs: {
begin: '(::=)|(:=)|(=)',
beginCaptures: {
1: {name: 'keyword.operator.assignment.non-standard.double-colon.ebnf'},
2: {name: 'keyword.operator.assignment.non-standard.single-colon.ebnf'},
3: {name: 'keyword.operator.assignment.ebnf'}
},
end: '(?=;|^\\s*(?:<?[A-Za-z][A-Za-z0-9_-]*>?\\s*)?:*=)',
name: 'meta.rhs.ebnf',
patterns: [{include: '#rhs-innards'}]
},
'rhs-innards': {
patterns: [
{match: ',', name: 'punctuation.delimiter.comma.ebnf'},
{
match: '\\|',
name: 'keyword.operator.logical.or.alternation.pipe.ebnf'
},
{
match: '-',
name: 'keyword.operator.logical.minus.hyphen.exception.ebnf'
},
{
match: '\\*',
name: 'keyword.operator.logical.repetition.asterisk.star.ebnf'
},
{include: '#special'},
{
begin: '"',
beginCaptures: {
0: {name: 'punctuation.definition.string.begin.ebnf'}
},
end: '"(?!")|(?=^\\s*+\\S+?\\s+::{0,2}=\\s|\\s+\\|)',
endCaptures: {0: {name: 'punctuation.definition.string.end.ebnf'}},
name: 'string.quoted.double.ebnf'
},
{
begin: "'",
beginCaptures: {
0: {name: 'punctuation.definition.string.begin.ebnf'}
},
end: "'(?!')|(?=^\\s*+\\S+?\\s+::{0,2}=\\s|\\s+\\|)",
endCaptures: {0: {name: 'punctuation.definition.string.end.ebnf'}},
name: 'string.quoted.single.ebnf'
},
{include: '#brackets'},
{include: '#comment'},
{
match: '\\b(?<!-)[A-Za-z][A-Za-z0-9_-]*',
name: 'variable.parameter.argument.identifier.reference.ebnf'
},
{
match: '!',
name: 'keyword.operator.logical.not.negation.non-standard.ebnf'
},
{include: 'source.lex.regexp#quantifier'}
]
},
semicolon: {match: ';', name: 'punctuation.terminator.statement.ebnf'},
special: {
captures: {
1: {name: 'keyword.operator.pragma.begin.ebnf'},
2: {name: 'support.constant.language.pragma.ebnf'},
3: {name: 'keyword.operator.pragma.end.ebnf'}
},
match: '(?<=\\s|^)(\\?)(.+?)(?<=\\s)(\\?)(?=[,;]?(?:$|\\s))',
name: 'meta.pragma.directive.special.iso14977.ebnf'
}
},
scopeName: 'source.ebnf'
}
export default grammar