Exemplo n.º 1
0
func BenchmarkParse(b *testing.B) {
	if raw, err := ioutil.ReadFile("./testdata/mm5.in"); err != nil {
		b.Fatal(err)
	} else {
		var p parser.PARSER
		data := string(raw)
		for i := 0; i < b.N; i++ {
			p.Parse(data)
		}
	}
}
Exemplo n.º 2
0
func parseresult(in string) (ret content.CompletionResult, err error) {
	var p cp.PARSER
	p.Parse(in)
	n := p.RootNode()
	for i := range n.Children {
		child := n.Children[i]
		switch child.Name {
		case "Variable":
			v := content.Field{}
			v.Type.Name.Relative = child.Children[0].Data()
			v.Name.Relative = data(child.Children[1])
			ret.Fields = append(ret.Fields, v)
		case "CFunction":
			f := content.Method{}
			f.Returns = append(f.Returns, content.Variable{Type: content.Type{Name: content.FullyQualifiedName{Relative: child.Children[0].Data()}}})
			f.Name.Relative = data(child.Children[1])
			args := child.Children[2:]
			for j := range args {
				if args[j].Name == "ConstQualifier" {
					// TODO
					break
				}
				p := content.Variable{}
				p.Type.Name.Relative = data(args[j])
				f.Parameters = append(f.Parameters, p)
			}
			ret.Methods = append(ret.Methods, f)
		case "ObjCFunction":
			f := content.Method{}
			f.Returns = append(f.Returns, content.Variable{Type: content.Type{Name: content.FullyQualifiedName{Relative: child.Children[1].Data()}}})
			args := child.Children[2:]
			for j := range args {
				p := content.Variable{}
				p.Type.Name.Relative = data(args[j].Children[1])
				p.Name.Relative = data(args[j].Children[0])

				f.Parameters = append(f.Parameters, p)
			}
			ret.Methods = append(ret.Methods, f)

		}
	}
	return
}