Ejemplo n.º 1
0
Archivo: load.go Proyecto: kpmy/ot
func NameOf(o otm.Object) (ret string) {
	if x, ok := o.Child(0); ok {
		if s, ok := x.(string); ok {
			ret = s
		}
	}
	return
}
Ejemplo n.º 2
0
Archivo: imp.go Proyecto: kpmy/ot
func ResolveContext(o otm.Object, resolver ResolverFunc, data map[string]interface{}) (err error) {
	assert.For(!fn.IsNil(o), 20)

	switch tpl := o.Qualident().Template; tpl {
	case Core.TemplateName:
		err = resolveContext(o.(*object), resolver, data)
	default:
		err = errors.New("nothing to resolve")
	}
	return
}
Ejemplo n.º 3
0
Archivo: imp.go Proyecto: kpmy/ot
func Resolve(o otm.Object) (err error) {
	assert.For(!fn.IsNil(o), 20)

	switch tpl := o.Qualident().Template; tpl {
	case Core.TemplateName:
		err = resolve(Core, o)
	default:
		err = errors.New("nothing to resolve")
	}
	return
}
Ejemplo n.º 4
0
func prettyPrintObject(o otm.Object, log *testing.T) {
	parent := ""
	for x := o.Parent(); !fn.IsNil(x); x = x.Parent() {
		parent = fmt.Sprint(x.Qualident(), "<-", parent)
	}
	log.Log(parent, o.Qualident())
	if o.ChildrenCount() > 0 {
		log.Log(":")
		for _x := range o.Children() {
			switch x := _x.(type) {
			case otm.Object:
				prettyPrintObject(x, log)
			case otm.Link:
				log.Log("@", x.Object().Qualident())
			case string, float64, int64, rune, tri.Trit:
				log.Log(_x)
			case []uint8:
				s := zbase32.EncodeToString(x)
				log.Log("zbase32(", s, ")", x)
			default:
				halt.As(100, reflect.TypeOf(x))
			}
		}
		log.Log(";")
	}
}
Ejemplo n.º 5
0
Archivo: g.go Proyecto: kpmy/ot
func (f *fm) object(o otm.Object) {
	q := o.Qualident()
	if q.Template != "" {
		f.Ident(q.Template)
		f.Char('~')
	}
	f.Ident(q.Class)
	if q.Identifier != "" {
		f.Char('(')
		f.Ident(q.Identifier)
		f.Char(')')
	}
	if o.ChildrenCount() > 0 {
		f.Char(':')
		for _x := range o.Children() {
			f.Char(' ')
			switch x := _x.(type) {
			case otm.Object:
				f.object(x)
			case string:
				f.stringValue(x)
			case int64:
				i := strconv.Itoa(int(x))
				f.RawString(i)
			case float64:
				if math.IsInf(x, 1) {
					f.RawString("inf")
				} else if math.IsInf(x, -1) {
					f.RawString("-inf")
				} else {
					f_ := strconv.FormatFloat(x, 'f', 8, 64)
					f.RawString(f_)
				}
			case rune:
				r := strconv.FormatUint(uint64(x), 16)
				f.RawString("0" + r + "U")
			case tri.Trit:
				f.Trinary(x)
			case []uint8:
				f.RawString(zbase32.EncodeToString(x))
			default:
				halt.As(100, reflect.TypeOf(x))
			}
		}
		f.Char(';')
	} else {
		f.Char(' ')
	}
}
Ejemplo n.º 6
0
func renderHtml(o otm.Object, log *testing.T) {
	buf := bytes.NewBufferString("<!DOCTYPE HTML>")
	e := xml.NewEncoder(buf)
	var obj func(otm.Object)
	obj = func(o otm.Object) {
		clazz := o.InstanceOf().Qualident()
		if clazz.Template == "html" {
			start := xml.StartElement{}
			start.Name.Local = clazz.Class
			if id := o.Qualident().Identifier; id != "" {
				attr := xml.Attr{}
				attr.Name.Local = "id"
				attr.Value = id
				start.Attr = append(start.Attr, attr)
			}
			e.EncodeToken(start)
			for _x := range o.Children() {
				switch x := _x.(type) {
				case otm.Object:
					obj(x)
				case string:
					e.EncodeToken(xml.CharData([]byte(x)))
				default:
					halt.As(100, reflect.TypeOf(x))
				}
			}
			e.EncodeToken(start.End())
		}
	}

	for x := range o.ChildrenObjects() {
		if x.InstanceOf().Qualident().Template == "html" && x.InstanceOf().Qualident().Class == "html" {
			obj(x)
		}
	}
	e.Flush()
	log.Log(buf.String())
}
Ejemplo n.º 7
0
Archivo: imp.go Proyecto: kpmy/ot
func resolve(t *ForeignTemplate, o otm.Object) (err error) {
	assert.For(!fn.IsNil(o), 20)
	var processList []pfunc

	var upd func(t *ForeignTemplate, o otm.Object)
	upd = func(t *ForeignTemplate, o otm.Object) {
		if clazz, ok := t.Classes[o.Qualident().Class]; ok && (o.Qualident().Template == t.TemplateName || o.Qualident().Template == "") {
			inst := clazz.copyOf()
			o.InstanceOf(inst)
			if fn := inst.apply(o); fn != nil {
				processList = append(processList, fn)
			}
			//log.Println("class updated for", o.Qualident(), " set ", clazz.Qualident())
		}
		for x := range o.ChildrenObjects() {
			upd(t, x)
		}
	}

	upd(t, o)

	for tmp := processList; len(tmp) > 0; {
		var _tmp []pfunc
		for _, f := range tmp {
			var p pfunc
			if p, err = f(); err == nil && p != nil {
				_tmp = append(_tmp, p)
			} else if err != nil {
				_tmp = nil
				break
			}
		}
		tmp = _tmp
	}
	return
}
Ejemplo n.º 8
0
Archivo: load.go Proyecto: kpmy/ot
func (w *Walker) forEach(o otm.Object, do func(w *Walker, o otm.Object)) {
	for v := range o.ChildrenObjects() {
		do(w, v)
	}
}
Ejemplo n.º 9
0
Archivo: load.go Proyecto: 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())
	}
}
Ejemplo n.º 10
0
Archivo: i2m.go Proyecto: kpmy/ot
func copyOf(o otm.Object) otm.Producer {
	return func(...otm.Modifier) otm.Object {
		return o.CopyOf(otm.DEEP)
	}
}