Commit Graph

309 Commits

Author SHA1 Message Date
Doug Gregor
bd61ca5927 Diagnose multiple statements/declarations on the same line that are not separated by a semicolon.
Swift SVN r4364
2013-03-13 01:32:30 +00:00
Joe Groff
062ad267c4 Value-only switch statements.
Implement switch statements with simple value comparison to get the drudge work of parsing and generating switches in place. Cases are checked using a '=~' operator to compare the subject of the switch to the value in the case. Unlike a C switch, cases each have their own scope and don't fall through. 'break' and 'continue' apply to an outer loop rather to the switch itself. Multiple case values can be specified in a comma-separated list, as in 'case 1, 2, 3, 4:'. Currently no effort is made to check for duplicate cases or to rank cases by match strength; cases are just checked in source order, and the first one wins (aside from 'default', which is branched to if all cases fail).

Swift SVN r4359
2013-03-12 04:43:01 +00:00
Dave Zarzycki
c4259e05c8 Make literal parsing more robust
Swift SVN r4339
2013-03-08 17:16:05 +00:00
Dave Zarzycki
0f2f031a67 Typo
Swift SVN r4266
2013-03-02 17:55:36 +00:00
Dave Zarzycki
68c6d4c6e3 13324820 Change tuple accessor syntax to 'tuple.0'
Swift SVN r4265
2013-03-02 17:51:03 +00:00
Dave Zarzycki
23cd39137b Do not allow embedded ASCII control characters in string/char literals
We might need/want to make an exception for '\t'.

Swift SVN r4257
2013-03-01 22:36:21 +00:00
Dave Zarzycki
9d777dfad7 Revert \a, \b, \f
This branch should have been committed a long time ago. Sorry.

Swift SVN r4256
2013-03-01 22:36:19 +00:00
Dave Zarzycki
f043cdca5a Revert "wipUnifyFormToken"
This reverts commit 39e8ace65c29d9e83f4fbebc24be9c9896e9a3e1.

Sorry!

Swift SVN r4185
2013-02-25 03:13:14 +00:00
Dave Zarzycki
06d3c09d97 wipUnifyFormToken
Swift SVN r4183
2013-02-25 03:11:11 +00:00
Dave Zarzycki
9b1a46c910 Treat zero length files as an empty line
<rdar://problem/13211640> "Missing newline at end of file" when input file is zero-length (truly "empty")

Swift SVN r4171
2013-02-24 01:24:11 +00:00
Joe Groff
ddb7ead55c REPL: Contextual completions.
If the completion prefix has a '.' behind it, guesstimate a context expression by lexing backward through an identifier(.identifier)* dotted path, then attempt to parse and typecheck that expression to decide on a base type in which to find completions.

Swift SVN r4063
2013-02-16 20:07:50 +00:00
Dave Zarzycki
177e243ad5 Tokens should not be named after their use
This fixes an old TODO item based on feedback from Chris and John.

Swift SVN r4038
2013-02-13 21:40:43 +00:00
Dave Zarzycki
5b92dae801 Make '=' consistent with the assignment operators
It seems wrong that '=' behaves differently than the compound assignment
operators and comparison operators.

I don't feel strongly about this behavior in and of itself. We can always
revert this change later if we want to rationalize why '=' should have
grammatically different rules than say '+='.

Swift SVN r4027
2013-02-13 06:02:10 +00:00
Dave Zarzycki
bf3c98a0e6 Revert \v from r3968
Nobody can find any modern use for \v.

Swift SVN r3990
2013-02-08 18:19:58 +00:00
Dave Zarzycki
a282c35e6a Make floating-point number parsing more strict
The range operators (".." and someday "...") make constructs like .24...42
ambiguous. Therefore, we will enforce that programmers either place digits
on both sides of the decimal place, or use of exponent based notation.

Swift SVN r3989
2013-02-08 15:48:02 +00:00
Dave Zarzycki
1ca414e1c9 Part two of r3968
Other subsystems need to be in sync with r3968.

Swift SVN r3978
2013-02-07 00:12:51 +00:00
Dave Zarzycki
9ad1e4c950 C/C++/ObjC Interop: string/char escapes
If we're going to import C/C++/ObjC code, we ought to "just work" with
their escape patterns when reasonable. (No error-prone octal escapes or
trigraph support). Also, update LangRef to document what the escapes do.

This patch DOES fix a bug with lexing operators in the case of (already
warned about) embedded NUL bytes within a source file.

This patch DOES NOT change what we consider to be valid whitespace in
the language.

