예제 #1
0
파일: item_test.go 프로젝트: seerdomin/gocc
/*
id : _a (_a | _b) _c =>
	id : •a (_a | _b) _c =>
		id : _a (• _a | _b) _c
		id : _a (_a | • _b) _c

id : _a (• _a | _b) _c =>
	id : _a (_a | _b) •_c =>
		id : _a (_a | _b) _c •

id : _a (_a | • _b) _c
	id : _a (_a | _b) •_c =>
		id : _a (_a | _b) _c •
*/
func Test4(t *testing.T) {
	src := "id : _a (_a | _b) _c ;"
	g := parse(src, t)
	symbols := symbols.NewSymbols(g.LexPart)

	items := NewItem("id", g.LexPart, symbols).Emoves()

	exp1 := "id : • _a (_a | _b) _c"
	matchItems(t, items, exp1)

	items1 := findItem(exp1, items).MoveRegDefId("_a")
	exp2 := "id : _a (• _a | _b) _c"
	exp3 := "id : _a (_a | • _b) _c"
	matchItems(t, items1, exp2, exp3)

	items2 := findItem(exp2, items1).MoveRegDefId("_a")
	exp4 := "id : _a (_a | _b) • _c"
	matchItems(t, items2, exp4)
	items3 := findItem(exp4, items2).MoveRegDefId("_c")
	exp5 := "id : _a (_a | _b) _c •"
	matchItems(t, items3, exp5)

	items4 := findItem(exp3, items1).MoveRegDefId("_b")
	exp6 := "id : _a (_a | _b) • _c"
	matchItems(t, items4, exp6)
}
예제 #2
0
파일: itemsets.go 프로젝트: seerdomin/gocc
func GetItemSets(lexPart *ast.LexPart) *ItemSets {
	itemSets := &ItemSets{
		sets:    make([]*ItemSet, 0, 256),
		lexPart: lexPart,
		symbols: symbols.NewSymbols(lexPart),
	}

	itemSets.Add(ItemsSet0(lexPart, itemSets.symbols))

	return itemSets.Closure()
}
예제 #3
0
파일: item_test.go 프로젝트: seerdomin/gocc
/*
id : [.] . =>
	id : [• .] .
	id : [.] • .

id : [.] • . =>
	id : [.] . •
*/
func Test3(t *testing.T) {
	src := `id : [.] .;`
	g := parse(src, t)
	symbols := symbols.NewSymbols(g.LexPart)

	items := NewItem("id", g.LexPart, symbols).Emoves()

	exp1 := "id : [• .] ."
	exp2 := "id : [.] • ."
	matchItems(t, items, exp1, exp2)
	exp3 := "id : [.] . •"
	matchItems(t, findItem(exp2, items).MoveDot(), exp3)
}
예제 #4
0
파일: item_test.go 프로젝트: seerdomin/gocc
/*
id : _a {_b} =>
	id : • _a {_b} =>
		id : _a {• _b}
		id : _a {_b} •
*/
func Test2(t *testing.T) {
	src := `_a : 'a'; _b : 'b' ; id : _a {_b};`
	g := parse(src, t)
	symbols := symbols.NewSymbols(g.LexPart)

	items1 := NewItem("id", g.LexPart, symbols).Emoves()

	exp1 := "id : • _a {_b}"
	matchItems(t, items1, exp1)

	items2 := findItem(exp1, items1).MoveRegDefId("_a")
	exp2 := "id : _a {• _b}"
	exp3 := "id : _a {_b} •"
	matchItems(t, items2, exp2, exp3)
}
예제 #5
0
파일: item_test.go 프로젝트: seerdomin/gocc
/*
id : _a | _b _a =>
	id : • _a | _b _a
	id : _a | • _b _a

id : • a | _b =>
	id : (_a | _b _a) •

id : a | • _b _a =>
	id : _a | _b • _a =>
		id : (_a | _b _A) •
*/
func Test1(t *testing.T) {
	src := `_a : 'a'; _b : 'b' ; id : _a | _b _a ;`
	g := parse(src, t)
	symbols := symbols.NewSymbols(g.LexPart)

	items1 := NewItem("id", g.LexPart, symbols).Emoves()
	exp1 := "id : • _a | _b _a"
	exp2 := "id : _a | • _b _a"
	matchItems(t, items1, exp1, exp2)

	exp3 := "id : (_a | _b _a) •"
	matchItems(t, findItem(exp1, items1).MoveRegDefId("_a"), exp3)

	exp4 := "id : _a | _b • _a"
	matchItems(t, findItem(exp2, items1).MoveRegDefId("_b"), exp4)
}
예제 #6
0
파일: item_test.go 프로젝트: seerdomin/gocc
/*
id : {_a | _b} =>
	id : {• _a | _b}
	id : {_a | • _b}
	id : {_a | _b} •

id : {• _a | _b} =>
	id : {• _a | _b}
	id : {_a | • _b}
	id : {_a | _b} •
*/
func Test5(t *testing.T) {
	src := `id : {_a | _b};`
	g := parse(src, t)
	symbols := symbols.NewSymbols(g.LexPart)

	items := NewItem("id", g.LexPart, symbols).Emoves()

	exp1, exp2, exp3 := "id : {• _a | _b}", "id : {_a | • _b}", "id : {_a | _b} •"
	matchItems(t, items, exp1, exp2, exp3)

	items1 := findItem(exp1, items).MoveRegDefId("_a")
	matchItems(t, items1, exp1, exp2, exp3)

	items2 := findItem(exp2, items).MoveRegDefId("_b")
	matchItems(t, items2, exp1, exp2, exp3)
}