package main import ( "os" "bufio" ) type PathSegment interface {} type Path []PathSegment type TerminalValue int const ( ArrayBegin TerminalValue = iota ArrayEnd MapBegin MapEnd ) type ValueNull struct {} type ValueBool bool type ValueNumber float64 type ValueString string type WalkValue interface {} type WalkItem struct { value WalkValue path Path } type Program []Command type ProgramState struct { space []WalkItem in chan WalkItem out chan WalkItem program []Command } func main() { quiet := false var input string hasInput := false for i := 1; i < len(os.Args); i += 1 { switch os.Args[i] { case "-n": quiet = true continue } if i < len(os.Args) - 1 { panic("Unexpected arguments after program") } input = os.Args[i] hasInput = true } if !hasInput { panic("Missing program") } tokens := Lex(input) program := Parse(tokens) stdin := bufio.NewReader(os.Stdin) dataStream := Json(stdin) state := ProgramState { in: dataStream, out: make(chan WalkItem), program: program, } go func () { for walkItem := range dataStream { state.space = []WalkItem{walkItem} for _, cmd := range state.program { cmd.exec(&state) } if !quiet { for _, item := range state.space { state.out <- item } } } close(state.out) }() JsonOut(state.out) }