diff options
author | Özgür Kesim <oec@codeblau.de> | 2019-06-17 08:47:04 +0200 |
---|---|---|
committer | Özgür Kesim <oec@codeblau.de> | 2019-06-17 08:47:04 +0200 |
commit | 7eb0b697dc157dfef2b7d4599b846788e7709ba3 (patch) | |
tree | b851cc7529b07f3e28dba116b94e11a41c260017 /tcl.go | |
parent | 9247710ccb1915a68d05dce81627ca99fc48b994 (diff) |
lexing successfully with larger example
Diffstat (limited to 'tcl.go')
-rw-r--r-- | tcl.go | 25 |
1 files changed, 18 insertions, 7 deletions
@@ -20,29 +20,40 @@ var ( ) var ( - comment = NewParser("comment", Merge(Seq("#", NotChars("\r\n")))).Map(drop) + comment = NewParser("comment", Merge(Seq("#", NotChars("\r\n"), Chars("\r\n")))).Map(drop) wordExp = NewParser("{*}word", Seq("{*}", &word)).Map(resultchild(1)) wordSub = NewParser("[*]word", Seq("[*]", &word)).Map(resultchild(1)) - wordBrc = NewParser("{command}", Seq("{", Many(&command), "}")).Map(func(r *Result) { collectchildren(&r.Child[1]); r.Result = r.Child[1].Result }) wordQtd = NewParser(`"word"`, StringLit(`"`)).Map(token) - wordSmp = NewParser("simple", NotChars("{}[]* ;\t\r\n")).Map(token) + wordSmp = NewParser("simple", NotChars("{} \t\r\n")).Map(token) + group = NewParser("{group}", Seq("{", Maybe(Chars("\r\n")), Some(Any(&command, &words)), "}")).Map(func(r *Result) { collectchildren(&r.Child[2]); r.Result = r.Child[2].Result }) ) func init() { - word = NewParser("word", Any(&wordSmp, &wordQtd, &wordBrc, &wordSub, &wordExp)) + word = NewParser("word", Any(&wordQtd, &group, &wordSmp, &wordSub, &wordExp)) words = NewParser("words", Many(&word)).Map(collectchildren) - command = NewParser("command", Seq(&words, Maybe(";"))).Map(resultchild(0)) + command = NewParser("command", Seq(&words, Any(";", Chars("\r\n")))).Map(resultchild(0)) script = NewParser("script", Many(Any(&comment, &command))).Map(collectchildren) } +func simpleWhitespace(s *State) { + for s.Pos < len(s.Input) { + switch s.Input[s.Pos] { + case '\t', '\v', '\f', ' ': + s.Pos++ + default: + return + } + } +} + func Parse(input string) (data interface{}, e error) { - data, e = Run(&script, input, ASCIIWhitespace) + data, e = Run(&script, input, simpleWhitespace) return } func ParseDebug(input string) (data interface{}, e error) { EnableLogging(os.Stdout) - data, e = Run(&script, input, ASCIIWhitespace) + data, e = Run(&script, input, simpleWhitespace) return } |