589 Commits

Author SHA1 Message Date
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
Chris Lattner
e5108826c2 change the interface to skipToEndOfInterpolatedExpression to return the
interesting character on failure as well as on success.  Simplify the
code in Lexer::getEncodedStringLiteral since it cannot be called on a 
string with an malformed interpolated expression.


Swift SVN r1758
2012-05-05 22:56:40 +00:00
Chris Lattner
822c7a2689 remove a hack that isn't needed now that we pre-lex the tokens in an interpolated string literal, thanks doug.
Swift SVN r1757
2012-05-05 22:44:14 +00:00
Chris Lattner
2f44c0038c Initial stab at implementing string literal interpolation for simple expressions,
e.g. "foo is \(i+j)".  This implements rdar://11223686

Doug implemented all the hard parts of this.  I ripped out support for nested string
literals (i.e. string literals within an interpolated string), which simplified the
approach and defined away some problems with his patch in progress.  I plan a few refinements
on top of this basic patch.



Swift SVN r1738
2012-05-04 05:53:50 +00:00
Chris Lattner
8c478d1cb7 remove the foreach keyword, switching foreach loops to use 'for' instead.
This uses one-token lookahead to distinguish between the two forms.


Swift SVN r1710
2012-05-02 01:06:06 +00:00
Chris Lattner
aa069a90cc fix error recovery to not crash: the lexer should always return a token even in an erroneous token.
Swift SVN r1676
2012-04-27 06:34:45 +00:00
Chris Lattner
615ca4a360 implement the rest of character literal support, and enhance Char to be character literal
compatible.  This wraps up rdar://11305635, though some cleanup of the testsuite can now be done.


Swift SVN r1672
2012-04-27 06:18:30 +00:00
Chris Lattner
c7e68a4a8b langref and lexer support for character literals.
Swift SVN r1671
2012-04-27 05:51:30 +00:00
Doug Gregor
f997a781bf Parsing and basic AST representation for 'foreach' statement.
Swift SVN r1594
2012-04-24 18:12:44 +00:00
Chris Lattner
df74bc03c0 lang ref and parser support for for statements. AST and sema next.
Swift SVN r1493
2012-04-19 18:25:48 +00:00
Doug Gregor
6897b6ab44 Add support for parsing a subscripting declaration, e.g.,
subscript (i : Int) -> Double {
    get { /* get ith element of something */ }
    set { /* set ith element of something to value*/ }
  }



Swift SVN r1476
2012-04-18 21:43:54 +00:00
John McCall
71157c65d5 Add parsing support, but no type-checking or IR-generation,
for new expressions.

Swift SVN r1466
2012-04-18 08:09:18 +00:00
John McCall
e6d56fd718 Require an unspaced [ to start a subscript or array-type suffix.
Per discussion, this should probably be "no newline since the last
token", but that decision should be made simultaneously for ( and [.

Swift SVN r1461
2012-04-18 08:08:58 +00:00
Eli Friedman
9009d294d2 More strictly special-case '..'; making '-.' etc. an operator would be a complete disaster.
Swift SVN r1444
2012-04-17 00:34:25 +00:00
Eli Friedman
6a001efbbb Make "..", "*^.^*", etc. into overloadable operators. Make 1..10 construct a Range.
This has the side-effect that you can't explicitly refer to an operator* with "swift.*", etc., but per discussion with Doug, that's probably okay.



Swift SVN r1443
2012-04-17 00:21:38 +00:00
Chris Lattner
cc421b20c1 allow ~ as the first character of an operator.
Swift SVN r1413
2012-04-13 05:57:48 +00:00
Chris Lattner
8a7c6f7258 Eli points out that 4 is the max length. apparently I can't handle this. Thanks Eli! :)
Swift SVN r1406
2012-04-12 23:21:54 +00:00
Chris Lattner
b01c3bd989 We need to eventually add unicode identifier support, but it is beyond the scope of
what I intend to do right now.



Swift SVN r1405
2012-04-12 23:14:48 +00:00
Chris Lattner
09e051ce99 reject invalid UTF8 characters in comments.
Swift SVN r1403
2012-04-12 21:58:30 +00:00
Chris Lattner
d19939ead3 rearrange file a bit, no functionality change.
Swift SVN r1402
2012-04-12 21:51:55 +00:00
Chris Lattner
c92cf52358 since we allow utf8 source files, start validating utf8 characters in string literals
and test that they continue to work.  Part of rdar://11220029


Swift SVN r1401
2012-04-12 21:47:12 +00:00