Skip to content

Instantly share code, notes, and snippets.

@jednano
Last active October 28, 2019 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jednano/3accca5fec9c234538b82d6ac7df6681 to your computer and use it in GitHub Desktop.
Save jednano/3accca5fec9c234538b82d6ac7df6681 to your computer and use it in GitHub Desktop.
EditorConfig Grammar
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