Skip to content

Commit 1d46a66

Browse files
authored
Add grammar definition (#661)
* Add grammar definition * Add missing `BrowserName` definition * Tweak * Fix definition * Rename * Add entrypoint * Exclude line break from "Space"
1 parent 3cba97f commit 1d46a66

3 files changed

Lines changed: 131 additions & 0 deletions

File tree

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ coverage/
99
.github/
1010
img/
1111
tsconfig.json
12+
grammar.w3c-ebnf

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ You can add `not ` to any query.
278278
[Can I Use]: https://caniuse.com/
279279
[Firefox Extended Support Release]: https://support.mozilla.org/en-US/kb/choosing-firefox-update-channel
280280

281+
### Grammar Definition
282+
283+
There is a [grammar specification](./grammar.w3c-ebnf) about the query syntax,
284+
which may be helpful if you're implementing a parser or something else.
281285

282286
### Debug
283287

grammar.w3c-ebnf

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
NonSpaceChar ::= [#x21-#xD7FF] | [#xE000-#xFFFD]
2+
3+
Digit ::= [0-9]
4+
5+
Space ::= ' ' | '\t'
6+
7+
Numeric ::= (Digit* '.')? Digit+
8+
9+
BrowserName ::= 'ie'
10+
| 'edge'
11+
| 'firefox'
12+
| 'chrome'
13+
| 'safari'
14+
| 'opera'
15+
| 'ios_saf'
16+
| 'op_mini'
17+
| 'android'
18+
| 'bb'
19+
| 'op_mob'
20+
| 'and_chr'
21+
| 'and_ff'
22+
| 'ie_mob'
23+
| 'and_uc'
24+
| 'samsung'
25+
| 'and_qq'
26+
| 'baidu'
27+
| 'kaios'
28+
| 'fx'
29+
| 'ff'
30+
| 'ios'
31+
| 'explorer'
32+
| 'blackberry'
33+
| 'explorermobile'
34+
| 'operamini'
35+
| 'operamobile'
36+
| 'chromeandroid'
37+
| 'firefoxandroid'
38+
| 'ucandroid'
39+
| 'qqandroid'
40+
41+
CompareOperator ::= ('>' | '<') '='?
42+
43+
VersionKeyword ::= 'version' 's'?
44+
45+
LastBrowsers ::= 'last' Space+ Digit+ Space+ (BrowserName Space+)? ('major' Space+)? VersionKeyword
46+
47+
LastElectron ::= 'last' Space+ Digit+ Space+ 'electron' Space+ ('major' Space+)? VersionKeyword
48+
49+
Unreleased ::= 'unreleased' Space+ ((BrowserName | 'electron') Space+)? VersionKeyword
50+
51+
Years ::= 'last' Space+ Numeric Space+ 'year' 's'?
52+
53+
Since ::= 'since' Space Digit+ ('-' Digit+ ('-' Digit+)?)?
54+
55+
Region ::= ('alt-' [a-z][a-z] | [A-Z][A-Z])
56+
57+
MyStats ::= 'my' Space+ 'stats'
58+
59+
CustomStats ::= NonSpaceChar+ Space+ 'stats'
60+
61+
Percentage ::= CompareOperator Space* Numeric '%' (Space+ 'in' Space+ (MyStats | CustomStats | Region))?
62+
63+
Cover ::= 'cover' Space+ Numeric '%' (Space+ 'in' Space+ (MyStats | Region))?
64+
65+
FeatureSupport ::= 'supports' Space+ ([a-z0-9] | '-')+
66+
67+
Version ::= (Digit | '.')+
68+
69+
BoundedRange ::= Version Space* '-' Space* Version
70+
71+
UnboundedRange ::= CompareOperator Space* Version
72+
73+
Electron ::= 'electron' Space+ (BoundedRange | UnboundedRange | Version)
74+
75+
Node ::= 'node' Space+ (BoundedRange | UnboundedRange | Version)
76+
77+
Browser ::= BrowserName Space+ (BoundedRange | UnboundedRange | Version | 'tp')
78+
79+
FirefoxESR ::= ('firefox' | 'fx' | 'ff') Space+ 'esr'
80+
81+
OperaMini ::= ('operamini' | 'op_mini') Space+ 'all'
82+
83+
CurrentNode ::= 'current' Space+ 'node'
84+
85+
MaintainedNode ::= 'maintained' Space+ 'node' Space+ 'versions'
86+
87+
Phantom ::= 'phantomjs' Space+ ('1.9' | '2.1')
88+
89+
BrowserslistConfig ::= 'browserslist config'
90+
91+
Extending ::= 'extends' Space NonSpaceChar+
92+
93+
Defaults ::= 'defaults'
94+
95+
Dead ::= 'dead'
96+
97+
QueryAtom ::= LastBrowsers
98+
| LastElectron
99+
| Unreleased
100+
| Years
101+
| Since
102+
| Percentage
103+
| Cover
104+
| FeatureSupport
105+
| Electron
106+
| Node
107+
| Browser
108+
| FirefoxESR
109+
| OperaMini
110+
| CurrentNode
111+
| MaintainedNode
112+
| Phantom
113+
| BrowserslistConfig
114+
| Extending
115+
| Defaults
116+
| Dead
117+
118+
SingleQuery ::= ('not' Space)? QueryAtom
119+
120+
OrOperator ::= Space+ 'or' Space+ | Space* ',' Space*
121+
122+
AndOperator ::= Space+ 'and' Space+
123+
124+
BrowserslistQuery ::= QueryAtom ((OrOperator | AndOperator) SingleQuery)*
125+
126+
Root ::= BrowserslistQuery

0 commit comments

Comments
 (0)