Commit Graph

85 Commits

Author SHA1 Message Date
Alex Hoppen
8177868000 Merge pull request #18673 from ahoppen/swift-syntax-xcode
[swiftSyntax] Fix issue where swiftc was not found when swiftSyntax is build via Xcode
2018-08-15 11:09:17 -07:00
Alex Hoppen
353473327a [swiftSyntax] Fix issue where swiftc was not found when swiftSyntax is build via Xcode 2018-08-14 17:16:01 -07:00
Alex Hoppen
7f8e46c7e9 [swiftSyntax] Make AbsolutePosition a value type
AbsolutePosition had value semantics anyway, the only reason it was a
reference type was so that we can use it in AtomicCache. But that can be
worked around by boxing it into a reference type.
2018-08-14 11:51:05 -07:00
Alex Hoppen
4369b36f21 Merge pull request #18497 from ahoppen/bytetree-infrastructure
[libSyntax] Add a binary serialization format for syntax trees
2018-08-13 15:41:30 -07:00
Saleem Abdulrasool
a4c604ff44 SwiftSyntax: some basic changes needed for Linux support
This adds a couple of changes to support building SwiftSyntax without an ObjC
runtime as well as swift-corelibs-foundation instead of the ObjC Foundation
implemetation.  This is needed to support building SwiftSyntax on Linux.
2018-08-13 08:48:58 -07:00
Alex Hoppen
139ba0313a [SwiftSyntax] Add a deserializer for the ByteTree format 2018-08-10 10:13:00 -07:00
Alex Hoppen
e4eb76fa0c [swiftSyntax] Add classifications for comments 2018-08-04 09:05:13 -07:00
Alex Hoppen
285b337cf5 Merge pull request #18424 from ahoppen/incremental-classification
[swiftSyntax] Incremental syntax classification
2018-08-03 11:09:28 -07:00
Alex Hoppen
56bf9a3469 [SwiftSyntax] Refactor AbsolutePosition
AbsolutePosition being a mutable reference type easily leads to bugs
where an AbsolutePosition is modified. Making it immutable eliminates
this issue. Furthermore, the introduction of SourceLength should allow
easier manipulation of AbsolutePositions on the client side.

