Commit Graph

78 Commits

Author SHA1 Message Date
Xi Ge
1b5306158d [test] libSyntax: add a test to ensure the client side decodes syntax tree properly. NFC (#14203)
We need to expose a SwiftSyntax API to encode a source file into Json
format.
2018-01-26 16:53:20 -08:00
Harlan
95fc7d335e Change vars in SwiftSyntax nodes to lets (#14173) 2018-01-26 15:19:05 -08:00
Xi Ge
d13f83df14 SwiftSyntax: Factor out an API to decode serialized SourceFileSyntax. NFC (#14164)
Since our recent integration with SourceKit, clients may get a SourceFileSyntax
in a serialized form from SourceKit response.  We need an API in the
SwiftSyntax framework to decode this form. This'll be a more common
pattern to get a Swift side syntax tree than invoking swiftc internally.
2018-01-25 13:40:42 -08: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
Rintaro Ishizaki
9c4d6f4893 Revert "[SwiftSyntax] Add debug print when the JSONDecoder fails to decode JSON (#14056)" (#14101)
This reverts commit 840166c3ea.
2018-01-24 10:01:43 +09:00
Rintaro Ishizaki
840166c3ea [SwiftSyntax] Add debug print when the JSONDecoder fails to decode JSON (#14056)
from the compiler's '-emit-syntax'.

Investigating: rdar://problem/36379512
2018-01-22 23:44:18 +09:00
Slava Pestov
162187c4fe Revert "SwiftSyntax: Fix resilient build"
This reverts commit bbb21c84ca.
2018-01-17 21:02:09 -08:00
Xi Ge
b85f6d9c58 libSyntax: add a C++ side read-only syntax visitor to facilitate verification. NFC (#13882) 2018-01-11 16:17:44 -08:00
Xi Ge
d41eedcbf6 SwiftSyntax: Add a read-only syntax visitor. (#13681)
Based on the feedbacks from our early adopters, separating syntax tree analysis
with transformation is a common pattern. Thus, we introduce a read-only
syntax tree visitor to help the analysis phase. This visitor never alters the
content of a tree being visited, in contrast to SyntaxRewriter which always does.
2018-01-02 16:52:30 -08:00
Xi Ge
d847bf5ddd SwiftSyntax: make Syntax node Hashable. (#13679)
SwiftSyntax: make Syntax node Hashable.

This gives Syntax node a unique identifier and makes them friendly
to Set and Dictionary.
2018-01-02 14:19:26 -08:00
Harlan
9185ef5610 [Syntax] Add #selector and #keyPath tokens (#13615)
* [Syntax] Add #selector and #keyPath tokens

* [Syntax][test] Add #selector and #keyPath to syntax parsing tests

* [Syntax] Don't fatalError on an unknown token kind

* Fix test build error
2017-12-29 12:35:08 -05:00
omochimetaru
3a3e89ba0c [Syntax] add TriviaKind::CarriageReturnLineFeed 2017-12-20 20:50:40 +09:00
Rintaro Ishizaki
2c06060165 [Syntax] Add CarriageReturn trivia kind
To distinguish '\r' from '\n'.
2017-12-19 09:24:34 +09:00
Harlan
a0512cd48a re-enable SwiftSyntax tests (#13399) 2017-12-14 23:39:16 -05:00
Rintaro Ishizaki
ef29650acd [Syntax] Parse: add support for TupleType and FunctionType
For now using SyntaxParsingContext.
2017-12-14 14:55:27 +09:00
Slava Pestov
bbb21c84ca SwiftSyntax: Fix resilient build
Address-only types do not support multiple case labels yet.
2017-12-12 21:10:59 -08:00
Harlan
2cc756414b [SwiftSyntax] Swift Diagnostics API (#11511)
This patch provides an API and Serialization for clang-style diagnostics
from within Swift. Libraries can use this API to pop their own custom
diagnostics that can be serialized to JSON.
2017-12-12 15:55:22 -05:00
Rintaro Ishizaki
2b1e316cf6 [Syntax] Add parsing hashbang (shebang) as a trivia.
Added GarbageText trivia kind for any skipped text.
2017-12-08 12:07:00 +09:00
Xi Ge
fec040d95e libSyntax: support generic parameter clause. (#13286)
This patch also performs minor refactoring to align syntax parsing
context with the right scope. We start to support the generic clauses
because they are necessary pieces to construct struct or
function syntax node.
2017-12-05 19:34:55 -08:00
Rintaro Ishizaki
e7cfae0ba9 [libSyntax] Support parsing type-identifier 2017-11-29 09:57:59 +09:00
Robert Widmann
cd64938e6b Provide an explicit iterator for SyntaxCollection (#13112)
The default IndexingIterator for a custom collection is not suitable for
subclasses that specialize the element type the way libSyntax does.
Overriding it with a more specific iterator, even with something like
covariant overrides, would not work because it the iterator is generic
over its base collection, not its element type.

Provide a custom iterator parameterized by the element type instead.
2017-11-28 15:23:35 -05:00
Harlan
f552f55969 Update SwiftSyntax's expectations now that -emit-syntax is emitting a SourceFileSyntax (#12860) 2017-11-10 15:48:13 -08:00
Tony Allevato
1187890ca4 [SwiftSyntax] Fix SyntaxChildren iteration (#12319)
* [SwiftSyntax] Fix SyntaxChildren iteration

SyntaxChildren.Iterator stops the first time it sees a nil child;
since it traverses all indexes without considering presence, this
causes it to terminate iteration early if there is a missing child
in the list.

* [SwiftSyntax] Add tests for SyntaxChildren
2017-10-15 00:38:35 -04:00
David Ungar
f81136040e Use an autoreleasepool instead of explicitly closing the files. 2017-09-27 10:52:12 -07:00
David Ungar
f282babc6a Close files after invoking swiftc in SwiftSyntax tool 2017-09-25 09:21:16 -07:00
Kuba (Brecka) Mracek
d03a575279 Unify the capitalization across all user-visible error messages (#11599)
* Unify the capitalization across all user-visible error messages (fatal errors, assertion failures, precondition failures) produced by the runtime, standard library and the compiler.

* Update some more tests to the new expectations.
2017-08-29 12:16:04 -07:00
Harlan
cba8a865e2 Split RawSyntax.presence into multiple cases (#11526) 2017-08-19 07:43:42 -07:00
Harlan
ade67ca899 [Syntax] Swift libSyntax API (#11320)
* Create Swift libSyntax API

This patch is an initial implementation of the Swift libSyntax API. It
aims to provide all features of the C++ API but exposed to Swift.

It currently resides in SwiftExperimental and will likely exist in a
molten state for a while.

* Only build SwiftSyntax on macOS
2017-08-14 16:47:48 -07:00