Swift SVN r3970
2013-02-06 17:51:18 +00:00
Dave Zarzycki
89865a0dd5 Warn when missing a newline at EOF
While we are not C, we should not ignore the strong Unix command-line
tool conventions that motivated the C standard to make this be a
requirement of the language and a warning in clang/gcc.

Swift SVN r3946
2013-02-05 01:30:50 +00:00
Joe Groff
081787c3d5 Lexer: Lex C99-style hexadecimal float literals.
APFloat's parser gives us the parsing for free. Unlike C99 we require at least one digit on both sides of the hexadecimal point in order to allow '0x1.method()' expressions, similar to Dave's proposed change to float lexing. Also, we were requiring a sign after 'e' in the exponent, which is inconsistent with C, C++, and the Java regex we claim to follow, so I made the exponent sign optional.

Swift SVN r3940
2013-02-03 19:06:08 +00:00
Dave Zarzycki
cd3f31fa9d Formalize "starting" vs "following" token generation
If we generalize John's insight about l_(paren|square) being about
"starting" and "following" tokens, then we can detect many statement
or declaration boundaries that are lacking either white space or a
semicolon.

Ensuring some amount of whitespace between statements and declarations
is good for future proofing.

Swift SVN r3914
2013-01-31 18:57:53 +00:00
Dave Zarzycki
ff8bd176b4 Sort the reserved keyword list
Swift SVN r3894
2013-01-29 21:13:41 +00:00
Dave Zarzycki
b36678214a Rename l_(paren|square)_(call|subscript)
Thanks Chris and John for the feedback.

Swift SVN r3893
2013-01-29 21:13:39 +00:00
Dave Zarzycki
5fe85d7020 Formalize unary prefix '&' to mean "make ref"
This makes reserved operator parsing more robust and easier to understand.

Swift SVN r3884
2013-01-27 21:20:06 +00:00
Dave Zarzycki
93a81f1cd8 Fix unresolved member versus field access ambiguity
'.' is an operator, therefore unary prefix '.' can mean something
different than binary '.' (field access).

Swift SVN r3883
2013-01-27 00:30:40 +00:00
Dave Zarzycki
d7cc4b4a91 Reclaim "in" as an identifier
In Swift the "in" keyword is really a form of punctuation, and highly
context specific punctuation at that. It never begins a statement, nor
does the grammar require it be statement keyword. The grammar also
doesn't use it outside of for-each loops, and its use within a for-each
loop is highly unambiguous.

Thanks to Chris for the performance related feedback. This improves the
performance of getter/setter parsing as well.

Swift SVN r3880
2013-01-26 01:49:18 +00:00
Dave Zarzycki
b98844adc9 Fix a test I missed
Also, simplify isStartOfLiteral() so it is easier to understand.

Swift SVN r3878
2013-01-26 01:18:15 +00:00
Dave Zarzycki
2443ec8db8 Reserve "non-literal" use of various characters for now
Given that we want semicolon statement separators to be optional,
literals can bump up right next to the previous statement at the moment:
'var x = y"hello".print()' is two statements right now, not one broken
expression being used to initialize to 'x'.  This is unfortunate if we
ever want to support C++ style raw strings or otherwise have some back
pocket grammar tricks to implement type state or trivially unambiguous
generics.

Swift SVN r3871
2013-01-25 23:37:39 +00:00
Dave Zarzycki
1dcfff8497 'this' and 'This' are keywords
Swift SVN r3858
2013-01-24 21:54:43 +00:00
Joe Groff
14c68e95d0 Lexer: Special-case 'super' and 'constructor'.
Dave noted that he's trying to scrub the parser codebase of wishy-washy 'isAnyLParen' and 'isAnyLBrace' calls by consistently lexing opening bracket tokens correctly to begin with. Since currently only 'super' and 'constructor' need to be lexed like identifiers for expression syntax (and, in the future, 'this' and 'This' when those become keywords), mark them as a special kind of 'identifier keyword' in Tokens.def and roll back some of the changes I made to make parsing other decls support either token.

Swift SVN r3848
2013-01-23 22:23:37 +00:00
Joe Groff
8af835edcc Lexer: '[' and '(' after a keyword is non-literal.
Opening brackets after a keyword have to lex as l_paren_call or l_square_subscript in order for expressions like 'super.constructor()' or 'super[i]' to parse. While we're here, let's move the keyword and punctuator list to a metaprogrammable Tokens.def header too. Update decl and stmt parsers to use 'isAnyLParen' so that, e.g., 'constructor(' and 'constructor (' both work as before.