We still cannot make AbsolutePosition a value type since it is used
inside AtomicCache, but the immutability gives the same safety.
2018-08-01 11:55:35 -07:00
Alex Hoppen
bffa15ba63 [SwiftSyntax] Don't reclassify nodes that haven't changed since last transfer 2018-07-31 15:41:07 -07:00
Alex Hoppen
49e9f824bf [SwiftSyntax] Record the nodes that have been reused during an incremental transfer
This way we will be able to avoid reclassifying these nodes for syntax
highlighting since we know they haven't changed.
2018-07-31 15:41:07 -07:00
Alex Hoppen
179940b65b [swiftSyntax] Add test cases for the SyntaxClassifier 2018-07-30 14:55:54 -07:00
Alex Hoppen
775beece65 [libSyntax] Add a swift token classifier for syntax highlighting 2018-07-30 14:54:43 -07:00
Alex Hoppen
478518fcf7 [swiftSyntax] Add type annotations to speed up compile time 2018-07-26 20:46:58 -07:00
Alex Hoppen
8c8f4eb1df [libSyntax] Make RawSyntax a struct
SourcePresence and ID are already shared between the two node kinds and
the node's length will soon be cached in RawSyntax as well. By making it
a struct, we will be able to compute the node's length when it is being
constructed in the initialiser.
2018-07-26 20:46:58 -07:00
Alex Hoppen
d926b74836 [incrParse] Add test cases to test the incremental syntax tree transfer 2018-07-24 16:32:23 -07:00
Alex Hoppen
8bab276d64 [libSyntax] Add incremental syntax tree deserialization to SwiftSyntax 2018-07-24 16:32:23 -07:00
Xi Ge
8f687714a2 SwiftSyntax: set up a test executable that can access SwiftSyntax APIs.
This will serve as the same functionality as swift-ide-test, but for
Swift syntax clients.
2018-07-19 18:18:30 -07:00
Xi Ge
e7b3db38dc Merge pull request #16350 from nkcsgexi/swift-syntax-absolute-pos-file
SwiftSyntax: Allow absolute position access for dangling nodes.
2018-05-03 13:49:57 -07:00
Xi Ge
cbf840fad4 SwiftSyntax: Allow absolute position access for dangling nodes.
Since absolute position is defined by accumulating proceeding nodes,
we should allow its access for nodes without SourceFileSyntax as root.
2018-05-03 12:13:36 -07:00
Harlan
405e34e91c Add descriptions for SwiftSyntax errors (#16339) 2018-05-03 14:40:14 -04:00
Harlan
9323d08b34 [SwiftSyntax] Add accessors for source locations and test diagnostic emission (#16141)
* [SwiftSyntax] Add accessors for source locations and test diagnostic emission

* Add tests for endLocation

* Pre-emptively copy AbsolutePosition to avoid mutating it twice
2018-04-26 16:17:07 +02:00
Harlan Haskins
0f5ac8d57a Actually add offsets in add(columns:) and add(lines:size:) 2018-04-24 16:41:19 -04:00
Harlan Haskins
6b29e2dd97 Re-add AbsolutePosition.swift 2018-04-24 16:15:55 -04:00
Harlan Haskins
572a144d2d Rename byteOffset to utf8Offset and remove utf16 2018-04-24 16:14:37 -04:00
Harlan Haskins
5d7549c1e0 Monomorphize AbsolutePosition.copy() 2018-04-24 14:11:02 -04:00
Harlan Haskins
76d8331a99 Un-rename property 2018-04-24 11:50:31 -04:00
Harlan Haskins
6bc087374c Clarify comment 2018-04-24 11:49:24 -04:00
Harlan Haskins
6189e6f1e9 Simplify AbsolutePosition offset calculation and support columns 2018-04-24 11:42:24 -04:00
Harlan
9e2e97a879 Update SwiftSyntax README with example (#15548)
* Update SwiftSyntax README with example

* Add link and Xcode instructions to README
2018-03-29 16:28:49 -04:00
Harlan
bdfa6cd4d7 [SwiftSyntax] Add SyntaxRewriter.visitAny(_:) (#15212)
* [SwiftSyntax] Add SyntaxRewriter.visitAny(_:)

This function, when overridden, allows Syntax rewriters to perform custom dynamic visitation behavior. If a user wanted to, say, store a series of transformations accessible by metatype, they can override visitAny and do their own runtime dispatch.

If a non-nil result is returned from visitAny, the original specialized visitors are skipped.
2018-03-27 10:55:31 -04:00
Xi Ge
de34be29b2 SwiftSyntax: bridging absolute location with diagnostics location. (#15434)
We have two similar objects for source location. AbsoluteLocation
calculates the offset of a syntax node on the fly. SourceLocation is
designed to serialize a Swift syntax diagnostics to the driver. The only
difference is AbsoluteLocation doesn't contain source file name however
SourceLocation does. This patch bridges them by making AbsoluteLocation
a private member of SourceLocation. We also expect Swift syntax to
be file-name agnostic. The clients should keep track of the file name
when emitting diagnostics.
2018-03-23 15:36:22 -07:00
Xi Ge
123ccc7602 SwiftSyntax: add an API to check whether a syntax node has underlying source. (#15389) 2018-03-20 18:16:54 -07:00
Denis Morozov
2866f0e0a6 [SwiftSyntax] Add replace method to SyntaxCollections (#15331)
* [SwiftSyntax] Add replace method SyntaxCollections

* Change replaceSubrange method call to subscript setter call

* [SwiftSyntax] Add test for SyntaxCollections

* Fix mistakes in SyntaxCollections tests

* Use syntax's raw value instead of syntax itself in replacing method

* Update SyntaxCollections tests
2018-03-20 14:58:16 -04:00
Xi Ge
20bc656261 SwiftSyntax: make absolute position calculation independent of specific encoding. NFC (#15352) 2018-03-19 16:33:05 -07:00
swift-ci
7118b180ab Merge pull request #15288 from nkcsgexi/utf8-view-syntax 2018-03-15 19:27:45 -07:00
Xi Ge
4c1be6aabd SwiftSyntax: avoid creating c-string when accumulating text. NFC 2018-03-15 18:16:22 -07:00
Xi Ge
1c9f1c48ed SwiftSyntax: allow any Syntax nodes to access their leading/trailing trivia. (#15278)
Although libSyntax is designed in a way that trivia is attached to
tokens, we shouldn't restrict clients to access trivia only from a token.
An example can be doc-comment, which conceptually attaches to a declaration rather
than the start token of a declaration, like at-attributes.
2018-03-15 15:31:08 -07:00
Xi Ge
af868778b6 SwiftSyntax: add an API to teach Trivia to calculate byte size. (#15251)
This missing piece will allow clients to customize the size of
SyntaxNode better.
2018-03-14 17:14:52 -07:00
Rintaro Ishizaki
f23edf0c4b [SwiftSyntax] Align implementation of SyntaxBuilders to C++ API (#15232)
Use 'nil' for missing *optional* children.
2018-03-15 01:44:36 +09:00
Rintaro Ishizaki
ea5f93807f [Syntax] Add 'unknown' token to Token.py 2018-03-14 20:38:48 +09:00
Xi Ge
ee36dbeda3 [WIP] SwiftSyntax: Implement APIs for Syntax nodes to calculate absolute positions. (#15097)
Syntax nodes are designed as reusable blocks to construct Swift source
code. For this reason, we don't track absolute position in each node;
instead, the absolute position should be calculated on the fly when
needed. We recently found absolute positions are useful to bridge with
sourcekitd, which typically speaks in the language of line, column and
offset. Therefore, this patch tries to add a computed
property on SyntaxNode to get its absolute position.

To compute the absolute position of a SyntaxNode from scratch requires tree traversal.
However, getting the absolute position from these added APIs doesn't necessarily
mean we'll traverse since SyntaxData will actively cache the computed position.
Also, since we recursively compute the absolute position, all the position caches
for a SyntaxNode's previous siblings and ancestors will be populated as well during
the calculation of this SyntaxNode.
2018-03-12 15:42:46 -07:00
Denis Morozov
6608176e13 Use RawSyntax presence state properties in SwiftSyntax 2018-03-12 15:35:29 -07:00
Denis Morozov
568ae2deda Improve comments in Syntax.swift 2018-03-11 11:46:51 -07:00
Harlan
37a6f4c6ec [SwiftSyntax] Make traits conform to Syntax (#15112) 2018-03-10 09:39:35 -05:00
Harlan
e41a42b060 [SwiftSyntax] Ensure SyntaxRewriter respects nil children when rewriting (#15052) 2018-03-08 00:37:41 -05:00
Xi Ge
e61c8958fd SwiftSyntax: simply trivia implementation on the Swift side. 2018-03-07 16:19:09 -08:00
Harlan
d3f6b8743d [SwiftSyntax] Publicize DiagnosticEngine.addConsumer and add hasErrors property (#14996)
* [SwiftSyntax] Publicize DiagnosticEngine.addConsumer and add hasErrors property

* [Syntax] Make DiagnosticEngine.hasErrors public
2018-03-06 00:40:24 -05:00
Harlan
2a3d4cb598 Initial infrastructure for documenting SwiftSyntax API (#14701) 2018-02-26 13:43:11 -05: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