Commit Graph

50 Commits

Author SHA1 Message Date
Alex Hoppen
8430eff670 [libSyntax] Add syntax coloring based on the syntax tree 2018-07-13 17:48:47 -07:00
Alex Hoppen
7bbb5fa87a [libSyntax] Fix parsing of key paths on specialised generics 2018-04-27 08:10:20 -07:00
Alex Hoppen
94b8a3545b [libSyntax] Fix parsing for KeyPath 2018-04-25 13:30:31 -07:00
Alex Hoppen
c52f4a8131 [libSyntax] Fix parsing of operators passed to higher order functions 2018-04-23 12:23:27 -07:00
Rintaro Ishizaki
338cedd6d5 [Syntax] Parse '#selector' expression syntax 2018-04-12 13:56:04 +09:00
Rintaro Ishizaki
93cd5bce15 [Syntax] Fix typo 2018-03-27 22:58:21 +09: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
bdebd8a210 SwiftSyntax: add WithTrailingCommanSyntax trait and fix inconsistent naming. NFC 2018-02-20 12:02:30 -08:00
Xi Ge
f814309f2e SwiftSyntax: Add ParenthesizedSyntax trait and mark various syntax nodes for conformances. NFC 2018-02-19 19:21:59 -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
Rintaro Ishizaki
1eedcb7682 [Syntax] Parse '->' in sequence expression 2018-02-06 15:06:00 +09:00
Rintaro Ishizaki
5dc6b78457 [Syntax] Parse generic specialize expression 2018-02-06 15:05:59 +09:00
Rintaro Ishizaki
9bf4c8af05 [Syntax] Allow tok::dollarident (e.g. $0) for IdentifierExpr 2018-01-23 19:15:06 +09:00
Rintaro Ishizaki
46d681c614 [Syntax] Allow 'self' and 'Self' keyword for IdentifierExpr 2018-01-23 19:15:06 +09:00
Rintaro Ishizaki
7f9578e5f3 [Syntax] Parse "dot self" expression nodes 2018-01-23 19:15:06 +09:00
Xi Ge
6cd5d0bf5e libSyntax: parse several magic identifier expressions.
They include #column, #file, #function and #dsohandle.
2018-01-10 18:02:02 -08:00
Xi Ge
7e4e7ff0bc libSyntax: parser object literal expressions.
This includes color, image and file literals.
2018-01-10 15:38:11 -08:00
Xi Ge
95f09d057e libSyntax: parse editor placeholder expression. (#13840) 2018-01-09 17:23:42 -08:00
Xi Ge
21f4564877 libSyntax: parse key path expressions. (#13813) 2018-01-08 20:54:53 -08:00
Xi Ge
1170a4ff01 libSyntax: parse InOut expression. (#13815) 2018-01-08 18:00:33 -08:00
Xi Ge
cb4bc9eb69 libSyntax: allow SyntaxCollection to specify acceptable element kinds. NFC
Segments list in interpolated string literal accepts two syntax kinds as
elements: StringSegment and ExpressionSegment. This patch generates
factory methods to reject other kinds.
2018-01-04 13:35:39 -08:00
Xi Ge
7476677bb2 libSyntax: create separate node kinds for quote (") and multiline quote (""").
This allows us to serialize the quote tokens without serializing their
underlying text.
2018-01-04 09:08:21 -08:00
Xi Ge
22ce6934bd libSyntax: parse string interpolation expression. (#13708)
A string interpolation expression is composed of { OpenQuote, Segments,
CloseQuote }. To represent OpenQuote, CloseQuote and StringSegment, we have to
introduce new token kinds correspondingly.
2018-01-03 20:41:34 -08:00
Rintaro Ishizaki
2855c9e693 [Syntax] Add support for compound name in expressions (#13630) 2018-01-02 10:53:41 -08:00
Rintaro Ishizaki
8d33f763a4 [Syntax] Parse "implicit member expression " and its postfixes
Unlike libAST, parse '.foo(a)' as:
  <call><implicit-member>.foo</implicit-member><args>a</args></call>
2017-12-25 18:52:41 +09:00
Rintaro Ishizaki
b46bb721c6 [Syntax] Parse "super" and its postfix expressions 2017-12-25 17:47:36 +09:00
Rintaro Ishizaki
5d65b2f510 [Syntax] Parse several suffix expression nodes
* FunctionCallExpr
* SubscriptExpr
* OptionalChainingExpr
* ForcedValueExpr
* PostfixUnaryExpr
2017-12-25 17:21:05 +09:00
Rintaro Ishizaki
8830fdda34 [Syntax] Parse "do statement" syntax node 2017-12-21 17:16:03 +09:00
Xi Ge
b4da5a3c31 libSyntax: use node choice for dictionary expression.
This allows us to support empty dictionary literal.
2017-12-20 18:23:23 -08:00
Xi Ge
21fc2fb92b libSyntax: use node choices for closure parameters.
This is to incorporate two styles of closure parameters: "a, b, c" or "(a:
T1, b: T2, c: T3)".
2017-12-20 18:23:23 -08:00
Rintaro Ishizaki
89d9993f59 [Syntax] Parse matching pattern syntax node
Added support for ExprPattern and UnresolvedPatternExpr.
2017-12-20 19:47:32 +09:00
Rintaro Ishizaki
53b2e0fe14 [Syntax] Parse composition type node 2017-12-15 10:52:10 -08:00
Xi Ge
796c51cb1f libSyntax: specialize closure expression. (#13421) 2017-12-13 18:25:44 -08:00
Xi Ge
9ddd60d4ef libSyntax: create syntax nodes for closure signature. (#13415)
This patch also refactors the structure of function signature node so
that closure signature can re-use parts of function signature. For
instance, we group arrow and return type to be "ReturnClause". And we
group parenthesized parameter list to be "ParamClause".

This structure of closure signature also calls for a good way to
represent either-or node in libSyntax APIs, since we've two ways to
specify parameters in closure: one is as regular function parameter and
the other is dot-separated simple names.
2017-12-13 16:48:24 -08:00
Xi Ge
9e8d0aea81 libSyntax: create syntax node for closure capture list. (#13408) 2017-12-12 20:14:04 -08:00
Xi Ge
2a39598b4f libSyntax: specialize try expression.
Optional try, forced try and regular try expressions are handled in
this syntax node.
2017-12-12 16:17:48 -08:00
Rintaro Ishizaki
8bbe4d20ef [libSyntax] Support TypeExpr (#13317)
Just for `Any` for now.
2017-12-07 11:40:05 -08:00
Xi Ge
5ace363dbc libSyntax: specialize As expression and Is expression. (#13179)
This patch also handles variants like "as!" and "as?".
2017-11-30 15:05:22 -08:00
Xi Ge
e560170a60 libSyntax: Parse member access expression. (#13119)
* libSyntax: Parse member access expression.

This patch uses createNodeInPlace from syntax parsing context API to
merge an expression with its suffix to create recursive nodes such as
member access expression.

Meanwhile, this patch breaks down a signed integer or float literal to a
prefix operator expression. This expression consists of two parts: an
operator and the following expression. This makes literals like "+1" or
"-1" no different from other prefix unary expressions such as "!true".
2017-11-28 16:29:50 -08:00
Xi Ge
036321546b libSyntax: Support tuple expression.
Tuple expression essentially has the same underlying structure as
function call arguments in libSyntax. However, we separate them as
different libSyntax kinds for better usability.

Different from AST, libSyntax currently allows single-child,
label-free tuple expressions (represented as ParenExpr in AST). This is
subject to change if we need to adopt the same differentiation in
libSyntax in the future.
2017-11-27 16:40:30 -08:00
Xi Ge
588ac6b3e8 libSyntax: add several elementary nodes. (#13085)
They are SequenceExpr, AssignmentExpr, and BinaryOperatorExpr.
2017-11-27 13:15:39 -08:00
Xi Ge
a4a01f9121 libSyntax: parse ternary expression.
Along with starting to support ternary expressions, this commit also
slightly changes SyntaxParsingContext APIs as follows:

1. Previously, makeNode() only supports node creation by using the nodes
from the underlying syntax token array; this commit allows it to use the nodes from
the pending syntax list as well.

2. This commit strictly limits that the pending syntax list should never
contain token syntax node.

3. The node kind test shouldn't include unknown kinds. They are noisy.
2017-11-14 23:29:23 -08:00
Xi Ge
3d5eb6e062 libSyntax: parse boolean literal expression. (#12908) 2017-11-13 21:03:42 -08:00
Xi Ge
ea76f585b9 libSyntax: parse DiscardAssignmentExpr and NilLiteralExpr. (#12872) 2017-11-11 11:24:34 -08:00
Xi Ge
a71a03986e libSyntax: Start parsing simple identifier expression. (#12862) 2017-11-10 15:26:37 -08:00
Xi Ge
0d9745f6eb libSyntax: teach parser to parse dictionary and array literals. (#12821)
This commit also adds ArrayExpr and DictionaryExpr to the libSyntax nodes
family. Also, it refactors the original parser code for these two
expressions to better fit to the design of SyntaxParsingContext.

This commit has also fixed two crashers.
2017-11-09 09:00:43 -08: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
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