Exemple #1
0
func TestRecursiveKnotElbow(t *testing.T) {
	p := ast.NewOr(ast.NewTreeNode(ast.NewAnyName(), ast.NewReference("main")), ast.NewTreeNode(ast.NewStringName("Elbow"), ast.NewZAny()))
	gkey, err := FieldNamesToNumbers("protonum", "Knot", ProtonumDescription(), p.Grammar())
	if err == nil {
		t.Fatalf("Expected: Any Field Not Supported: Name: _, but got %v", gkey)
	}
}
Exemple #2
0
func checkRef(refs ast.RefLookup, p *ast.Pattern) *ast.Pattern {
	for name, rpat := range refs {
		if rpat.Equal(p) {
			return ast.NewReference(name)
		}
	}
	return p
}
Exemple #3
0
func TestKeyLeftRecursive(t *testing.T) {
	p := ast.NewOr(
		ast.NewReference("a"),
		ast.NewTreeNode(ast.NewStringName("C"), ast.NewReference("main")),
		ast.NewTreeNode(ast.NewStringName("A"), ast.NewZAny()),
	)
	g := p.Grammar().AddRef("a", ast.NewReference("main"))
	gkey, err := FieldNamesToNumbers("debug", "Debug", debug.DebugDescription(), g)
	if err != nil {
		t.Fatal(err)
	}
	t.Logf("%v", gkey)
	if gkey.GetTopPattern().GetOr().GetRightPattern().GetOr().GetLeftPattern().GetTreeNode().GetName().GetName().GetUintValue() != 3 {
		t.Fatalf("expected field 3, but got %v", gkey)
	}
	check(t, gkey)
}
Exemple #4
0
func TestFormatGrammar(t *testing.T) {
	format(t, " #main =  *", "#main = *")
	format(t,
		`//attachedcomment
	  *`,
		`//attachedcomment
*`)
	format(t,
		`//unattachedcomment

		*`,
		`//unattachedcomment
*`)
	//2 pattern declarations
	format(t,
		`#main = *
			#other = a->any()`,
		`#main = *
#other = a->any()`)
	//2 pattern declarations without a new line
	format(t,
		`#main = *	#other = a->any()`,
		`#main = * #other = a->any()`)
	//3 pattern declarations
	format(t,
		`*
			#other = a->any()

			#more = (*)*`,
		`*
#other = a->any()
#more = (*)*`)
	//treenode
	format(t,
		`#main =   "a":*`,
		`#main = a:*`)
	format(t,
		ast.NewGrammar(map[string]*ast.Pattern{"main": ast.NewReference("ref1"), "ref1": ast.NewReference("main")}).String(),
		`@ref1
#ref1=@main`)
}
Exemple #5
0
func TestKeyRecursive(t *testing.T) {
	p := ast.NewOr(
		ast.NewTreeNode(ast.NewStringName("C"), ast.NewReference("main")),
		ast.NewTreeNode(ast.NewStringName("A"), ast.NewZAny()),
	)
	g := p.Grammar()
	gkey, err := FieldNamesToNumbers("debug", "Debug", debug.DebugDescription(), g)
	if err != nil {
		t.Fatal(err)
	}
	t.Logf("%v", gkey)
	check(t, gkey)
}