Skip to content

Instantly share code, notes, and snippets.

@afucher
Created February 4, 2016 00:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afucher/a8729a5e67ae987d6c10 to your computer and use it in GitHub Desktop.
Save afucher/a8729a5e67ae987d6c10 to your computer and use it in GitHub Desktop.
Grammar from PEGjs for ini file
IniFile
= first: Section (BlankLine* others: Section*) {others.unshift(first); return others; }
Section
= section: SectionHeader "\n" values: KeyValues* {return {section:values}}
SectionHeader
= "[" section_name: word "]" {return section_name}
KeyValues
= a: word "=" value: word "\n"? {var o = {}; o[a]=value; return o;}
BlankLine
= "\n"
QuotedString
= '"' quote: NotQuote* '"' {return quote.join("")}
NotQuote
= !'"' char: . {return char}
myText = text:(word / space / Symbols)* {return text.join("");}
complexWord = word:(letter+ / Symbols+)* {return word.join("");}
word = letter+
freeMessage = char:.* {return char.join("");}
Text
= Numbers Text
/ Characters Text
/ Symbols Text
/ space
datetime
= year:Numbers "-" month:Numbers "-" day:Numbers Characters hour:Numbers ":" minute:Numbers ":" seconds:Numbers "." Numbers "-" Numbers ":" Numbers {return new Date(year, month-1, day, hour, minute, seconds);}
additive
= left:multiplicative "+" right:additive { return left + right; }
/ multiplicative
multiplicative
= left:primary "*" right:multiplicative { return left * right; }
/ primary
primary
= integer
/ "(" additive:additive ")" { return additive; }
integer "integer"
= digits:[0-9]+ { return parseInt(digits.join(""), 10); }
Numbers
= numbers: [0-9]+ {return numbers.join("")}
space = " " {return "";}
Characters
= text: [a-zA-Z]+ {return text.join("")}
Symbols
= symbols: "." / "(" / ")" / "@" / "=" / '"' / "-" / "*" / "\n" / ":" / "<" / ">" / "?" / "," / "/" / "_"
EOF
= !.
letter = text: [a-zA-Z0-9]+ {return text.join("")}
@hughesjanuary
Copy link

uh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment