aboutsummaryrefslogtreecommitdiff
path: root/src/go/parser/parser.go
AgeCommit message (Collapse)Author
2022-07-12[release-branch.go1.17] go/parser: limit recursion depthRoland Shoemaker
Limit nested parsing to 100,000, which prevents stack exhaustion when parsing deeply nested statements, types, and expressions. Also limit the scope depth to 1,000 during object resolution. Thanks to Juho Nurminen of Mattermost for reporting this issue. Fixes #53707 Updates #53616 Fixes CVE-2022-1962 Change-Id: I4d7b86c1d75d0bf3c7af1fdea91582aa74272c64 Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1491025 Reviewed-by: Russ Cox <rsc@google.com> Reviewed-by: Damien Neil <dneil@google.com> (cherry picked from commit 6a856f08d58e4b6705c0c337d461c540c1235c83) Reviewed-on: https://go-review.googlesource.com/c/go/+/417070 Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Knyszek <mknyszek@google.com>
2021-06-22go/parser: parse an ast.IndexExpr for a[]Rob Findley
To be consistent with Go 1.16, and to preserve as much information in the AST as possible, parse an ast.IndexExpr with BadExpr Index for the invalid expression a[]. A go/types test had to be adjusted to account for an additional error resulting from this change. We don't have a lot of test coverage for parser error recovery, so rather than write an ad-hoc test for this issue, add a new go/types test that checks that the indexed operand is used. Updates #46403 Change-Id: I21e6ff4179746aaa50e530d4091fded450e69824 Reviewed-on: https://go-review.googlesource.com/c/go/+/329791 Trust: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-05go/parser: don't parse a nil IndexExpr.IndexRob Findley
When parsing type parameters, an empty type instantiation was parsed as an IndexExpr with nil Index. This should be considered a breaking change to parsing: ast.Walk previously assumed that Index was non-nil. Back out the nil check in ast.Walk, and for now pack an empty argument list as a non-nil ListExpr with nil Elems. Alternatives considered: - Parsing the entire index expression as a BadExpr: this led to inferior errors while type checking. - Parsing the Index as a BadExpr: this seems reasonable, but encodes strictly less information into the AST. We may want to opt for one of these alternatives in the future, but for now let's just fix the breaking change. Change-Id: I93f2b89641692ac014b8ee98bfa031ed3477afb8 Reviewed-on: https://go-review.googlesource.com/c/go/+/315851 Trust: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-04-27go: various minor cleanups with the help of Golandkumakichi
• fix some typos • remove superfluous conversions/parentheses • remove superfluous nil checks Change-Id: I428bf6a7be551b79270567047878c3076dd6f2ff GitHub-Last-Rev: 3b1c7573cfdf89ac184fd6ae44bca4be78b0cd64 GitHub-Pull-Request: golang/go#45799 Reviewed-on: https://go-review.googlesource.com/c/go/+/314069 Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Findley <rfindley@google.com>
2021-04-20all: remove redundant spaces before . and ,Yury Smolsky
Change-Id: I6a4bd2544276d0638bddf07ebcf2ee636db30fea Reviewed-on: https://go-review.googlesource.com/c/go/+/311009 Run-TryBot: Yury Smolsky <yury@smolsky.by> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-04-16go/parser: add a SkipObjectResolution mode to bypass object resolutionRob Findley
Parser object resolution is an auxiliary feature in which the parser attempts to resolve identifiers to their declarations. In functionality, it significantly overlaps with go/types and in fact cannot be correctly computed at parse-time without type information (for example, it is generally not possible to resolve k in the composite lit c{k: v}). Due to these limitations, it is of limited utility and rarely used. Now that object resolution is isolated as a post-processing pass, it is trivial to offer a parser mode that skips it entirely. This CL adds that mode. Fixes #45104 Change-Id: I5a2c05437e298964ad2039e1ff98e63d6efbd1af Reviewed-on: https://go-review.googlesource.com/c/go/+/306149 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-04-13go/*,cmd/gofmt: guard AST changes with the typeparams build tagRob Findley
This CL changes our approach to guarding type parameter functionality and API. Previously, we guarded type parameter functionality with the parser.parseTypeParams parser mode, and were in the process of hiding the type parameter API behind the go1.18 build constraint. These mechanisms had several limitations: + Requiring the parser.parseTypeParams mode to be set meant that existing tooling would have to opt-in to type parameters in all places where it parses Go files. + The parseTypeParams mode value had to be copied in several places. + go1.18 is not specific to typeparams, making it difficult to set up the builders to run typeparams tests. This CL addresses the above limitations, and completes the task of hiding the AST API, by switching to a new 'typeparams' build constraint and adding a new go/internal/typeparams helper package. The typeparams build constraint is used to conditionally compile the new AST changes. The typeparams package provides utilities for accessing and writing the new AST data, so that we don't have to fragment our parser or type checker logic across build constraints. The typeparams.Enabled const is used to guard tests that require type parameter support. The parseTypeParams parser mode is gone, replaced by a new typeparams.DisableParsing mode with the opposite sense. Now, type parameters are only parsed if go/parser is compiled with the typeparams build constraint set AND typeparams.DisableParsing not set. This new parser mode allows opting out of type parameter parsing for tests. How exactly to run tests on builders is left to a follow-up CL. Updates #44933 Change-Id: I3091e42a2e5e2f23e8b2ae584f415a784b9fbd65 Reviewed-on: https://go-review.googlesource.com/c/go/+/300649 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-03-31go/parser: switch to resolving objects as a post-processing passRob Findley
Coupling object resolution to parsing complicates the parsing code, and is a barrier to improvement. It requires passing around context such as 'lhs' or 'keyOk', and even then sometimes requires guess-work, such as whether to resolve the key in a composite literal. In this CL we delay object resolution to a separate pass after the file parse completes. This makes it easier to see logic of scoping, and removes state from the parsing code. This can enable subsequent improvements such as optionally skipping object resolution, aligning the parser with cmd/compile/internal/syntax, and allowing alternative parsers to reuse object resolution. The additional AST traversal appears to slow down parsing by around 4%. That seems small enough not to worry about, especially since performance sensitive users may eventually be able to disable object resolution entirely, saving around 18% off the previous baseline. I'll also mail a speculative CL showing how we can significantly mitigate the cost of object resolution by transposing scopes. For #45104 Change-Id: I98d9143fd77ae29e84ec7c3ae2fdb1139510da37 Reviewed-on: https://go-review.googlesource.com/c/go/+/304455 Trust: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-03-31go/parser: remove redundant list argument to Parser.shortVarDeclRob Findley
Change-Id: I75d089a7c1c3cdd50e5d2dafdb3386620efff4c9 Reviewed-on: https://go-review.googlesource.com/c/go/+/304454 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-03-30go/parser: resolve the type name when parsing a composite lit valueRob Findley
parsePrimaryExpr has to be careful to resolve identifiers used in composite expressions when parsing in LHS mode. It missed the literal type name. Fixes #45136 Change-Id: I3e12f91e3ef5fdb43faa436cdf1240eb3293fe1a Reviewed-on: https://go-review.googlesource.com/c/go/+/304451 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-03-17go/parser: avoid formatting a panic message if an assertion succeedsRob Findley
tryResolve is an extremely hot method on the parser. Eliminating this formatting led to a 20% performance improvement in BenchmarkParse. Change-Id: Idf8850404bd72d45d1351356427a85086422ea68 Reviewed-on: https://go-review.googlesource.com/c/go/+/302629 Trust: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-03-02go/parser,go/types: hide API changes related to type parametersRob Findley
While the dev.typeparams branch was merged, the type parameter API is slated for go1.18. Hide these changes to the go/parser and go/types API. This was done as follows: + For APIs that will probably not be needed for go1.18, simply unexport them. + For APIs that we expect to export in go1.18, prefix symbols with '_', so that the planned (upper-cased) symbol name is apparent. + For APIs that must be exported for testing, move both API and tests to files guarded by the go1.18 build constraint. + parser.ParseTypeParams is unexported and copied wherever it is needed. + The -G flag is removed from gofmt, replaced by enabling type parameters if built with the go1.18 build constraint. Notably, changes related to type parameters in go/ast are currently left exported. We're looking at the AST API separately. The new API diff from 1.16 is: +pkg go/ast, method (*FuncDecl) IsMethod() bool +pkg go/ast, method (*ListExpr) End() token.Pos +pkg go/ast, method (*ListExpr) Pos() token.Pos +pkg go/ast, type FuncType struct, TParams *FieldList +pkg go/ast, type ListExpr struct +pkg go/ast, type ListExpr struct, ElemList []Expr +pkg go/ast, type TypeSpec struct, TParams *FieldList +pkg go/types, type Config struct, GoVersion string Change-Id: I1baf67e26279b49092e774309a836c460979774a Reviewed-on: https://go-review.googlesource.com/c/go/+/295929 Trust: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-02-22go/parser: return ast.BadExpr for missing index operandsRob Findley
The parser was returning the indexed operand when a slice or index or instance expression was missing any index arguments (as in the expression `a[]`). This can result in returning an *ast.Ident for the LHS of the (invalid) assignment `a[] = ...` -- in this case parsing the LHS as just `a`. Unfortunately, as the indexed operand `a` has already been resolved, this results in a panic for duplicate resolution. Fix this by instead returning an ast.BadExpr. This can suppress some subsequent errors from the typechecker, but those errors may or may not be correct anyway. Other interpretations, such as an *ast.IndexExpr with bad or missing X, run into potential misinterpretations downstream (both caused errors in go/types and/or gopls). Fixes #44504 Change-Id: I5ca8bed4a1861bcc7db8898770b08937110981d4 Reviewed-on: https://go-review.googlesource.com/c/go/+/295151 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-02-19go/parser: improve error recovery from invalid selector exprsRob Findley
Before this CL, the parser consumed the next token following an invalid selector expr no matter what it was. This leads to poor error recovery when this next token is a closing delimiter or other reasonable element of a stop set. As a side-effect, x/tools tests broke when parser logic for type parameters was introduced, as they threw off the parser synchronization to the point where the x/tools test bailed out. This CL introduces a targeted fix that allows the x/tools tests to pass. More general improvement for parser error recovery should be done for go1.17. Change-Id: I44d73d34b6063e62d16a23d24ab7cbce6500239d Reviewed-on: https://go-review.googlesource.com/c/go/+/293792 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2021-02-18[dev.typeparams] go/types: use a new ast.ListExpr for multi-type instancesRob Findley
Modify go/parser to consistently represent type instantiation as an ast.IndexExpr, rather than use an ast.CallExpr (with Brackets:true) for instantiations with multiple type parameters. To enable this, introduce a new ast expr type: ListExpr. This brings go/types in line with types2, with the exception of a small change to funcInst to eliminate redundant errors if values are erroneously used as types. In a subsequent CL, call.go and expr.go will be marked as reviewed. This also catches some type instance syntax using '()' that was previously accepted incorrectly. Tests are updated accordingly. Change-Id: I30cd0181c7608f1be7486a9a8b63df993b412e85 Reviewed-on: https://go-review.googlesource.com/c/go/+/293010 Trust: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-01-19[dev.typeparams] go/parser: error for type instances without ParseTypeParamsRob Findley
It should be an invariant that the parser does not produce ast.CallExprs with Brackets == true unless parsing with ParseTypeParams. Fix the one case where this invariant was violated, and add a test for errors produced in valid generic code when ParseTypeParams is unset. We did have some coverage of errors in short_test.go, but I find them to be easier to read in a testdata file and would like to gradually migrate them there. Change-Id: If2d174377087daa1b820cabc2b5bf8bcb0b39d8e Reviewed-on: https://go-review.googlesource.com/c/go/+/284192 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Griesemer <gri@golang.org> Trust: Robert Findley <rfindley@google.com>
2020-12-08[dev.typeparams] go/*: add TODOs from CLs importing dev.go2go changesRob Findley
With the plurality of CLs importing dev.go2go changes it's getting hard to track all of the code review comments that were deferred for later consideration. Add some TODOs to capture these comments in the source, so that they may be more easily located. Change-Id: I5caf085fec11ca8992b7affe6feb0a7aa202f21f Reviewed-on: https://go-review.googlesource.com/c/go/+/276254 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2020-11-24[dev.typeparams] go/parser: support the ParseTypeParams modeRob Findley
Support is added for parsing type parameters only if the ParseTypeParams mode is set, otherwise emitting syntax errors for source code that is invalid without type parameters. Rather than have large conditional blocks switching between legacy parser logic and new parser logic, effort is made to minimize special handling for ParseTypeParams. Change-Id: I243f6c4b9b8eb1313b838e8649b6cc1e5e8339ba Reviewed-on: https://go-review.googlesource.com/c/go/+/271218 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Griesemer <gri@golang.org> Trust: Robert Findley <rfindley@google.com>
2020-11-24[dev.typeparams] import go2go changes to parse type parametersRob Findley
This CL imports changes on the go2go branch to support parsing type params, as well as the unsubmitted changes from CL 269300 to remove support for parenthesize type parameter syntax. Change-Id: I27ab942ce69eab62c2a1800f8f9661c4dcb233fe Reviewed-on: https://go-review.googlesource.com/c/go/+/270857 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Griesemer <gri@golang.org> Trust: Robert Findley <rfindley@google.com>
2019-10-29go/parser: use valid position when reporting an error (copy-paste bug)Robert Griesemer
This is a follow-up on https://golang.org/cl/202581. Updates #33649. Change-Id: Ib078fed983792c5493bdbed6d33e21b86856894a Reviewed-on: https://go-review.googlesource.com/c/go/+/204041 Run-TryBot: Robert Griesemer <gri@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-10-28go/parser, go/ast: correctly take into account presence of } in blockRobert Griesemer
Correctly track whether the closing } of a block (or a function body) is present or not in the AST and report correct End() positions in each case. There are more cases like this but this CL addresses an immediate issue and sets a precedent for how to fix similar cases if a need arises. Fixes #33649. Change-Id: Id6662ddaac09f3c15f8003edc9275fe2b0c41c78 Reviewed-on: https://go-review.googlesource.com/c/go/+/202581 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
2019-10-22go/parser: remove superfluous case from switch statementajz01
Change-Id: I96a9b34bf8e42c21a3e0258cbc8b1416328834be GitHub-Last-Rev: 32709619a690459dc29a32f12cfbd3908ce270e3 GitHub-Pull-Request: golang/go#35066 Reviewed-on: https://go-review.googlesource.com/c/go/+/202598 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2019-10-21go/parser: better error (recovery) for Allman/BSD-style func declsRobert Griesemer
This matches the behavior and error of cmd/compile. Fixes #34946. Change-Id: I329ef358deea63d8425f76f1d54c95749b96c365 Reviewed-on: https://go-review.googlesource.com/c/go/+/202484 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-07-08Revert "go/parser: include more comments in a struct or interface"Agniva De Sarker
This reverts commit https://golang.org/cl/161177/. Reason for revert: this led to non-contiguous comments spaced by an empty line to be grouped into a single CommentGroup Fixes #32944 Updates #10858 Change-Id: I5e16663b308c3b560496da8e66c33befdf9ed9dd Reviewed-on: https://go-review.googlesource.com/c/go/+/185040 Reviewed-by: Robert Griesemer <gri@golang.org>
2019-03-06go/parser: include more comments in a struct or interfaceAgniva De Sarker
While parsing inside a struct or an interface, skipping over empty lines too to collect the next group of comments. We do not need to skip over more than 1 empty line since gofmt already removes multiple empty consecutive lines. Fixes #10858 Change-Id: I0c97b65b5fc44e225e5dc7871ace24f43419ce08 Reviewed-on: https://go-review.googlesource.com/c/go/+/161177 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2018-10-06all: fix a bunch of misspellingsIgor Zhilianin
Change-Id: If2954bdfc551515403706b2cd0dde94e45936e08 GitHub-Last-Rev: d4cfc41a5504cf10befefdb881d4c45986a1d1f8 GitHub-Pull-Request: golang/go#28049 Reviewed-on: https://go-review.googlesource.com/c/140299 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-05-18go/parser: make sure we have a valid AST when 'if' condition is missingRobert Griesemer
This prevents a crash in go/types due to a nil condition in an 'if' statement. There's more we can do to make go/types more robust but this will address the immediate cause and also makes sure that the parser returns a valid AST in this case. Fixes #25438. Change-Id: Ie55dc2c722352a5ecb17af6a16983741e8a8b515 Reviewed-on: https://go-review.googlesource.com/113735 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Dominik Honnef <dominik@honnef.co> Reviewed-by: Alan Donovan <adonovan@google.com>
2018-02-12go/parser: improved error message for unexpected literalsRobert Griesemer
R=go1.11 This is a follow up for #11377 which reported that an error like /tmp/xx.go:9:6: expected '(', found 'IDENT' F1 shouldn't print 'IDENT', as it's just an internal detail. The relevant change wasn't made in the original fix, so here it is. For #11377. Change-Id: Ib76957d86b88e3e63646fbe4abf03a3b9d045139 Reviewed-on: https://go-review.googlesource.com/87900 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-12go/parser: remove newly introduced TODO (cleanup)Robert Griesemer
R=go1.11 No semantic change. For #23434. Change-Id: Iafdb062b0ebe6cd6e51f9a98b62b1d10f1bacc5c Reviewed-on: https://go-review.googlesource.com/87899 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-12go/parser: improved error recovery after missing typeRobert Griesemer
R=go1.11 This CL also introduces a new TODO in parser.go. To be addressed in a separate CL to make this easier to review. Also: Make parser's test harness easier to use by ignoring auto-inserted (invisible) semicolons when computing error positions. Adjusted testdata/commas.src accordingly. Fixes #23434. Change-Id: I050592d11d5f984f71185548394c000eea509205 Reviewed-on: https://go-review.googlesource.com/87898 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-12go/parser: more robust error handling for 'if' headersRobert Griesemer
R=go1.11 To fix this, this CL borrows code from the new syntax package which has a better tuned parser at this point. Fixes #11377. Change-Id: Ib9212c945903d6f62abcc59ef5a5767d4ef36981 Reviewed-on: https://go-review.googlesource.com/87495 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-08-06all: remove some manual hyphenationJosh Bleecher Snyder
Manual hyphenation doesn't work well when text gets reflown, for example by godoc. There are a few other manual hyphenations in the tree, but they are in local comments or comments for unexported functions. Change-Id: I17c9b1fee1def650da48903b3aae2fa1e1119a65 Reviewed-on: https://go-review.googlesource.com/53510 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-06-12go/parser: handle last line commentsHiroshi Ioka
Fixes #20636 Change-Id: Icea0012fecb73944c95f6037922505c63b57b245 Reviewed-on: https://go-review.googlesource.com/45295 Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-01-09[dev.typealias] go/ast, go/parser, go/printer, go/types: initial type alias ↵Robert Griesemer
support Parsing and printing support for type aliases complete. go/types recognizes them an issues an "unimplemented" error for now. For #18130. Change-Id: I9f2f7b1971b527276b698d9347bcd094ef0012ee Reviewed-on: https://go-review.googlesource.com/34986 Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-11-05Revert "go/ast, go/parser: parse alias declarations"Robert Griesemer
This reverts commit 57ae83307fc4cb90338b39dcc6fe3c61ee8ce0b7. Reason: Decision to back out current alias implementation. For #16339. Change-Id: I7bcc04ac87ea3590999e58ff65a7f2e1e6c6bc77 Reviewed-on: https://go-review.googlesource.com/32823 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-10-27cmd/compile, go/parser: disallow "type T = p.T" - must use "=>"Robert Griesemer
I had added this originally so we can play with different notations but it doesn't make sense to keep it around since gofmt will convert a type alias declaration using "=" into one using "=>" anyhow. More importantly, the spec doesn't permit it. Change-Id: Icb010b5a9976aebf877e48b3ce9d7245559ca494 Reviewed-on: https://go-review.googlesource.com/32105 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-10-04go/ast, go/parser: parse alias declarationsRobert Griesemer
For now, we also accept "type p = p.T" (using = instead of =>, for type aliases only), so we can experiment with an approach that only uses type aliases. This concession is implemened in the parser. For #16339 Change-Id: I88b5522a8b6cfc2e97ca146ede8b32af340220f8 Reviewed-on: https://go-review.googlesource.com/30211 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-02-26cmd/compile, go/parser: simpler binary expression parsingMatthew Dempsky
The existing nested loops are too tricky for me to grok and don't seem necessary. Change-Id: I75c65c8470b799d6f4cfb05bb1b4796c5d7d32e7 Reviewed-on: https://go-review.googlesource.com/19927 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2015-12-07go/parser, go/types: report invalid else branch in if statementsRobert Griesemer
- Only accept valid if statement syntax in go/parser. - Check AST again in go/types since it may have been modified and the AST doesn't preclude other statements in the else branch of an if statement. - Removed a test from gofmt which verified that old-style if statements permitting any statement in the else branch were correctly reformatted. It's been years since we switched to the current syntax; no need to support this anymore. - Added a comment to go/printer. Fixes #13475. Change-Id: Id2c8fbcc68b719cd511027d0412a37266cceed6b Reviewed-on: https://go-review.googlesource.com/17408 Reviewed-by: Russ Cox <rsc@golang.org>
2015-09-16go/parser: better error message for incorrect type switch headerRobert Griesemer
Fixes 11829. Change-Id: I2e39f61e12953147b0cd6a11d29179c500c94964 Reviewed-on: https://go-review.googlesource.com/14566 Reviewed-by: Chris Manghane <cmang@golang.org>
2015-09-16go/parser: comma is not permitted at the end of a struct field listRobert Griesemer
Fixes #11611. Change-Id: I63d35cf15c3be759c899e3e561e631330dcc0bbb Reviewed-on: https://go-review.googlesource.com/14565 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Chris Manghane <cmang@golang.org>
2015-09-14go/parser: better error message for unexpected ',' in struct typeRobert Griesemer
Fixes #12437. Change-Id: I5463970a6259527003eb0e12903a338cc78e0683 Reviewed-on: https://go-review.googlesource.com/14564 Reviewed-by: Chris Manghane <cmang@golang.org>
2015-06-18go/parser: document that parser accepts a wider language than specifiedRobert Griesemer
See also issue #11271. Change-Id: I34175f46ce137b14ca483500f673b0f8ee1f2108 Reviewed-on: https://go-review.googlesource.com/11262 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-20go/parser: parse incomplete selection "fmt." as a blank selection "fmt._"Alan Donovan
Formerly it would return a BadExpr. This prevents partial syntax from being discarded, and makes the error recovery logic more consistent with other places where an identifier was expected but not found. + test Change-Id: I223c0c0589e7ceb7207ae951b8f71b9275a1eb73 Reviewed-on: https://go-review.googlesource.com/10269 Reviewed-by: Robert Griesemer <gri@golang.org>
2015-05-15go/parser: better error message for missing ',' in listsRobert Griesemer
Fixes #8940. Change-Id: Ie9e5149983518ba8d56ddd82ac8f4cde6b644167 Reviewed-on: https://go-review.googlesource.com/10089 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-20go/parser: permit type elision from composite literal map keysRobert Griesemer
Per pending https://go-review.googlesource.com/2591 . Change-Id: I1ce9d1c629e9fc43dbd862b3433aa5840f46656c Reviewed-on: https://go-review.googlesource.com/2621 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-18all: use "reports whether" in place of "returns true if(f)"Josh Bleecher Snyder
Comment changes only. Change-Id: I56848814564c4aa0988b451df18bebdfc88d6d94 Reviewed-on: https://go-review.googlesource.com/7721 Reviewed-by: Rob Pike <r@golang.org>
2015-02-24go/ast, go/parser: correct End() position for *ast.EmptyStmtRobert Griesemer
- added a new field ast.EmptyStmt.Implicit to indicate explicit or implicit semicolon - fix ast.EmptyStmt.End() accordingly - adjusted parser and added test case Fixes #9979. Change-Id: I72b0983b3a0cabea085598e1bf6c8df629776b57 Reviewed-on: https://go-review.googlesource.com/5720 Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-23go/parser: report error for var/const decls with missing init exprsRobert Griesemer
Fixes #9639. Change-Id: I311045d3df26b29b9380c159ef4727e85650d13b Reviewed-on: https://go-review.googlesource.com/3211 Reviewed-by: Alan Donovan <adonovan@google.com>
2014-12-30go/parser: add {map,chan,interface} to expression lookahead tokensAlan Donovan
+ tests that these parse: map[int]int{}[0]++ interface{f()}(x).f() chan int(x) <- 0 Fixes #9474 Change-Id: If9fa57b3ab415ae7e93aa9935ec63edda8fe9d4f Reviewed-on: https://go-review.googlesource.com/2178 Reviewed-by: Robert Griesemer <gri@golang.org>