Commit Graph

136 Commits

Author SHA1 Message Date
Slava Pestov
93c80da77c Parse: __shared and __owned should be contextual keywords
This was a source compatibility regression, someone actually had
an identifier named __shared.
2017-10-24 20:45:50 -07:00
Xi Ge
34e2aec662 Parser: use parser to generate a refined token stream to help syntax coloring. (#11809)
This patch allows Parser to generate a refined token stream to satisfy tooling's need. For syntax coloring, token stream from lexer is insufficient because (1) we have contextual keywords like get and set; (2) we may allow keywords to be used as argument labels and names; and (3) we need to split tokens like "==<". In this patch, these refinements are directly fulfilled through parsing without additional heuristics. The refined token vector is optionally saved in SourceFile instance.
2017-09-08 10:28:19 -07:00
Robert Widmann
b77f2c147c Parse Shared
Add parser support for __shared and __owned as type attributes.  Also, extend parser diagnostics and tests to account for the new type attributes.
2017-07-23 21:47:25 -07:00
John Holdsworth
981e706fd9 An implementation for 0168-multi-line-string-literals.md (#8813)
This adds support for SE-0168, multi-line string literals.

Extend the lexer to recognize the new literals. Test cases added.

There are still areas for future diagnostic improvement, such as fixits and notes as to why a multi-line string literal will be malformed. Multi-line literals are explicitly forbidden inside of string interpolation, though this may be relaxed in the future.
2017-04-25 18:13:03 -07:00
David Farler
7ee42994c8 Start the Syntax library and optional full token lexing
Add an option to the lexer to go back and get a list of "full"
tokens, which include their leading and trailing trivia, which
we can index into from SourceLocs in the current AST.

This starts the Syntax sublibrary, which will support structured
editing APIs. Some skeleton support and basic implementations are
in place for types and generics in the grammar. Yes, it's slightly
redundant with what we have right now. lib/AST conflates syntax
and semantics in the same place(s); this is a first step in changing
that to separate the two concepts for clarity and also to get closer
to incremental parsing and type-checking. The goal is to eventually
extract all of the syntactic information from lib/AST and change that
to be more of a semantic/symbolic model.

Stub out a Semantics manager. This ought to eventually be used as a hub
for encapsulating lazily computed semantic information for syntax nodes.
For the time being, it can serve as a temporary place for mapping from
Syntax nodes to semantically full lib/AST nodes.

This is still in a molten state - don't get too close, wear appropriate
proximity suits, etc.
2017-02-17 12:57:04 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
9d0b2abfc2 [gardening] Normalize end-of-namespace comments 2016-12-17 22:29:07 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
David Farler
f450f0ccdf Revert "Preserve whitespace and comments during lexing as Trivia"
This reverts commit d6e2b58382.
2016-11-18 13:23:31 -08:00
David Farler
d6e2b58382 Preserve whitespace and comments during lexing as Trivia
Store leading a trailing "trivia" around a token, such as whitespace,
comments, doc comments, and escaping backticks. These are syntactically
important for preserving formatting when printing ASTs but don't
semantically affect the program.

Tokens take all trailing trivia up to, but not including, the next
newline. This is important to maintain checks that statements without
semicolon separators start on a new line, among other things.

Trivia are now data attached to the ends of tokens, not tokens
themselves.

Create a new Syntax sublibrary for upcoming immutable, persistent,
thread-safe ASTs, which will contain only the syntactic information
about source structure, as well as for generating new source code, and
structural editing. Proactively move swift::Token into there.

Since this patch is getting a bit large, a token fuzzer which checks
for round-trip equivlence with the workflow:

fuzzer => token stream => file1
  => Lexer => token stream => file 2 => diff(file1, file2)

Will arrive in a subsequent commit.

This patch does not change the grammar.
2016-11-15 16:11:57 -08:00
Jordan Rose
043c2e0c71 [Parse] Parse SE-0117's contextual 'open' keyword. (#3875)
This will allow us to start writing 'open' in downstream projects
while John finishes the implementation. (This patch is extracted from
his full WIP.)
2016-07-29 20:15:18 -07:00
Chris Lattner
d522cd4270 Centralize the parsing logic for #identifiers and make it more similar to
the identifier parsing logic.
2016-02-03 22:37:28 -08:00
Denis Vnukov
3205d42144 Added getter for full (raw) text of the token 2016-01-27 13:43:40 -08:00
Doug Gregor
dccf3155f1 SE-0022: Implement parsing, AST, and semantic analysis for #selector. 2016-01-26 21:12:04 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Doug Gregor
c8dd8d0661 Implement SE-0001: Allow (most) keywords as argument labels.
Allow all keywords except for parameter introducers (var/let/inout) to
be argument labels when declaring or calling a
function/initializer/subscript, e.g., this

  func touchesMatching(phase: NSTouchPhase, `in` view: NSView?) -> Set<NSTouch>

can now be expressed as

  func touchesMatching(phase: NSTouchPhase, in view: NSView?) -> Set<NSTouch>

and the call goes from

  event.touchesMatching(phase, `in`: view)

to

  event.touchesMatching(phase, in: view)

Fixes [SR-344](https://bugs.swift.org/browse/SR-344) /
rdar://problem/22415674.
2015-12-22 16:18:28 -08:00
Xi Ge
d569159ffb [Token] Trim surrounding whitespace when querying the ranges of tokens' associated comments.
Need this for rdar://21607719

Swift SVN r31880
2015-09-11 02:14:30 +00:00
Doug Gregor
c02cd1a424 Factor omit-needless-words logic out of the Clang importer.
Sink the actual logic for omitting needless words way down into
Basic, so we can re-use it elsewhere. Tie the Clang importer into that
logic, mapping Clang types down to strings appropriately. NFC

Swift SVN r31233
2015-08-13 23:39:29 +00:00
Doug Gregor
f76bc108fc Don't omit words down to "get", "set", or a Swift keyword.
Swift SVN r31189
2015-08-12 21:24:42 +00:00
Jordan Rose
f5b1efb354 Move client-affecting configuration options into a generated Config.h.
This way they can be used from other projects, like LLDB. The downside
is we now have to make sure the header is included consistently in all
the places we care about, but I think in practice that won't be a problem,
especially not with tests.

rdar://problem/22240127

Swift SVN r31173
2015-08-12 17:50:13 +00:00
Chris Willmore
5ea5ce0e70 Source range of backtick-escaped identifier token should include backticks.
<rdar://problem/21392294> Swift 2 Migration failures, redux

Swift SVN r30907
2015-08-01 05:07:32 +00:00
Chris Lattner
0001dc27bb remove support for the experiemental "character literals" feature.
Swift SVN r30509
2015-07-22 22:35:19 +00:00
Joe Groff
66ba6827bf Parse the 'indirect' attribute on enums and cases.
Swift SVN r29777
2015-06-28 21:52:59 +00:00
Devin Coughlin
8b5f6fec60 Rename '#os' to '#available'
The API review list found it confusing that if #os() and #if os() looked so similar, so
change the availability checking query to be spelled #available:

if #available(iOS >= 9.0, *) {
  ...
}

Swift SVN r26995
2015-04-04 23:33:13 +00:00
Chris Lattner
a0d02cdcdd Several minor changes:
- Strength reduce isAtStartOfBindingName() to just check for 
   identifier or _ and inline into its two callers.
 - Rename Token::isIdentifierOrNone to isIdentifierOrUnderscore.
 - Teach InVarOrLetPattern about matching patterns, so that the
   parser knows when it is parsing an expression as a matching
   pattern but is not yet inside a let/var pattern.
 - Use newfound knowledge of matching patterns to refine handling
   of unexpected let/var when parsing an expression, but not in a
   pattern context, slightly improving QoI in invalid cases.



Swift SVN r26172
2015-03-15 23:36:05 +00:00
Chris Lattner
65b432a495 split tok::oper_postfix into two token kinds, one that indicates that it was spaced
and one that indicates that it was unspaced.  NFC, needed by my next patch.


Swift SVN r25225
2015-02-12 05:19:18 +00:00
Dmitri Hrybenko
d225e496e6 Fix warnings about && nested in ||
Swift SVN r22326
2014-09-28 01:55:18 +00:00
Devin Coughlin
0d7996f4ee Add parsing of availability query expressions (#os(...))
This patch adds a new 'pound_os' token, a new case for it in parseExprPostfix, and parsing of platform version constraints, e.g., OSX >= 10.10. 

It also adds enough type checking and SILGen to get the parsing tests to run without triggering "Unimplemented" assertions.


Swift SVN r21865
2014-09-11 02:59:05 +00:00
Chris Lattner
8991456ff2 Switch infix/postfix/prefix to be declaration modifiers instead of attributes,
eliminating the @'s from them when used on func's.  This is progress towards
<rdar://problem/17527000> change operator declarations from "operator prefix" to "prefix operator" & make operator a keyword

This also consolidates rejection of custom operator definitions into one
place and makes it consistent, and adds postfix "?" to the list of rejected
operators.

This also changes the demangler to demangle weak/inout/postfix and related things
without the @.



Swift SVN r19929
2014-07-14 15:51:49 +00:00
Chris Lattner
8078fecd18 fix <rdar://problem/17625253> Remove the 'strong' context-sensitive keyword
Swift SVN r19819
2014-07-10 19:46:22 +00:00
Chris Lattner
5b49d59c57 Remove the @ from @final and @lazy, the last major piece of
rdar://17168115.

Also, reinstate the ARM driver change and testcase that I removed
in my last patch.


Swift SVN r19790
2014-07-10 06:23:27 +00:00
Chris Lattner
fe95f81397 introduce a new 'DeclModifier' flag on attributes, which mark that the
attribute is a "modifier" of a decl, not an "attribute" and thus shouldn't
be spelt with an @ sign.  Teach the parser to parse "@foo" but reject it with
a nice diagnostic and a fixit if "foo" is a decl modifier.

Move 'dynamic' over to this (since it simplifies some code), and switch the
@optional and @required attributes to be declmodifiers (eliminating their @'s).



Swift SVN r19787
2014-07-10 05:49:10 +00:00
Joe Groff
9ddad1d718 Sema: Basic parsing and checking for 'dynamic'.
Parse 'dynamic' as a contextual keyword, and check that it's applied only to ObjC-compatible members of classes. We don't handle inheritance of the attribute yet.

Swift SVN r19781
2014-07-10 05:05:29 +00:00
Jordan Rose
9320f1a7c5 Claim 'private', 'internal', and 'public' as full keywords.
Swift SVN r19756
2014-07-09 22:56:28 +00:00
Chris Lattner
02999cac51 Reinstate the @ on the @objc attribute. This is largely a revert of r19555 with a few tweaks.
Swift SVN r19706
2014-07-08 21:50:34 +00:00
Jordan Rose
3f59d6b9ee Drop the '@' from access control modifiers.
Test and stdlib changes to follow.

Swift SVN r19671
2014-07-08 02:16:59 +00:00
Chris Lattner
7a56499d61 Start making @objc not start with an @ sign:
- Change the parser to accept "objc" without an @ sign as a contextual
   keyword, including the dance to handle the general parenthesized case.
 - Update all comments to refer to "objc" instead of "@objc".
 - Update all diagnostics accordingly.
 - Update all tests that fail due to the diagnostics change.
 - Switch the stdlib to use the new syntax.

This does not switch all tests to use the new syntax, nor does it warn about
the old syntax yet.  That will be forthcoming.  Also, this needs a bit of 
refactoring, which will be coming up.



Swift SVN r19555
2014-07-04 05:57:57 +00:00
Chris Lattner
cb97c11214 Fix a super-obscure bug where we could attach the doc comment attached to a token when
backtracking, because we didn't restore the lexer state to before the comment, preventing
it from being attached to the token that followed it after backtracking was restored.

This is super obscure right now, but causes two tests to fail with my forthcoming patch,
lets nip this in the bud.



Swift SVN r19553
2014-07-04 05:54:26 +00:00
Adrian Prantl
400f1774e9 Add support for a #line directive.
This patch extends the syntax with a new #line directive that is inspired
by the homonymous CPP directive. It can be specified in all locations a #if
is legal (Stmt, Decl).

Semantics
---------

#line 42 "file.swift"
This makes diagnostics and debug information behave as if the subsequent
lines came from file.swift+42.

#line // without arguments
This switches back to the main source file and the switches back to the
normal line numbering. Any previous #line directives will result in gaps
in the main file.

Rationale
---------

LLDB and the REPL need this for making expressions that are entered into
the expression evaluator or REPL debugable. For more info see
<rdar://problem/17441710> Need #line directive or something similar so we can enhance the debugging of expressions and REPL

Also, I believe the stdlib would benefit from this and it would allow us
to get rid of the line-directive wrapper script.

Swift SVN r19384
2014-06-30 23:50:11 +00:00
Dmitri Hrybenko
a01b72ea2f Comment parsing: increase the maximum size of documentation comment
Turns out 64 Kib is closer than it seems -- I hit this limit with an
autogenerated source file where a part of it was commented out, and the
compiler crashed in an obscure way.


Swift SVN r19339
2014-06-30 12:59:43 +00:00
Joe Groff
88f2632a44 Allow trailing closures with a line break before '{'.
Swift SVN r19322
2014-06-28 05:12:48 +00:00
Dave Abrahams
b7a8fc7d4c Revert "Allow trailing closures with a line break before '{'."
This reverts r19315, which broke my build:

-- Testing: 1 tests, 1 threads --
FAIL: Swift :: Interpreter/arrays.swift (1 of 1)
******************** TEST 'Swift :: Interpreter/arrays.swift' FAILED ********************
Script:
--
rm -rf /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp && mkdir -p /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp && xcrun -sdk macosx10.10 /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/bin/swift -target x86_64-apple-macosx10.9 -resource-dir '/Users/dave/build/swift/Ninja-RelWithDebInfo/swift/lib/swift' -module-cache-path /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/swift-module-cache -module-cache-path /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp/clang-module-cache /Users/dave/src/s/swift/test/Interpreter/arrays.swift -o /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp/a.out &&  /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp/a.out | FileCheck /Users/dave/src/s/swift/test/Interpreter/arrays.swift
--
Exit Code: 1

Command Output (stderr):
--
/Users/dave/src/s/swift/test/Interpreter/arrays.swift:54:1: error: invalid use of '()' to call a value of non-function type '()'
println()
^

Swift SVN r19317
2014-06-28 01:51:45 +00:00
Joe Groff
0c9fc15ae1 Allow trailing closures with a line break before '{'.
Swift SVN r19315
2014-06-28 00:36:45 +00:00
Chris Lattner
2dc1df52d1 Implement <rdar://problem/16954464> Cannot make a strong IBOutlet
This adds support for the "strong" ownership modifier, and specifically 
make it override the "implicit weak" behavior of @IBOutlet.



Swift SVN r18737
2014-06-08 20:49:21 +00:00
Chris Lattner
bca1634958 fix rdar://16889886 - Assert when trying to weak capture a property of self in a lazy closure
also improve error recovery.


Swift SVN r18008
2014-05-13 16:45:15 +00:00
Jordan Rose
57e771ca38 [Parse] Make Token::isAny and Token::isNotAny variadic.
No functionality change.

Swift SVN r17519
2014-05-06 02:06:02 +00:00
Chris Lattner
0ceb7ab023 introduce new Token::isAny and Token::isNotAny methods which are
helper predicates to see if the token is any of a set.


Swift SVN r17498
2014-05-05 23:52:49 +00:00
Chris Lattner
2427e36ff8 Introduce a new "convenience" context sensitive keyword, which can only be
used on init decls, with the same semantics as "-> Self".  Switch the ast
printer, and fixits to use it.

As driveby's, simplify verification of contextual keywords in declparsing,
and rename parseConstructor/Destructor to parseInit/Deinit.


Swift SVN r17356
2014-05-04 04:02:32 +00:00
Chris Lattner
b3133da827 Parse weak/unowned/unowned(safe)/unowned(unsafe) as context sensitive keywords.
This is part of <rdar://problem/16782966> make weak and unowned be context sensitive keywords

The part still missing is where we ban the attribute with a fixit to use the
non-attribute syntax.



Swift SVN r17235
2014-05-02 06:21:44 +00:00
Chris Lattner
0f6c01a6e8 factor a test for decl contextual keywords out into a helper function. NFC.
Swift SVN r17227
2014-05-02 04:33:35 +00:00