Swift SVN r3846
2013-01-23 21:24:26 +00:00
Dave Zarzycki
735294a5c9 Make the lexing of '(', '[', and '.' consistent
The lexer now models tuples, patterns, subscripting, function calls, and
field access robustly. The output tokens are now better named as well:
l_paren and l_paren_call, and l_square and l_square_subscript. It
should be much more clear now which one to use. Also, the use of
l_paren or l_square will not arbitrarily flip flop if the token before
it is a keyword or if the token before it was the trailing ']' of an
attribute list. Similarly, tuples will always cause the lexer to produce
l_paren, regardless if the user typed '((x,y))' or '( (x,y))'.

When we someday add array literals, the right token is now naturally
falling out of the lexer.

Swift SVN r3840
2013-01-23 03:23:17 +00:00
Chris Lattner
ede0fc287e rework r3701 a bit to pull the uncommon cases out of the hot path of the operator lexer loop.
Swift SVN r3707
2013-01-08 02:02:55 +00:00
Dave Zarzycki
21270376db Robustness: clean up handling of '.'
'.' is an operator in order to make '..' work and perhaps someday '...'
work, but we shouldn't interpret '....' as '...' followed by '.'.

Swift SVN r3705
2013-01-08 00:22:34 +00:00
Dave Zarzycki
7a25fe61fa Robustness: tighten up ".42" float literal lexing
Swift SVN r3704
2013-01-07 22:03:22 +00:00
Dave Zarzycki
1af9c2b153 Robustness: better comment detection
Swift SVN r3703
2013-01-07 20:04:02 +00:00
Dave Zarzycki
3454762f3c UTF8 validation: don't let reserved values slip through
Swift SVN r3698
2013-01-06 18:11:41 +00:00
Chris Lattner
c378beb606 Fix rdar://12951176 - rejecting */, instead of parsing it as an operator.
Swift SVN r3687
2013-01-04 23:21:56 +00:00
Dave Zarzycki
78785c903f Char: add NUL literal and unit tests
Swift SVN r3681
2013-01-04 19:47:40 +00:00
Chris Lattner
b19f4ffaf5 fix typo in regex.
Swift SVN r3598
2012-12-28 09:55:16 +00:00
John McCall
a6a2ab92b3 Add a production to the type grammar for writing metatypes.
Swift SVN r3052
2012-10-24 07:54:17 +00:00
Doug Gregor
27e3a03525 Implement parsing, AST, and basic validation of requires clauses
within generic parameter clauses, e.g.,

  func f<T requires T : P1, T : P2>() {}




Swift SVN r2369
2012-07-18 23:36:56 +00:00
Eli Friedman
6b4a248f04 Parsing and AST support for destructors on classes.
Swift SVN r2348
2012-07-12 01:26:02 +00:00
Doug Gregor
35e6e56595 When we split a token starting with '<' or '>', make sure that the
resulting token goes back through the lexer to get the appropriate
token kind. Thanks to Chris for spotting this.

Also, document the '<' and '>' splitting behavior in LangRef.


Swift SVN r2192
2012-06-18 16:40:59 +00:00
Chris Lattner
db0cd646fc lexer/parser/ast/sema support for do/while statements. irgen next.
Swift SVN r2186
2012-06-17 02:29:54 +00:00
John McCall
8c46c69efa Lexically distinguish prefix, postfix, and binary operators
and use this information as cues in the language.  Right now,
we do not accept things like "-- *i" because the prefix
operator is not correctly right-bound;  instead you have to
write "--(*i)".  I'm okay with that;  I did add a specialized
diagnostic recognizing operator-binary in a place where we're
expecting a potential operator-prefix.

Swift SVN r2161
2012-06-07 01:00:06 +00:00
Eli Friedman
75907029f1 Add parsing and semantic analysis for a basic ConstructorDecl. Still missing: no IRGen, and semantic analysis to actually call them.
Swift SVN r2159
2012-06-05 23:51:19 +00:00
Eli Friedman
c404598fcb Parsing and semantic analysis for 'break' and 'continue'.
Swift SVN r2087
2012-05-31 00:55:33 +00:00
Eli Friedman
099a97847d Parsing and AST support for varargs tuples.
Swift SVN r1875
2012-05-16 22:02:01 +00:00
Eli Friedman
a5a39860cd Basic parsing plus a bit more of the AST for ClassDecls.
Swift SVN r1860
2012-05-15 22:07:31 +00:00
Chris Lattner
22300ed57f improve diagnostic for a " in the middle of an interpolated string, including a range:
t.swift:4:19: error: unexpected '"' character in string interpolation
"Hello \(x+1 world"
        ~~~~~~~~~~^



Swift SVN r1759
2012-05-05 23:12:07 +00:00