non functioning init
This commit is contained in:
parent
54d8301b96
commit
e3ea0f0201
57
tcl.go
Normal file
57
tcl.go
Normal file
@ -0,0 +1,57 @@
|
||||
package tcl
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
. "github.com/oec/goparsify"
|
||||
)
|
||||
|
||||
// Tcl parser, using combinators
|
||||
// Based on the grammer in:
|
||||
// https://wiki.tcl-lang.org/page/BNF+for+Tcl
|
||||
|
||||
var (
|
||||
word Parser
|
||||
commands Parser
|
||||
script Parser
|
||||
)
|
||||
|
||||
var (
|
||||
comment = NewParser("comment", Merge(NoAutoWS(Seq("#", NotChars("\r\n"))))).Map(found("comment"))
|
||||
wordExp = NewParser("{*}word", NoAutoWS(Seq("{*}", &word))).Map(found("wordExp"))
|
||||
wordSub = NewParser("[*]word", NoAutoWS(Seq("[*]", &word))).Map(found("wordSub"))
|
||||
wordBrc = NewParser("{word}", Seq("{", &word, "}")).Map(found("wordBrc"))
|
||||
wordQtd = NewParser(`"word"`, StringLit(`"`)).Map(found("wordQtd"))
|
||||
wordSmp = NewParser("simple", NotChars("{}[]*")).Map(found("simple"))
|
||||
command = NewParser("command", Many(&word)).Map(found("command")).Map(found("command"))
|
||||
)
|
||||
|
||||
func init() {
|
||||
word = NewParser("word", Any(&wordSmp, &wordQtd, &wordBrc, &wordSub, &wordExp)).Map(found("word"))
|
||||
commands = NewParser("commands", Any(&command, Maybe(Chars(";"))))
|
||||
script = NewParser("script", Many(Any(&comment, &commands)))
|
||||
}
|
||||
|
||||
func Parse(input string) (data interface{}, e error) {
|
||||
data, e = Run(&script, input, ASCIIWhitespace)
|
||||
return
|
||||
}
|
||||
|
||||
func ParseDebug(input string) (data interface{}, e error) {
|
||||
EnableLogging(os.Stdout)
|
||||
data, e = Run(&script, input, ASCIIWhitespace)
|
||||
return
|
||||
}
|
||||
|
||||
func found(typ string) func(*Result) {
|
||||
return func(r *Result) {
|
||||
log.Println("found a", typ)
|
||||
spew.Dump(r)
|
||||
|
||||
}
|
||||
}
|
||||
func dump(r *Result) {
|
||||
spew.Dump(r)
|
||||
}
|
33
tcl_test.go
Normal file
33
tcl_test.go
Normal file
@ -0,0 +1,33 @@
|
||||
package tcl
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFirst(t *testing.T) {
|
||||
input := `#TMSH-VERSION: 12.1.2
|
||||
|
||||
cli admin-partitions {
|
||||
update-partition Common
|
||||
}
|
||||
apm report default-report {
|
||||
report-name sessionReports/sessionSummary
|
||||
user /Common/admin
|
||||
}
|
||||
auth user admin {
|
||||
description "Admin User"
|
||||
encrypted-password $6$IIhG.HP4$kmWDt3Czta4rK5Ct4rYgaGSCDtqkMbAIgCUUdIDaQ/W8HTVHy7F1EZmSM.KYO9sdxDTuggaAGHj7QO/8f9rB80
|
||||
partition-access {
|
||||
all-partitions {
|
||||
role admin
|
||||
}
|
||||
}
|
||||
shell bash
|
||||
}`
|
||||
|
||||
d, e := ParseDebug(input)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
|
||||
t.Logf("got d: %#v\n", d)
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user