Пример #1
0
func (n fileNex) Relations(rels nex.Type) (nex.Field, error) {
	if rels == nex.Relation {
		return nex.NewField(nex.Super, nex.Attribute, nex.Sub), nil
	} else if rels == nex.Super {
		if isFileSystemRoot(n.path) {
			return nex.NewField(GetHostNex()), nil
		}
		n := GetFileNex(filepath.Dir(n.path))
		if n.Type() == nex.ErrorNex {
			return nil, n.(error)
		}
		return nex.NewField(n), nil
	} else if rels == nex.Attribute && !n.stat.IsDir() {
		return nex.NewField(fileSize{n}), nil
	} else if rels == nex.Sub {
		if n.stat.IsDir() {
			file, err := os.Open(n.path)
			if err != nil {
				return nil, err
			}
			defer file.Close()
			names, err := file.Readdirnames(-1)
			return &dirField{n.path, names, err}, nil
		}
		return newBinaryFileField(n.path), nil
	}
	return nex.NewField(), nil
}
Пример #2
0
func (n fileSize) Relations(rel nex.Type) (nex.Field, error) {
	if rel == nex.Relation {
		return nex.NewField(nex.Super), nil
	} else if rel == nex.Super {
		return nex.NewField(n.fileNex), nil
	}
	return nex.NewField(), nil
}
Пример #3
0
func (rn ruleNex) Relations(rels nex.Type) (nex.Field, error) {
	if rels == nex.Relation {
		return nex.NewField(nex.Sub), nil
	} else if rels == nex.Sub {
		return rn.subs, nil
	}
	return nex.NewField(), nil
}
Пример #4
0
func (n lineNex) Relations(filter nex.Type) (nex.Field, error) {
	if filter == nex.Relation {
		return nex.NewField(nex.Super), nil
	} else if filter == nex.Super {
		return nex.NewField(n.parent), nil
	}
	return nex.NewField(), nil
}
Пример #5
0
func (n textFileNex) Relations(filter nex.Type) (nex.Field, error) {
	if filter == nex.Relation {
		return nex.NewField(nex.Ground, nex.Attribute, nex.Sub), nil
	} else if filter == nex.Ground {
		return nex.NewField(n.fileNex), nil
	} else if filter == nex.Attribute {
		return nex.NewField(fileSize{n.fileNex}), nil
	} else if filter == nex.Sub {
		return newLineField(n)
	}
	return nex.NewField(), nil
}
Пример #6
0
func (n hostNode) Relations(filter nex.Type) (nex.Field, error) {
	if filter == nex.Relation {
		return nex.NewField(nex.Sub), nil
	} else if filter == nex.Sub {
		roots := []nex.Nex{}
		for _, r := range getFileSystemRoots() {
			roots = append(roots, GetFileNex(r))
		}
		return nex.NewField(roots...), nil
	}
	return nex.NewField(), nil
}
Пример #7
0
func makeNexFromArray(g grammar.Grammar, r grammar.Rule, x interface{}) nex.Nex {
	// tlog.Println("make nex from array rule: ", r.String(*g.Syms, -1))
	switch y := x.(type) {
	case []interface{}:
		if len(y) == 1 {
			return makeNex(g, y[0])
		}
		var a []nex.Nex
		for _, e := range y {
			a = append(a, makeNex(g, e))
		}
		a = cleanup(a)
		if len(a) == 0 {
			return nil
		}
		n := ruleNex{
			termNex: termNex{
				typ:   nexType(r.LHS, g),
				value: g.Syms.Get(r.LHS).Name,
			},
			subs: nex.NewField(a...),
		}
		return n
	default:
		tlog.Panic("Unknown type in makeNexFromArray ", y)
	}
	return nil
}
Пример #8
0
func makeNex(g grammar.Grammar, x interface{}) nex.Nex {
	// tlog.Println("make nex: ", x)
	switch y := x.(type) {
	case nil:
		return nil
	case nex.Nex:
		return y
	case lexer.Token:
		if y.ID == syms.EMPTY {
			return nil
		}
		return termNex{typ: Term, value: y.Str}
	// case []interface{}:
	// 	return makeNexFromArray(g, grammar.Rule{LHS: syms.IDENT}, y)
	case parser.ParseError:
		var a []nex.Nex
		for _, e := range y.Valid {
			a = append(a, makeNex(g, e))
		}
		var exp bytes.Buffer
		exp.WriteString("Expected: ")
		for _, sk := range y.Expected {
			exp.WriteString(sk.Name)
			exp.WriteString(" ")
		}
		a = append(a, termNex{typ: Expected, value: exp.String()})
		for _, t := range y.Invalid {
			a = append(a, termNex{typ: Term, value: t.Str})
		}
		a = cleanup(a)
		n := ruleNex{
			termNex: termNex{
				typ:   ParseError,
				value: "ParseError",
			},
			subs: nex.NewField(a...),
		}
		return n
	default:
		tlog.Panic("Unknown type in makeNex:", fmt.Sprintf("%#v", x))
	}
	return nil
}
Пример #9
0
func (b byteNex) Relations(rel nex.Type) (nex.Field, error) { return nex.NewField(), nil }
Пример #10
0
func (tn termNex) Relations(rels nex.Type) (nex.Field, error) { return nex.NewField(), nil }