Commit Graph

154 Commits

Author SHA1 Message Date
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
Nathan Hawes
d257f1dd36 [SyntaxColor] Restrict the keywords colored as identifiers to just those that can be used as argument labels. rdar://problem/29098176
Most keywords can be used as argument labels. When they are they shouldn't be
colored as a keyword. This patch fixes three issues with this:
-  keywords as local argument labels (where an external label was also present)
were still colored as keywords
- 'let', 'var', and 'inout' cannot be used as argument labels, but were colored
as identifiers rather than keywords when used like one
- the check to see if a keyword token is being used as an argument label wasn't
quite restrictive enough, e.g. treating the 'let's in 'case (let x, let y):' as
identifiers.
2016-11-07 10:47:04 -08:00
Ben Langmuir
f07457834a [sourcekitd] Replace a slow std::regex with custom parsing
This gave a roughly 40-45% improvement in sourcekitd's incremental
syntax-only parse time in files with a lot of doc comments (test case
was ~6000 lines, with ~780 lines being doc comments). This is on the
critical path for every edit.

While there were a few smaller improvements we could have made to the
original code, ultimately std::regex is slow, and it was better to just
use a custom parser for these simple patterns.

rdar://problem/28809397
2016-10-18 11:29:25 -07:00
Xi Ge
4d946f4918 [SyntaxModel] Improve the performance of searching URLs in comments (#5214)
[SyntaxModel] When searching URLs in doc comments, reduce the number of protocol name comparisons by looking ahead more characters, NFC. rdar://28298506

Searching URL in doc comments can be expensive. We used to look for
every colon as an indicator of potential URLs. However, this is not
efficient enough. Suggested by Ben, we further divide protocols into
categories so that most protocols can use "://" as an indicator of its
existence.

Not sure whether this is enough to close the radar, but I believe it is
a valuable performance improvement anyway.
2016-10-10 14:42:40 -07:00
Xi Ge
e6f263fe31 [SyntaxColor] Respect keywords' syntax kind when they appear in conditions. (#5076)
Keywords like 'let' can serve as argument labels. When they do so, we should
highlight them as identifiers instead of keywords. However, the check for this
situation seems overly lenient so that when 'let', 'var' appear in conditions
of IfStmt or GuardStmt, they are wrongly highlighted as identifiers too. This
commit strengthens the checking to preserve keywords' identity in these statements.
rdar://28297337
2016-09-29 19:36:55 -07:00
Ben Langmuir
74113f92ce [syntax-map] Fix array-of-object-literal syntax map, argument label keywords
Argument labels are allowed to use keywords, in which case we want to
treat them as identifiers in the syntax map (except for '_'). This
commit moves calculation of that into the original lexing instead of
in the model walker, which makes it much more robust, since the model
walker was only guessing about what was next on the the TokenNodes list.

This fixes a bug where arrays of object literals would only have the
first object correct (the following ones were identifiers), as well as
some incorrect cases where we treated keywords as identifiers.

rdar://problem/27726422
2016-08-09 10:25:42 -07:00
John McCall
c8c41b385c Implement SE-0077: precedence group declarations.
What I've implemented here deviates from the current proposal text
in the following ways:

- I had to introduce a FunctionArrowPrecedence to capture the parsing
  of -> in expression contexts.

- I found it convenient to continue to model the assignment property
  explicitly.

- The comparison and casting operators have historically been
  non-associative; I have chosen to preserve that, since I don't
  think this proposal intended to change it.

- This uses the precedence group names and higherThan/lowerThan
  as agreed in discussion.
2016-07-26 14:04:57 -07:00
Xi Ge
195c737b54 [libIDE] Add syntax kind of argument to fix a crash. rdar://27377118
Argument used to have the same syntax kind with that of parameter. This patch
starts to differentiate them.
2016-07-19 15:10:46 -07:00
Jordan Rose
5ff3ee3933 [IDE] Don't assume a platform name's SourceRange matches its length.
We're about to make 'macOS' and 'OSX' aliases.

Groundwork for SE-0106.
2016-07-07 10:28:52 -07:00
Xi Ge
3e03b78b77 [SyntaxColoring] Tolerating empty spaces between doc-comment openning… (#3373)
* [SyntaxColoring] Tolerating empty spaces between doc-comment opennings and field keywords. rdar://26310081

* [test] Update test for SourceKit.
2016-07-06 22:41:58 -07:00
Xi Ge
500fdd22d1 [Syntax] Avoid highlighting keyword-like labels in call arguments as … (#3369)
* [Syntax] Avoid highlighting keyword-like labels in call arguments as keywords. rdar://24460689

* [test] Update test for SourceKit.
2016-07-06 22:40:44 -07:00
David Farler
05235956fc SourceKit: Include up to closing paren in object literals
rdar://problem/26451674
2016-05-24 18:29:01 -07:00
David Farler
6c726620c0 SourceKit: Clean up syntax map switch
When creating the token map for highlighting, there is some glitchy
behavior that needed to be cleaned up:

- New image literal syntax wasn't getting highlighted as an object
  literal keyword.
- Other #-prefixed keywords had no data
- #line would appear as a build config ("brown") at the start of a line
- #available showed up as a build config. However, this should be a keyword
  because it is a runtime check, not a build configuration.

Add some test cases for these.

Fixes:
rdar://problem/26451674
2016-05-24 17:34:22 -07:00
Ted Kremenek
b8bbed8c13 [WIP] Implement SE-0039 (Modernizing Playground Literals) (#2215)
* Implement the majority of parsing support for SE-0039.

* Parse old object literals names using new syntax and provide FixIt.

For example, parse "#Image(imageLiteral:...)" and provide a FixIt to
change it to "#imageLiteral(resourceName:...)".  Now we see something like:

test.swift:4:9: error: '#Image' has been renamed to '#imageLiteral
var y = #Image(imageLiteral: "image.jpg")
        ^~~~~~ ~~~~~~~~~~~~
        #imageLiteral resourceName

Handling the old syntax, and providing a FixIt for that, will be handled in a separate
commit.

Needs tests.  Will be provided in later commit once full parsing support is done.

* Add back pieces of syntax map for object literals.

* Add parsing support for old object literal syntax.

... and provide fixits to new syntax.

Full tests to come in later commit.

* Improve parsing of invalid object literals with old syntax.

* Do not include bracket in code completion results.

* Remove defunct code in SyntaxModel.

* Add tests for migration fixits.

* Add literals to code completion overload tests.

@akyrtzi told me this should be fine.

* Clean up response tests not to include full paths.

* Further adjust offsets.

* Mark initializer for _ColorLiteralConvertible in UIKit as @nonobjc.

* Put attribute in the correct place.
2016-04-25 07:19:26 -07:00
practicalswift
abfecfde17 [gardening] if ([space]…[space]) → if (…), for(…) → for (…), while(…) → while (…), [[space]x, y[space]] → [x, y] 2016-04-04 16:22:11 +02:00
Xi Ge
f0e96f1e70 [SyntaxColoring] Allow empty lines when highlighting doc comment keywords. rdar://25144566 2016-03-15 13:28:34 -07:00
Ben Langmuir
8030d44826 [SyntaxMap] Fold unary minus into numeric literals
Unlike other prefix operators, unary minus is folded into the
NumberLiteralExpr in the parser. This commit recreates this effect in
the lexer-based syntax map so that token ranges will include the leading
minus.

rdar://problem/20205885
2016-03-15 10:40:52 -07:00
Xi Ge
b74bd730a6 [SyntaxColoring] Not coloring 'keywords' appearing in API argument names as actual keywords; they are legal names. rdar://25129880 2016-03-14 17:39:40 -07:00
Xi Ge
8b7eff2e7f [SyntaxColoring] Sanitize extra closing parenthesis by the end of URLs. 2016-03-14 11:18:48 -07:00
Xi Ge
f64ff89bd4 [SyntaxColoring] Remember to search for URLs inside doc comment lines/blocks. 2016-03-14 11:18:48 -07:00
Xi Ge
9c2f28475e [SyntaxColoring] Highlight doc comment keywords in playground-specific doc comment format. rdar://24870642 2016-03-01 15:44:41 -08:00
Chris Lattner
8dedfb31e3 Add support for #file/#line, etc according to SE-0028. __FILE__ and friends
are still accepted without deprecation warning as of this patch.
2016-02-04 14:22:22 -08:00
Doug Gregor
dccf3155f1 SE-0022: Implement parsing, AST, and semantic analysis for #selector. 2016-01-26 21:12:04 -08:00
Xi Ge
00bff249ff [SyntaxModel] Highlight /*: ... */, when appearing in playground, as doc comment block. rdar://24234991 2016-01-21 11:05:34 -08:00
Doug Gregor
ecfde0e71c Start parsing names with argument labels.
Basic implementatation of SE-0021, naming functions with argument
labels. Handle parsing of compound function names in various
unqualified-identifier productions, updating the AST representation of
various expressions from Identifiers to DeclNames. The result doesn't
capture all of the source locations we want; more on that later.

As part of this, remove the parsing code for the "selector-style"
method names, since we now have a replacement. The feature was never
publicized and doesn't make sense in Swift, so zap it outright.
2016-01-20 17:09:01 -08:00
Xi Ge
c73bb636cd [SyntaxColoring] Teach syntax model to recognize playground-specific doc comment lines. rdar://23902920 2016-01-04 12:38:34 -08:00
practicalswift
1339b5403b Consistent use of header comment format.
Correct format:
//===--- Name of file - Description ----------------------------*- Lang -*-===//
2016-01-04 13:26:31 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Ge Sen
7ac02d54ba Erase redundant whitespaces. 2015-12-10 13:35:06 +08:00
Doug Coleman
86d99cea9b Fix eight Linux warnings.
Fix spurious docs warning that @in and @in_guaranteed should be ``fn``.

Add ``#ifdef SWIFT_OBJC_INTEROP`` to silence a -Wunused-function
on linux since that function is only used from within that #ifdef
elsewhere.

Fix three -Wunused-function warnings on linux.

Fix two -Wunreachable-code warnings on linux dealing with
SWIFT_HAVE_WORKING_STD_REGEX.
2015-12-07 15:29:41 -08:00
Xi Ge
37370aaa55 [SyntaxColoring] Check if the end quote is escaped when checking if a string ends. rdar://23188457 2015-11-04 10:55:15 -08:00
Dmitri Hrybenko
2e51d23875 Un-ifdef object literals
Swift SVN r32880
2015-10-25 07:50:53 +00:00
Dmitri Hrybenko
0b4a54f64c CMake: detect and refuse broken std::regex
Swift SVN r32256
2015-09-26 05:06:43 +00:00
Argyrios Kyrtzidis
012f6cb083 [IDE] Make sure to process the body of a defer statement properly.
Fixes IDE features (except code-completion) not working inside 'defer'.
rdar://22849414.

Swift SVN r32254
2015-09-26 00:50:39 +00:00
Xi Ge
7f6a8b1315 Remove the constructor of CharSourceRange that takes SourceRange;
And add a utility function at lexer that converts SourceRange to CharSourceRange.

Swift SVN r32023
2015-09-17 01:15:34 +00:00
Xi Ge
682e4320d8 [SyntaxModel] Adjust the end loc when converting from SourceRange to CharSourceRange. rdar://22676599
Swift SVN r32013
2015-09-16 21:58:53 +00:00
Xi Ge
3088128501 Refactor DenseMapInfo<ASTNode> to ASTNode.h
Swift SVN r31438
2015-08-24 22:25:24 +00:00
Xi Ge
a21010e8f7 [SyntaxColor] Teach syntax model walker not to walk into active regions inside #if config stmt twice. rdar://22224993
Swift SVN r31433
2015-08-24 18:28:08 +00:00
Xi Ge
f9a621e6f5 [SyntaxHighlight] Highlight #line as keyword. rdar://22163375
Swift SVN r31040
2015-08-06 01:34:25 +00:00
Jordan Rose
953424072e Guard "object literals" feature with SWIFT_ENABLE_OBJECT_LITERALS.
This is not a feature we're releasing at the moment, so provide a way
to turn it off.

rdar://problem/21935551

Swift SVN r30966
2015-08-04 00:16:52 +00:00
Xi Ge
da69adbb09 [SyntaxHighlighting] Fix a issue when detecting multiple urls exist in one line of commit.
Swift SVN r30682
2015-07-27 01:12:30 +00:00
Xi Ge
f51335ac65 [SyntaxHighlighting] Highlight platform keywords inside available attributes. rdar://21905215
Swift SVN r30681
2015-07-27 01:12:28 +00:00
Xi Ge
61ccc5f48e Move radar number out of source file.
Swift SVN r30546
2015-07-23 20:23:04 +00:00
Xi Ge
72df884348 [SyntaxColoring] Correct the node kind of attributes and comment on the special case.
Swift SVN r30544
2015-07-23 19:49:17 +00:00
Xi Ge
95dc5b5607 [SyntaxColoring] Address Jordan's comments.
Highlight all decl modifiers for enum element decls, not just "indirect", as keywords.

Swift SVN r30524
2015-07-23 02:24:43 +00:00
Xi Ge
d980700f17 [SyntaxColoring] Add syntax coloring to indirect keyword of enum element decl. rdar://21927124
Swift SVN r30521
2015-07-23 01:37:22 +00:00
Chris Lattner
0001dc27bb remove support for the experiemental "character literals" feature.
Swift SVN r30509
2015-07-22 22:35:19 +00:00
Xi Ge
2f3a77ab40 Address Ben's comments on r30290
Swift SVN r30325
2015-07-17 20:27:17 +00:00