Skip to content

Instantly share code, notes, and snippets.

@TrainerGuy22
Created July 24, 2014 01:06
Show Gist options
  • Save TrainerGuy22/758ffca6e059122f3b64 to your computer and use it in GitHub Desktop.
Save TrainerGuy22/758ffca6e059122f3b64 to your computer and use it in GitHub Desktop.
library toml;
import "package:parser/parser.dart";
class TomlParser extends CompositeParser {
@override
void initialize() {
_grammar();
_parser();
}
void _parser() {
action("entry", (value) => print(value.toString()));
}
void _grammar() {
def("anything", letter() | digit() | whitespace());
def("newline", Token.newlineParser());
def("comment", char('#').seq(ref("newline").neg().plus().flatten()));
def("whitespace", (char('\t') | char(' ')).star());
def("key", letter().plus().flatten());
def("value", ref("anything").plus());
def("entry", ref("key").seq(ref("whitespace")).seq(char("=")).seq(ref("whitespace")).seq(ref("value")));
def("config", (ref("entry") | ref("comment")).separatedBy(ref("newline"), includeSeparators: false).star());
def("start", ref("config"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment