Esempio n. 1
0
func main() {
	f, err := os.Open(os.Args[1])
	if err != nil {
		panic(err)
	}

	file, err := ioutil.ReadAll(f)
	if err != nil {
		panic(err)
	}

	langdef, err := astgen.Load(file)
	if err != nil {
		panic(err)
	}

	var sortedTypes sort.StringSlice

	for s, _ := range langdef.Types {
		sortedTypes = append(sortedTypes, s)
	}

	// TODO: This sorting can be done by the library.

	sort.Sort(sortedTypes)

	for _, s := range sortedTypes {
		emitZeframParser(langdef, langdef.Types[s])
	}
}
Esempio n. 2
0
func main() {
	f, err := os.Open(os.Args[1])
	if err != nil {
		panic(err)
	}

	file, err := ioutil.ReadAll(f)
	if err != nil {
		panic(err)
	}

	langdef, err := astgen.Load(file)
	if err != nil {
		panic(err)
	}

	var sortedTypes sort.StringSlice

	for s, t := range langdef.Types {
		gatherTokens(t)
		sortedTypes = append(sortedTypes, s)
	}

	// TODO: This sorting can be done by the library.

	sort.Sort(sortedTypes)

	emitPrologue()

	for _, s := range sortedTypes {
		switch tt := langdef.Types[s].(type) {
		case *astgen.LexicalType:
			//emitLexical(tt)
		case *astgen.EnumType:
			emitEnum(tt)
		case *astgen.OptionType:
			emitOption(tt)
		case *astgen.StructType:
			emitStruct(tt)
		}
	}

	emitEpilogue()
}
Esempio n. 3
0
func main() {
	f, err := os.Open(os.Args[1])
	if err != nil {
		panic(err)
	}

	file, err := ioutil.ReadAll(f)
	if err != nil {
		panic(err)
	}

	langdef, err := astgen.Load(file)
	if err != nil {
		panic(err)
	}

	var sortedTypes sort.StringSlice

	for s, _ := range langdef.Types {
		sortedTypes = append(sortedTypes, s)
	}

	// TODO: This sorting can be done by the library.

	sort.Sort(sortedTypes)

	for _, s := range sortedTypes {
		switch tt := langdef.Types[s].(type) {
		case *astgen.LexicalType:
			// Nothing.
		case *astgen.EnumType:
			emitGoEnum(tt)
		case *astgen.OptionType:
			emitGoOption(tt)
		case *astgen.StructType:
			emitGoStruct(tt)
		}
	}
}
Esempio n. 4
0
func main() {
	if len(os.Args) != 3 || (os.Args[1] != "--header" && os.Args[1] != "--impl") {
		fmt.Fprintf(os.Stderr, "Usage:\n\t%s --header <filename>\n\t%s --impl <filename>\n\n", os.Args[0], os.Args[0])
		os.Exit(1)
	}

	f, err := os.Open(os.Args[2])
	if err != nil {
		panic(err)
	}

	file, err := ioutil.ReadAll(f)
	if err != nil {
		panic(err)
	}

	langdef, err := astgen.Load(file)
	if err != nil {
		panic(err)
	}

	var sortedTypes sort.StringSlice

	for s, _ := range langdef.Types {
		sortedTypes = append(sortedTypes, s)
	}

	// TODO: This sorting can be done by the library.

	_interfaces = interfaces(langdef)

	sort.Sort(sortedTypes)

	sortedTypes = sortIfaces(langdef, sortedTypes)

	if os.Args[1] == "--header" {
		for _, s := range sortedTypes {
			switch langdef.Types[s].(type) {
			case *astgen.LexicalType:
				// Nothing.
			case *astgen.EnumType:
				fmt.Printf("enum class %s;\n", s)
			case *astgen.OptionType, *astgen.StructType:
				fmt.Printf("class %s;\n", s)
			}
		}

		fmt.Println()

		emitCppVisitorInterface(langdef, sortedTypes)

		for _, s := range sortedTypes {
			switch tt := langdef.Types[s].(type) {
			case *astgen.LexicalType:
				// Nothing.
			case *astgen.EnumType:
				emitCppEnum(tt)
			case *astgen.OptionType:
				emitCppOption(tt)
			case *astgen.StructType:
				emitCppStructInterface(tt)
			}
		}
	} else {
		for _, s := range sortedTypes {
			switch tt := langdef.Types[s].(type) {
			case *astgen.StructType:
				emitVisitorImpl(tt)
			}
		}

		for _, s := range sortedTypes {
			switch tt := langdef.Types[s].(type) {
			case *astgen.StructType:
				emitCppStructImpl(tt)
			}
		}
	}
}