Commit Graph

96 Commits

Author SHA1 Message Date
Rintaro Ishizaki 0780c529c4 [Syntax] Unify RawSyntax and RawTokenSyntax using union and TrailingObjects
It better matches with SwiftSyntax model.

Using TrailingObjects reduces the number of heap allocation which
gains 18% performance improvement.
2018-01-18 14:49:46 +09:00
Xi Ge 71af76a87e libSyntax: optionally emit diagnostics for unknown expressions and declarations. (#13973)
With more syntax nodes being specialized, we'd like this
straight-forward way to pinpoint unknown entities. This diagnostics
is only issued in -emit-syntax frontend action and swift-syntax-test
invocation.
2018-01-16 16:14:57 -08:00
Xi Ge 031488bada libSyntax: several enhancements on source location bridging. (#13956)
libSyntax nodes don't maintain absolute source location on each
individual node. Instead, the absolute locations are calculated on
demand with a given root by accumulating the length of all the other
nodes before the target node. This bridging is important for issuing
diagnostics from libSyntax entities.

With the observation that our current implementation of the source
location calculation has multiple bugs, this patch re-implemented this
bridging by using the newly-added syntax visitor. Also, we moved the function
from RawSyntax to Syntax for better visibility.

To test this source location calculation, we added a new action in
swift-syntax-test. This action parses a given file as a
SourceFileSyntax, calculates the absolute location of the
EOF token in the SourceFileSyntax, and dump the buffer from the start
of the input file to the absolute location of the EOF. Finally, we compare
the dump with the original input to ensure they are identical.
2018-01-15 16:39:17 -08: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 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 01f42c89d3 Merge pull request #13631 from omochi/lex-escape-backtick
[Parse] Lexer build backtick trivia around espaced identifier token
2017-12-29 12:36:00 +09:00
Yurii Samsoniuk d5771cea6b Added extension specialization to libSyntax 2017-12-29 01:27:26 +09:00
omochimetaru 36adae8ce8 [Syntax] add test for escaped identifier 2017-12-29 00:22:38 +09:00
Rintaro Ishizaki 002cfe5136 [Syntax] Add test cases for fixed round trip failures. 2017-12-27 17:49:33 +09: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 1dc6a3f775 [Syntax] Parse "for-in statement" node 2017-12-23 12:20:34 +09:00
Rintaro Ishizaki 1e83ad2cbf [Syntax] Parse "if statement" and "guard statement" nodes 2017-12-23 12:20:34 +09:00
Rintaro Ishizaki d01f5d1da3 [Syntax] Parse "statement condition" nodes 2017-12-23 12:20:34 +09:00
Rintaro Ishizaki cd5fdff9bb [Syntax] Parse "repeat-while statement" syntax node 2017-12-21 17:16:26 +09:00
Rintaro Ishizaki 8830fdda34 [Syntax] Parse "do statement" syntax node 2017-12-21 17:16:03 +09:00
Rintaro Ishizaki f102636d85 [Syntax] Parse basic statement nodes
* ReturnStmt -> 'return' expr?
* BreakStmt -> 'break' identifier?
* ContinueStmt -> 'continue' identifier?
* FallthroughStmt -> 'fallthrough'
* ThrowStmt -> 'throw' expr
* DeferStmt -> 'defer' code-block
2017-12-21 13:30:55 +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
Rintaro Ishizaki 87ea7bd9d3 [Syntax] Add test case for unresolved matching patterns
Patterns those are parsed as ExpressionPattern at first, then resolved
to actual patterns:

* OptionalPattern -> pattern '?'
* AsTypePattern -> pattern 'as' type
* EnumCasePattern -> type? '.' identifier tuple-pattern
2017-12-20 20:24:34 +09:00
Rintaro Ishizaki 93a74fea44 [Syntax] Parse "is type pattern" syntax node 2017-12-20 19:59:22 +09: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 bc768b6e0e [Syntax] Parse "value binding pattern" nodes 2017-12-20 18:22:08 +09:00
Rintaro Ishizaki c379f5c232 [Syntax] Parse wildcard pattern node 2017-12-20 17:33:30 +09:00
Rintaro Ishizaki a1340fd9a2 [Syntax] Parse tuple pattern node 2017-12-20 17:32:30 +09:00
Xi Ge e0d167f1dd libSyntax: create syntax nodes for variable declarations.
Variable declarations are declarations led by either 'var' or 'let'. It
can contain multiple pattern bindings as children.

For patterns, this patch only creates syntax nodes for simple identifier
patterns, e.g. 'a = 3'. The rest of the pattern kinds are still left
unknown (UnknownPattern).
2017-12-19 12:25:51 -08:00
Xi Ge fe1a4ca0d2 libSyntax: create libSyntax node for var decl accessors. 2017-12-18 15:16:14 -08:00
Rintaro Ishizaki 8e967adc0e [Syntax] Parse attributed type node 2017-12-18 08:28:24 -08:00
Faiçal Tchirou 5e41098851 libSyntax: specialize class declaration syntax node. (#13485) 2017-12-16 11:36:58 -08:00
Xi Ge df7db884cf libSyntax: create syntax nodes for IfConfigDecl. 2017-12-15 13:36:47 -08:00
Rintaro Ishizaki 53b2e0fe14 [Syntax] Parse composition type node 2017-12-15 10:52:10 -08:00
Xi Ge b4b638651d libSyntax: create syntax node for typealias declarations. (#13450) 2017-12-14 17:44:54 -08:00
Xi Ge a6b3559a8a libSyntax: specialize import declaration. (#13437) 2017-12-14 12:27:52 -08:00
Rintaro Ishizaki e616b2ad37 [Syntax] Use initializer clause syntax node for function parameter (#13430) 2017-12-14 08:12:10 -08:00
Rintaro Ishizaki fc5f31c6d9 [Syntax] Decompose TupleType when it turns out to be a part of FunctionType 2017-12-14 14:55:27 +09:00
Rintaro Ishizaki ef29650acd [Syntax] Parse: add support for TupleType and FunctionType
For now using SyntaxParsingContext.
2017-12-14 14:55:27 +09: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
Xi Ge fda8dfcfd3 libSyntax: specialize protocol declaration syntax. 2017-12-11 16:17:13 -08:00
Xi Ge 8256b1f88f libSyntax: function declaration syntax should accept operators as name. 2017-12-08 16:30:45 -08:00
Xi Ge 7901583833 libSyntax: create parameter list for function signatures without parameters.
If we don't create the empty parameter list, a 0-parameter function declaration
will not be well-formed.
2017-12-08 15:59:59 -08:00
Xi Ge f870087805 libSyntax: specialize function declaration syntax node. 2017-12-07 17:28:19 -08:00
Xi Ge ec5232a359 libSyntax: support function signature. 2017-12-07 14:38:44 -08:00