github.com/dannin/go@v0.0.0-20161031215817-d35dfd405eaa/src/cmd/compile/internal/gc/parser.go (about) 1 // Copyright 2015 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 the LICENSE file. 4 5 package gc 6 7 // The recursive-descent parser is built around a slighty modified grammar 8 // of Go to accommodate for the constraints imposed by strict one token look- 9 // ahead, and for better error handling. Subsequent checks of the constructed 10 // syntax tree restrict the language accepted by the compiler to proper Go. 11 // 12 // Semicolons are inserted by the lexer. The parser uses one-token look-ahead 13 // to handle optional commas and semicolons before a closing ) or } . 14 15 func mkname(sym *Sym) *Node { 16 n := oldname(sym) 17 if n.Name != nil && n.Name.Pack != nil { 18 n.Name.Pack.Used = true 19 } 20 return n 21 } 22 23 func unparen(x *Node) *Node { 24 for x.Op == OPAREN { 25 x = x.Left 26 } 27 return x 28 }