Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add grammar definition #661

Merged
merged 7 commits into from Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmignore
Expand Up @@ -9,3 +9,4 @@ coverage/
.github/
img/
tsconfig.json
grammar.w3c-ebnf
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -278,6 +278,10 @@ You can add `not ` to any query.
[Can I Use]: https://caniuse.com/
[Firefox Extended Support Release]: https://support.mozilla.org/en-US/kb/choosing-firefox-update-channel

### Grammar Definition

There is a [grammar specification](./grammar.w3c-ebnf) about the query syntax,
which may be helpful if you're implementing a parser or something else.

### Debug

Expand Down
126 changes: 126 additions & 0 deletions grammar.w3c-ebnf
@@ -0,0 +1,126 @@
NonSpaceChar ::= [#x21-#xD7FF] | [#xE000-#xFFFD]

Digit ::= [0-9]

Space ::= ' ' | '\t'

Numeric ::= (Digit* '.')? Digit+

BrowserName ::= 'ie'
| 'edge'
| 'firefox'
| 'chrome'
| 'safari'
| 'opera'
| 'ios_saf'
| 'op_mini'
| 'android'
| 'bb'
| 'op_mob'
| 'and_chr'
| 'and_ff'
| 'ie_mob'
| 'and_uc'
| 'samsung'
| 'and_qq'
| 'baidu'
| 'kaios'
| 'fx'
| 'ff'
| 'ios'
| 'explorer'
| 'blackberry'
| 'explorermobile'
| 'operamini'
| 'operamobile'
| 'chromeandroid'
| 'firefoxandroid'
| 'ucandroid'
| 'qqandroid'

CompareOperator ::= ('>' | '<') '='?

VersionKeyword ::= 'version' 's'?

LastBrowsers ::= 'last' Space+ Digit+ Space+ (BrowserName Space+)? ('major' Space+)? VersionKeyword

LastElectron ::= 'last' Space+ Digit+ Space+ 'electron' Space+ ('major' Space+)? VersionKeyword

Unreleased ::= 'unreleased' Space+ ((BrowserName | 'electron') Space+)? VersionKeyword

Years ::= 'last' Space+ Numeric Space+ 'year' 's'?

Since ::= 'since' Space Digit+ ('-' Digit+ ('-' Digit+)?)?

Region ::= ('alt-' [a-z][a-z] | [A-Z][A-Z])

MyStats ::= 'my' Space+ 'stats'

CustomStats ::= NonSpaceChar+ Space+ 'stats'

Percentage ::= CompareOperator Space* Numeric '%' (Space+ 'in' Space+ (MyStats | CustomStats | Region))?

Cover ::= 'cover' Space+ Numeric '%' (Space+ 'in' Space+ (MyStats | Region))?

FeatureSupport ::= 'supports' Space+ ([a-z0-9] | '-')+

Version ::= (Digit | '.')+

BoundedRange ::= Version Space* '-' Space* Version

UnboundedRange ::= CompareOperator Space* Version

Electron ::= 'electron' Space+ (BoundedRange | UnboundedRange | Version)

Node ::= 'node' Space+ (BoundedRange | UnboundedRange | Version)

Browser ::= BrowserName Space+ (BoundedRange | UnboundedRange | Version | 'tp')

FirefoxESR ::= ('firefox' | 'fx' | 'ff') Space+ 'esr'

OperaMini ::= ('operamini' | 'op_mini') Space+ 'all'

CurrentNode ::= 'current' Space+ 'node'

MaintainedNode ::= 'maintained' Space+ 'node' Space+ 'versions'

Phantom ::= 'phantomjs' Space+ ('1.9' | '2.1')

BrowserslistConfig ::= 'browserslist config'

Extending ::= 'extends' Space NonSpaceChar+

Defaults ::= 'defaults'

Dead ::= 'dead'

QueryAtom ::= LastBrowsers
| LastElectron
| Unreleased
| Years
| Since
| Percentage
| Cover
| FeatureSupport
| Electron
| Node
| Browser
| FirefoxESR
| OperaMini
| CurrentNode
| MaintainedNode
| Phantom
| BrowserslistConfig
| Extending
| Defaults
| Dead

SingleQuery ::= ('not' Space)? QueryAtom

OrOperator ::= Space+ 'or' Space+ | Space* ',' Space*

AndOperator ::= Space+ 'and' Space+

BrowserslistQuery ::= QueryAtom ((OrOperator | AndOperator) SingleQuery)*

Root ::= BrowserslistQuery