Ejemplo n.º 1
0
func emitOptionVisitor(langdef *astgen.LangDef, t *astgen.OptionType) {
	fmt.Print("func visit_")
	fmt.Printf("%v", strings.ToLower(t.Name))
	fmt.Print("(v: *Visitor, node: *AST")
	fmt.Printf("%v", t.Name)
	fmt.Print(")\n")
	fmt.Print("{\n")
	fmt.Print("\tif node == null {\n")
	fmt.Print("\t\treturn\n")
	fmt.Print("\t}\n")
	fmt.Print("\t\n")
	fmt.Print("\ttype switch node\n")
	for _, tt := range t.ConcreteTypes() {
		ttt := langdef.Types[tt].(*astgen.StructType)
		fmt.Print("\tcase *AST")
		fmt.Printf("%v", ttt.Name)
		fmt.Print(" {\n")
		fmt.Print("\t\tvisit_")
		fmt.Printf("%v", strings.ToLower(ttt.Name))
		fmt.Print("(v, node)\n")
		fmt.Print("\t}\n")
	}
	fmt.Print("\tdefault {\n")
	fmt.Print("\t\tfail BUG, \"Missing switch case.\"\n")
	fmt.Print("\t};;\n")
	fmt.Print("}\n")
}
Ejemplo n.º 2
0
func emitOptionType(t *astgen.OptionType) {
	fmt.Print("func parse_AST")
	fmt.Printf("%v", t.Name)
	fmt.Print("(p: *spl.SeqParser, r: *spl.Reader) (ret: own *AST")
	fmt.Printf("%v", t.Name)
	fmt.Print(")\n")
	fmt.Print("{\n")
	fmt.Print("\tif !p.is_list(r) {\n")
	fmt.Print("\t\tenv.print(\"parse_AST")
	fmt.Printf("%v", t.Name)
	fmt.Print(": Expected list start at \", p.line(), \":\", p.column(), \".\\n\")\n")
	fmt.Print("\t\tfail BAD_INPUT, \"parse_AST")
	fmt.Printf("%v", t.Name)
	fmt.Print(": Expected list start.\"\n")
	fmt.Print("\t}\n")
	fmt.Print("\t\n")
	fmt.Print("\tp.down(r)\n")
	fmt.Print("\t\n")
	fmt.Print("\tif p.is_end(r) {\n")
	fmt.Print("\t\tp.up(r)\n")
	fmt.Print("\t\treturn null\n")
	fmt.Print("\t}\n")
	fmt.Print("\t\n")
	fmt.Print("\tif !p.is_string(r) {\n")
	fmt.Print("\t\tenv.print(\"parse_AST")
	fmt.Printf("%v", t.Name)
	fmt.Print(": Expected string at \", p.line(), \":\", p.column(), \".\\n\")\n")
	fmt.Print("\t\tfail BAD_INPUT, \"parse_AST")
	fmt.Printf("%v", t.Name)
	fmt.Print(": Expected string.\"\n")
	fmt.Print("\t}\n")
	fmt.Print("\t\n")
	fmt.Print("\tvar tag = p.string(r)\n")
	fmt.Print("\t\n")
	fmt.Print("\tif p.is_end(r) {\n")
	fmt.Print("\t\tenv.print(\"parse_AST")
	fmt.Printf("%v", t.Name)
	fmt.Print(": Unexpected list end at \", p.line(), \":\", p.column(), \".\\n\")\n")
	fmt.Print("\t\tfail BAD_INPUT, \"parse_AST")
	fmt.Printf("%v", t.Name)
	fmt.Print(": Unexpected list end.\"\n")
	fmt.Print("\t}\n")
	fmt.Print("\t\n")
	fmt.Print("\tswitch tag\n")
	for _, tn := range t.ConcreteTypes() {
		fmt.Print("\tcase \"")
		fmt.Printf("%v", tn)
		fmt.Print("\" {\n")
		fmt.Print("\t\tret = parse_AST")
		fmt.Printf("%v", tn)
		fmt.Print("(p, r)\n")
		fmt.Print("\t}\n")
	}
	fmt.Print("\tdefault {\n")
	fmt.Print("\t\tenv.print(\"parse_AST")
	fmt.Printf("%v", t.Name)
	fmt.Print(": Unknown tag '\", tag, \"' before \", p.line(), \":\", p.column(), \".\\n\")\n")
	fmt.Print("\t\tfail BAD_INPUT, \"parse_AST")
	fmt.Printf("%v", t.Name)
	fmt.Print(": Unknown tag.\"\n")
	fmt.Print("\t};;\n")
	fmt.Print("\t\n")
	fmt.Print("\tif !p.is_end(r) {\n")
	fmt.Print("\t\tenv.print(\"parse_AST")
	fmt.Printf("%v", t.Name)
	fmt.Print(": Expected list end at \", p.line(), \":\", p.column(), \".\\n\")\n")
	fmt.Print("\t\tfail BAD_INPUT, \"parse_AST")
	fmt.Printf("%v", t.Name)
	fmt.Print(": Expected list end.\"\n")
	fmt.Print("\t}\n")
	fmt.Print("\t\n")
	fmt.Print("\tp.up(r)\n")
	fmt.Print("\t\n")
	fmt.Print("\treturn\n")
	fmt.Print("}\n")
}
Ejemplo n.º 3
0
func emitOptionType(t *astgen.OptionType) {
	fmt.Print("func ParseAST")
	fmt.Printf("%v", t.Name)
	fmt.Print("(p *spl.SeqParser) (ret AST")
	fmt.Printf("%v", t.Name)
	fmt.Print(", err error) {\n")
	fmt.Print("\tif !p.IsList() {\n")
	fmt.Print("\t\terr = fmt.Errorf(\"ParseAST")
	fmt.Printf("%v", t.Name)
	fmt.Print(": Expected list start at %d:%d.\", p.Line(), p.Column())\n")
	fmt.Print("\t\treturn\n")
	fmt.Print("\t}\n")
	fmt.Print("\t\n")
	fmt.Print("\tp.Down()\n")
	fmt.Print("\t\n")
	fmt.Print("\tif p.IsEnd() {\n")
	fmt.Print("\t\tp.Up()\n")
	fmt.Print("\t\treturn nil, nil\n")
	fmt.Print("\t}\n")
	fmt.Print("\t\n")
	fmt.Print("\tif !p.IsString() {\n")
	fmt.Print("\t\terr = fmt.Errorf(\"ParseAST")
	fmt.Printf("%v", t.Name)
	fmt.Print(": Expected string at %d:%d.\", p.Line(), p.Column())\n")
	fmt.Print("\t\treturn\n")
	fmt.Print("\t}\n")
	fmt.Print("\t\n")
	fmt.Print("\ttag := p.String()\n")
	fmt.Print("\t\n")
	fmt.Print("\tif p.IsEnd() {\n")
	fmt.Print("\t\terr = fmt.Errorf(\"ParseAST")
	fmt.Printf("%v", t.Name)
	fmt.Print(": Unexpected list end at %d:%d.\", p.Line(), p.Column())\n")
	fmt.Print("\t\treturn\n")
	fmt.Print("\t}\n")
	fmt.Print("\t\n")
	fmt.Print("\tswitch tag {\n")
	for _, tn := range t.ConcreteTypes() {
		fmt.Print("\tcase \"")
		fmt.Printf("%v", tn)
		fmt.Print("\":\n")
		fmt.Print("\t\tret, err = ParseAST")
		fmt.Printf("%v", tn)
		fmt.Print("(p)\n")
	}
	fmt.Print("\tdefault:\n")
	fmt.Print("\t\terr = fmt.Errorf(\"ParseAST")
	fmt.Printf("%v", t.Name)
	fmt.Print(": Unknown tag %s before %d:%d.\", tag, p.Line(), p.Column())\n")
	fmt.Print("\t\treturn\n")
	fmt.Print("\t}\n")
	fmt.Print("\t\n")
	fmt.Print("\tif err != nil {\n")
	fmt.Print("\t\treturn\n")
	fmt.Print("\t}\n")
	fmt.Print("\t\n")
	fmt.Print("\tif !p.IsEnd() {\n")
	fmt.Print("\t\terr = fmt.Errorf(\"ParseAST")
	fmt.Printf("%v", t.Name)
	fmt.Print(": Expected list end at %d:%d.\", p.Line(), p.Column())\n")
	fmt.Print("\t\treturn\n")
	fmt.Print("\t}\n")
	fmt.Print("\t\n")
	fmt.Print("\tp.Up()\n")
	fmt.Print("\t\n")
	fmt.Print("\treturn ret, nil\n")
	fmt.Print("}\n")
}