Last active
October 28, 2019 15:14
-
-
Save jednano/3accca5fec9c234538b82d6ac7df6681 to your computer and use it in GitHub Desktop.
EditorConfig Grammar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document = _ children:(Newline / Comment / Rule)* _ sections:Section* _ { | |
return { | |
type: 'EditorConfig', | |
version: '15.0.0', | |
children: children.concat(sections), | |
} | |
} | |
_ 'whitespace' = [ \t\n\r]* | |
RuleEnd = _';'?_ | |
Boolean = 'true' / 'false' | |
Newline = value:('\n' / '\r\n') { | |
return { | |
type: 'Newline', | |
value, | |
} | |
} | |
Comment = _ ('#' / ';') value:[^\r\n]* newline:Newline? { | |
return { | |
type: 'Comment', | |
value: value.join('').trim(), | |
newline, | |
} | |
} | |
Rule = | |
_ key:Identifier | |
_ '=' | |
_ value:[^ \t\r\n]+ | |
RuleEnd { | |
var value = value.join('') | |
try { | |
value = JSON.parse(value.toLowerCase()) | |
} catch (err) { | |
// noop | |
} | |
return { | |
type: 'Rule', | |
key, | |
value, | |
} | |
} | |
Identifier = $([a-z_]i+) | |
Section = _ glob:SectionName _ children:(Comment / Rule)* _ { | |
return { | |
type: 'Section', | |
glob: glob.join(''), | |
children, | |
} | |
} | |
SectionName = '[' patterns:[^\]]+ ']' { | |
return patterns; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment