Пример #1
0
Файл: load.go Проект: kpmy/ot
func (w *Walker) traverse(o otm.Object) {
	var (
		this    schema.Guide
		skip    *bool
		skipped = func() {
			s := true
			skip = &s
		}
		important = func() {
			s := false
			skip = &s
		}
	)

	switch o.Qualident().Class {
	//structure elements
	case "grammar":
		skipped()
		if start := o.FindByQualident(otm.Qualident{Template: "ng", Class: "start"}); start != nil {
			w.forEach(start[0], traverseWrap())
		}
	case "ref":
		skipped()
		panic(0)
		/*		if ref := w.root.FindByName(n.Name); ref != nil {
					if cached := w.cache[n.Name]; cached == nil {
						this = Construct(n.XMLName)
						{
							std.NameAttr(this, n.Name)
							//std.RefAttr(this, cached.root)
						}
						w.cache[n.Name] = &Cached{node: ref, root: this}
						w.GrowDown(this)
						w.forEach(ref, traverseWrap())
						w.Up()
					} else {
						w.Grow(cached.root)
					}
				} else {
					halt.As(100, "ref not found", n.Name)
				}
		*/
	//content elements
	case "element", "attribute", "data", "text", "value", "name", "param":
		fallthrough
	//constraint elements
	case "choice", "interleave", "optional", "zeroOrMore", "oneOrMore", "group", "list", "mixed", "except", "anyName", "nsName", "empty", "externalRef":
		important()
		this = Construct(o.Qualident())
		{
			std.NameAttr(this, NameOf(o))
			/*std.CharDataAttr(this, n.Data())
			std.TypeAttr(this, n.Type)
			std.NSAttr(this, n.NS)
			std.DataTypeAttr(this, n.DataType)
			std.CombineAttr(this, n.Combine)
			std.HrefAttr(this, n.Href)
			*/
		}
		w.GrowDown(this)
		w.forEach(o, traverseWrap())
		w.Up()
	//skipped elements
	case "description": //descriprion do nothing
	default:
		halt.As(100, o.Qualident())
	}
	if skip != nil {
		assert.For(*skip || this != nil, 60, "no result for ", o.Qualident())
	} else if this == nil {
		log.Println("unhandled", o.Qualident())
	}
}