github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/internal/rsg/yacc/node.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in licenses/BSD-golang.txt. 4 5 // Portions of this file are additionally subject to the following license 6 // and copyright. 7 // 8 // Copyright 2016 The Cockroach Authors. 9 // 10 // Use of this software is governed by the Business Source License 11 // included in the file licenses/BSL.txt. 12 // 13 // As of the Change Date specified in that file, in accordance with 14 // the Business Source License, use of this software will be governed 15 // by the Apache License, Version 2.0, included in the file 16 // licenses/APL.txt. 17 18 // Copied from Go's text/template/parse package and modified for yacc. 19 20 // Parse nodes. 21 22 package yacc 23 24 // Pos represents a byte position in the original input text from which 25 // this template was parsed. 26 type Pos int 27 28 // Nodes. 29 30 // ProductionNode holds is a named production of multiple expressions. 31 type ProductionNode struct { 32 Pos 33 Name string 34 Expressions []*ExpressionNode 35 } 36 37 func newProduction(pos Pos, name string) *ProductionNode { 38 return &ProductionNode{Pos: pos, Name: name} 39 } 40 41 // ExpressionNode hold a single expression. 42 type ExpressionNode struct { 43 Pos 44 Items []Item 45 Command string 46 } 47 48 func newExpression(pos Pos) *ExpressionNode { 49 return &ExpressionNode{Pos: pos} 50 } 51 52 // Item hold an item. 53 type Item struct { 54 Value string 55 Typ ItemTyp 56 } 57 58 // ItemTyp is the item type. 59 type ItemTyp int 60 61 const ( 62 // TypToken is the token type. 63 TypToken ItemTyp = iota 64 // TypLiteral is the literal type. 65 TypLiteral 66 )