Commit Graph

17 Commits

Author SHA1 Message Date
Rintaro Ishizaki
a673043737 Terminology change: 'garbage' -> 'unexpected'
There are no "garbage" characters in Swift code. They are just
"unexpected."
2022-08-15 14:32:28 -07:00
Robert Widmann
ddd876614e MissingDeclSyntax Can Have Attributes and Modifiers
Strange as it sounds, we parse

@foo public

in item position as a decl that has a hanging attribute and access
control modifier. We need to be able to stick... something in the
tree here so we don't just drop these tokens on the floor.
2022-08-11 11:06:26 -07:00
Alex Hoppen
c2695f0ffc [libSyntax] Allow adding garbage nodes in between any two children of a syntax node
When the source code is invalid, this allows us to represent tokens that could not be used to form a valid syntax tree with more fidelity.

This commit does not start using GarbageNodes yet, it just sets everything up for them.
2022-08-04 09:20:31 +02:00
Alex Hoppen
e643fb14b5 Introduce a new syntax kind to represent missing base nodes
In the future, we only want to attach a source presence to tokens, not to nodes. All concreate nodes which are missing can be represented by creating the node and marking all tokens as missing, but if a syntax node carries a child, that has a base kind (like `Decl`), we can’t decide which concrete node to instantiate. Introduce `MissingDecl` etc. node for this purpose.

rdar://97908258
rdar://97775360
2022-08-01 16:22:47 +02:00
Kim de Vos
a8fa3ba0eb Added helper variables and methods for SwiftSyntax gyb
https://github.com/apple/swift-syntax/pull/268
2021-04-21 13:03:23 +02:00
Saleem Abdulrasool
e3c60e631d gyb: make SyntaxSupport python3 compatible
Adjust the python imports to be python2 and python3 compatible to enable
gyb to be switched over to python3.
2020-05-31 14:23:04 -07:00
Argyrios Kyrtzidis
3612cd3d72 [utils/gyb_syntax_support] Add collection_element_name for when specifying a Child
This is useful to provide `add<ELEMENT_NAME>` APIs for SwiftSyntax that are better named
and without having name conflicts.
2019-04-23 18:14:39 -07:00
Alex Hoppen
1b3baf908f [incrParse] Add error nodes to the end of a CodeBlockItem
Creating a new CodeBlockItem meant that when doing an edit in the error
nodes, the prefix gets reused and thus the code is parsed as invalid
although it is not.
2018-05-22 09:07:55 -07:00
Alex Hoppen
e1a99efd57 [incrParse] Fix parsing of nodes covering no source text 2018-05-22 08:52:39 -07:00
Alex Hoppen
4c1b27db83 [libSyntax] Fix parsing of delayed function bodies 2018-04-27 21:05:36 -07:00
Harlan
2a3d4cb598 Initial infrastructure for documenting SwiftSyntax API (#14701) 2018-02-26 13:43:11 -05:00
Xi Ge
7c905d38af SwiftSyntax: add WithStatementsSyntax trait and make all names consistent. NFC (#14782) 2018-02-22 14:38:29 -08:00
Xi Ge
1b81fcb2b6 SwiftSyntax: Add a trait for those statement nodes with code block as body. (#14726)
This patch also refactors SyntaxNodes code so that protocol conformances
are declared as extensions.
2018-02-19 18:49:07 -08:00
Xi Ge
2b61d4edbb SwiftSyntax: add a mechanism to define traits of syntax nodes to allow abstract access to popular child kinds. NFC (#14668)
Swift syntax APIs lack an abstract way of accessing children. The client has to
down-cast a syntax node to the leaf type to access any of its children. However,
some children are common among different syntax kinds, e.g.
DeclAttributeSyntax and DeclMembers. We should allow an abstract way to
access and modify them, so that clients can avoid logic duplication.

This patch adds a mechanism to define new traits and specify satisfied
traits in specific syntax nodes. A trait is a set of common children
and implemented in Swift as a protocol for syntax nodes to conform to.
As a proof-of-concept, we added two traits for now including DeclGroupSyntax
and BracedSyntax.

Resolves: SR-6931 and SR-6916
2018-02-15 16:41:20 -08:00
Rintaro Ishizaki
6c0af2a24f [Syntax] Introduce CodeBlockItem (#14458)
CodeBlockItem represents Decl, Stmt or Expr that optionally followed by
semi-colon.
SourceFile syntax holds a list of CodeBlockItem.
2018-02-08 10:31:01 +09:00
Harlan
a339c82c1e [SwiftSyntax] Make Syntax nodes structs instead of classes (#14122)
* [Experiment] Make Syntax nodes structs instead of classes

* [Experiment] Add Hashable conformance to concrete types

* Fix pep8 violation

* Remove AnySyntax, explicitly specialize SyntaxCollection nodes

* Refine the comment for SyntaxCollection nodes
2018-01-24 23:17:25 -05:00
Harlan
a5098e6b69 Generate libSyntax API (#10926)
* Generate libSyntax API

This patch removes the hand-rolled libSyntax API and replaces it with an
API that's entirely automatically generated. This means the API is
guaranteed to be internally stylistically and functionally consistent.
2017-07-25 18:19:58 -07:00