Created
July 24, 2014 01:06
-
-
Save TrainerGuy22/758ffca6e059122f3b64 to your computer and use it in GitHub Desktop.
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
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