Skip to content

Instantly share code, notes, and snippets.

@ftaiolivista
Created June 28, 2024 13:24
Show Gist options
  • Save ftaiolivista/752d04e0ad939461c1fe19da26f05a51 to your computer and use it in GitHub Desktop.
Save ftaiolivista/752d04e0ad939461c1fe19da26f05a51 to your computer and use it in GitHub Desktop.
PeggyJS ini file grammar
{
function makeObject(entries) {
const result = {};
for (const [key, value] of entries) {
result[key] = value;
}
return result;
}
}
IniFile
= _ sections:Section* _ { return makeObject(sections); }
Section
= "[" _ name:Identifier _ "]" _ entries:Entry* _ { return [name, makeObject(entries)]; }
Entry
= key:Identifier _ "=" _ value:Value _ { return [key, value]; }
Identifier
= chars:[a-zA-Z0-9_]+ { return chars.join(''); }
Value
= chars:[^\n#]+ { return chars.join('').trim(); }
_
= (Whitespace / Comment)*
Whitespace
= [ \t\r\n]+
Comment
= [#|;] [^\n]*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment