func nexType(sid syms.SymbolID, g grammar.Grammar) nex.Type { t, found := nonTermMap[sid] if found { return t } t = nex.NewType("Go/"+g.Syms.Get(sid).Name, NonTerm) nonTermMap[sid] = t return t }
package nexsys import ( "io" "os" "os/user" "path/filepath" "github.com/hialin/hialin/nex" ) var ( FileSystem = nex.NewType("FileSystem", nex.Entity) Directory = nex.NewType("Directory", FileSystem) File = nex.NewType("File", FileSystem) FileSize = nex.NewType("FileSize", FileSystem, nex.Amount, nex.ByteUnit) ) func GetFileNex(fpath string) nex.Nex { abspath, err := filepath.Abs(fpath) if err != nil { return nex.NewErrorNex(err) } fpath = filepath.Clean(abspath) fi, err := os.Stat(fpath) if err != nil { return nex.NewErrorNex(err) } return fileNex{fpath, fi} }
package nexsys import "github.com/hialin/hialin/nex" import ( "bufio" "mime" "os" "path/filepath" "strings" ) var ( Text = nex.NewType("Text", nex.Interpretation) TextFile = nex.NewType("TextFile", File) TextLine = nex.NewType("TextLine", Text) ) var textExtensions = map[string]bool{ ".go": true, ".conf": true, ".md": true, ".js": true, ".java": true, ".py": true, ".html": true, ".css": true, ".xml": true, ".xsd": true, ".json": true, }
"io" "io/ioutil" "github.com/hialin/hialin/nex" "github.com/hialin/hialin/parse/internal/engine/grammar" "github.com/hialin/hialin/parse/internal/engine/lexer" "github.com/hialin/hialin/parse/internal/engine/parser" "github.com/hialin/hialin/parse/internal/engine/syms" "github.com/hialin/hialin/trace" ) var tlog = trace.New("parse.golang") var ( GoInterpretation = nex.NewType("GoInterpretation", nex.ProgramInterpretation) GoEntity = nex.NewType("GoEntity", nex.ProgramEntity) Term = nex.NewType("Term", GoEntity) NonTerm = nex.NewType("NonTerm", GoEntity) ParseError = nex.NewType("ParseError", GoEntity, nex.ErrorMark) Expected = nex.NewType("Expected", ParseError) nonTermMap = make(map[syms.SymbolID]nex.Type) ) var ( s syms.SymbolSet l lexer.Lexer g grammar.Grammar
package nexsys import ( "os" "runtime" "github.com/hialin/hialin/nex" ) var Host = nex.NewType("Host", nex.Entity) func GetHostNex() nex.Nex { name, err := os.Hostname() if err != nil { return nex.NewErrorNex(err) } return hostNode{name} } type hostNode struct { name string } var _ nex.Nex = hostNode{} func (n hostNode) Type() nex.Type { return Host } func (n hostNode) Value() nex.Value { return nex.Str(n.name) } 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 {