GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — meyer/ast/ast.go at v0.1.2 · sqlc-dev/meyer Expand file tree/ Copy pathast.goMore file actions 76 lines (67 loc) · 2.13 KB / Copy pathast.goFile metadata and controls76 lines (67 loc) · 2.13 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 // Package ast declares the syntax tree for the SQLite SQL dialect. // // Node names follow SQLite rather than PostgreSQL or sqlc: the tree is a // direct rendering of src/parse.y, and every node carries a comment naming // the grammar rule it comes from. Mapping onto another representation is a // consumer's job. // // Every node embeds Span and so reports byte offsets into the original // input; sqlc slices the source with those offsets, so they are load-bearing // rather than diagnostic (see PLAN.md). package ast import "reflect" // Node is implemented by every syntax tree node. Positions are byte offsets // into the original input. type Node interface { Pos() int End() int Children() []Node } // Stmt is implemented by all statement nodes. SetSpan is part of the // interface because the parser widens a statement's span once it has seen // the terminating semicolon, and a node that could not be widened would get // a quietly wrong span rather than a compile error. type Stmt interface { Node SetSpan(Span) stmtNode() } // Expr is implemented by all expression nodes. type Expr interface { Node exprNode() } // Span carries a node's byte extent and is embedded in every node type. type Span struct { Start int `json:"start"` Stop int `json:"end"` } func (s Span) Pos() int { return s.Start } func (s Span) End() int { return s.Stop } // SetSpan replaces the node's extent. The parser uses it to widen a // statement's span once its terminating semicolon has been consumed. func (s *Span) SetSpan(sp Span) { *s = sp } // Walk calls fn for n and, unless fn returns false, for its descendants in // source order. func Walk(n Node, fn func(Node) bool) { if isNil(n) || !fn(n) { return } for _, c := range n.Children() { Walk(c, fn) } } // isNil reports whether n is either a nil interface or a typed nil pointer. // Children() slices are assembled from optional fields, so typed nils are // common and must not leak into a traversal. func isNil(n Node) bool { if n == nil { return true } v := reflect.ValueOf(n) switch v.Kind() { case reflect.Pointer, reflect.Interface, reflect.Slice, reflect.Map: return v.IsNil() } return false } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |