Commit Graph

276 Commits

Author SHA1 Message Date
Joe Groff
8d0d6ff1be LangRef: Demonstrate comma-separated case syntax.
The grammar already until-now-incorrectly claimed that 'case A, B' worked, but insert an example now that it actually works.

Swift SVN r8515
2013-09-20 20:44:11 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Chris Lattner
1928361a5a Change the list of usecases for structs.
Swift SVN r8402
2013-09-18 16:12:14 +00:00
Dave Zarzycki
fa8792d8a8 LangRef: Discuss why structs do not support inheritance
Swift SVN r8399
2013-09-18 15:18:48 +00:00
Doug Gregor
a14ddd41ba Minimally update LangRef for "constructor" -> "init" changes.
Swift SVN r8396
2013-09-18 05:49:34 +00:00
Doug Gregor
90b8b3e499 Constructor selectors always start with 'init'.
Implement the new rules for mapping between selector names and
constructors. The selector for a given constructor is formed by
looking at the names of the constructor parameters:
  * For the first parameter, prepend "init" to the parameter name and
  uppercase the first letter of the parameter name. Append ':' if
  there are > 1 parameters or the parameter has non-empty-tuple type.
  * For the remaining parameters, the name of each parameter followed
  by ':'.

When a parameter doesn't exist, assume that the parameter name is the
empty string.

And, because I failed to commit it separately, support selector-style
declarations of constructor parameters so that we can actually write
constructors nicely, e.g.:

  // selector is initWithFoo:bar:
  constructor withFoo(foo : Foo) bar(bar : Bar) { ... }



Swift SVN r8361
2013-09-17 22:49:05 +00:00
Doug Gregor
ca31b28e0f LangRef: add some basic documentation for generics.
Swift SVN r8240
2013-09-14 03:22:56 +00:00
Doug Gregor
1dea838517 Remove the "x as T" syntax from the language.
Swift SVN r7874
2013-09-03 22:47:33 +00:00
Howard Hinnant
c6d960c3df Minor type-o in Reserved Punctuation Tokens.
Swift SVN r7800
2013-08-30 21:02:39 +00:00
Dmitri Hrybenko
453205f5c2 LangRef: fix the only instance of missing this -> self rename that I could find
Swift SVN r7669
2013-08-28 17:21:40 +00:00
Jordan Rose
d40f74f2c1 [Parse] Treat ! as a postfix operator when both left- and right-bound.
For most operators, an expression like "a@b" is lexed with '@' as a binary
operation on 'a' and 'b'. However, we want to make sure we can support
calling optional functions using the syntax "a!()". Consequently, if there
are no spaces around a single '!' token, it is treated as a postfix operator
instead of an infix operator. The infix interpretation can still be requested
by using spaces on both sides of the operator.

Swift SVN r7651
2013-08-28 00:18:19 +00:00
Ted Kremenek
8f5b8ccb02 Rename "This" to "Self" and "this" to "self".
This was not likely an error-free change.  Where you see problems
please correct them.  This went through a fairly tedious audit
before committing, but comments might have been changed incorrectly,
not changed at all, etc.

Swift SVN r7631
2013-08-27 21:58:27 +00:00
Joe Groff
2d8a16331d Update union discussion in LangRef and add a section on union element patterns.
Swift SVN r7519
2013-08-23 19:36:52 +00:00
John McCall
329a5e47db Permit attribute lists to be split into multiple clauses.
This is particularly convenient for dealing with generated
code (e.g. as produced by the SIL printer), but it's also
quite defensible as a way for users to logically group
related attributes and split unrelated ones out, should
users find themselves using a lot of verbose attributes
(and prior experience with e.g. user-defined attributes
is that they definitely do sometimes turn into walls of
text...).

Swift SVN r7376
2013-08-20 22:37:38 +00:00
Jordan Rose
6f5d463d18 LangRef: include "T?" syntax.
This documents the current state of affairs, where "Int?[]" is allowed but
"Int[]?" is not. I'll update this again if/when we reach a new decision.

Swift SVN r7269
2013-08-15 18:59:06 +00:00
Dmitri Hrybenko
19298233af Update grammar for stmt-for-c-style: add optional parentheses
Swift SVN r7253
2013-08-15 01:59:08 +00:00
Jordan Rose
35f84dfbee Remove "import foo, bar" syntax.
We never really discussed this and it doesn't really buy us much. If we
want to have a compact way to import many things, it may not even end
up looking like this.

Swift SVN r7015
2013-08-07 22:56:58 +00:00
Jordan Rose
757cf9826f Add Parse and AST support for the new import syntax.
Also, update LangRef.

Note that an explicit "import module" has been left out for now, since
it's not strictly necessary and "module" isn't a keyword yet.

Swift SVN r6786
2013-07-31 23:23:26 +00:00
Jordan Rose
43e9cd7bb4 LangRef: Update union grammar and code examples.
Note: the new grammar allows the multiple-case syntax "case A, B".
This is <rdar://problem/14595749>.

Swift SVN r6784
2013-07-31 21:33:46 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +00:00
Doug Gregor
0842fb5cf8 Rename "base class" to "superclass" and "derived class" to "subclass".
Standardize on the more-common "superclass" and "subclass" terminology
throughout the compiler, rather than the odd mix of base/derived and
super/sub. 

Also, have ClassDecl only store the Type of the superclass. Location
information will be part of the inheritance clause for parsed classes.




Swift SVN r6687
2013-07-29 15:48:34 +00:00
Joe Groff
69d3392191 Accept underscore separators in numeric literals.
This makes long literals like 1_000_000_000 or 0x7FFF_FFFF_FFFF_FFFF much easier to read, and has precedent in Perl, OCaml, Python, Ruby, Rust, ... Fixes <rdar://problem/14247571>.

Swift SVN r6681
2013-07-28 18:56:30 +00:00
Anna Zaks
320d3300ef [docs] Add noreturn attribute documentation to the LangRef
Swift SVN r6632
2013-07-26 00:32:25 +00:00
John McCall
c34eaf1a24 Fix langref specification of call syntax.
Swift SVN r6601
2013-07-25 17:03:04 +00:00
Joe Groff
1776881f3a LangRef: Update tuple keyword argument syntax.
Swift SVN r6450
2013-07-22 15:39:07 +00:00
Joe Groff
733c2dd6a0 LangRef: Remove outdated section about metatype expressions.
Swift SVN r6428
2013-07-21 18:39:40 +00:00
Joe Groff
751da69c6a LangRef: Remove some stale references to 'following' tokens.
Swift SVN r6416
2013-07-20 17:35:35 +00:00
Joe Groff
02c609854c LangRef: Update keyword list.
Re-alphabetize 'where' among the declaration keywords. Eliminate the now non-user-facing "identifier-like keyword" concept and sort them among the other expression keywords. Add 'in' as a keyword.

Swift SVN r6182
2013-07-11 23:21:28 +00:00
Joe Groff
070ee26c56 Replace 'requires' keyword with 'where'.
Reuse the 'where' keyword to introduce generic requirement clauses, as in 'func foo<T:Enumerator where T.Element == Int>()'.

Swift SVN r6180
2013-07-11 22:20:40 +00:00
Joe Groff
dd1208c62c LangRef: Update 'switch' statement description.
Swift SVN r6159
2013-07-11 18:08:38 +00:00
Joe Groff
b62b376d45 LangRef: Clean up some grammar and phrasing.
Swift SVN r6158
2013-07-11 18:08:36 +00:00
Doug Gregor
61060baf8e Eliminate the type-checking pass that resolves default arguments in tuple types.
Per r6154, this is now dead code. The only places we allow default
arguments will be visited by normal type validation, so there's
nothing specific to do here.


Swift SVN r6157
2013-07-11 18:06:14 +00:00
Doug Gregor
50d6fd0455 Lock down on the use of default values in patterns and types.
Per previous discussions, we only want to allow default values for
uncurried 'func' and 'constructor' parameters, and not for return
types or arbitrary tuple types. Introduce this restriction, fixing
part of <rdar://problem/13372694>. 



Swift SVN r6156
2013-07-11 17:53:05 +00:00
Joe Groff
d5dd3edcff LangRef: Describe the magic default argument behavior of __LINE__ etc.
Swift SVN r6148
2013-07-11 15:30:30 +00:00
Joe Groff
b2d8226039 LangRef: Describe the new pattern forms.
Swift SVN r6147
2013-07-11 04:51:00 +00:00
Joe Groff
deab9bba9d Typo in LangRef anchor link.
Swift SVN r6131
2013-07-10 21:54:34 +00:00
Doug Gregor
63ff23147f Implement another new closure syntax.
In this syntax, the closure signature (when present) is placed within
the braces and the 'in' keyword separates it from the body of the
closure, e.g.,

      magic(42, { (x : Int, y : Int) -> Bool in
        print("Comparing \(x) to \(y).\n")
        return y < x
      })

When types are omitted from the parameter list, one can also drop the
parentheses, e.g.,

      magic(42, { x, y -> Bool in
        print("Comparing \(x) to \(y).\n")
        return y < x
      })

The parsing is inefficient and recovers poorly (in part because 'in'
is a contextual keyword rather than a real keyword), but it should
handle the full grammar. A number of tests, along with the whitepaper
and related rational documents, still need to be updated. Still, this
is the core of <rdar://problem/14004323>.



Swift SVN r6105
2013-07-10 01:15:15 +00:00
Chris Lattner
2fe98e14e7 implement basic __FILE__, __LINE__, and __COLUMN__ magic identifiers.
Swift SVN r5912
2013-06-30 21:19:32 +00:00
Chris Lattner
71be5c9c60 fallthrough is a control flow transfer too.
Swift SVN r5810
2013-06-26 04:37:59 +00:00
Chris Lattner
1259e32913 - Update LangRef to mention stmt-break/continue/fallthrough. Factor the stmt
grammar description in LangRef and the parser to expose a new stmt-control-transfer.
- remove obsolete comment in ParseStmt.cpp talking about stmt-brace.

No behavior change.


Swift SVN r5809
2013-06-26 04:31:28 +00:00
Doug Gregor
85030ae72f Remove a stray selector-args production from the expr-super grammar
Swift SVN r5776
2013-06-24 14:48:38 +00:00
Doug Gregor
fad5c78484 Remove expr-func from the syntax of the language.
FuncExpr still lives on as the implementation mechanism for FuncDecl,
but it's not long for this world.


Swift SVN r5752
2013-06-21 18:54:18 +00:00
Joe Groff
cb2e800612 LangRef: Update stale language about cast operator syntax.
Cast operators no longer have precedence below all operators, but they still end sequence expression parsing because of the type production on their right sides.

Swift SVN r5572
2013-06-11 00:36:44 +00:00
Joe Groff
5358806890 LangRef: Note that '=' expr has void result.
Swift SVN r5559
2013-06-10 16:31:46 +00:00
Joe Groff
44790622c6 LangRef: Update assign/cast operator descriptions.
Describe the new handling of '=' and cast operators as builtin binary operators.

Swift SVN r5558
2013-06-10 16:20:39 +00:00
Joe Groff
3de47b3fec LangRef: Remove outdated lparen/lsquare whitespace sensitivity talk.
Swift SVN r5557
2013-06-10 01:58:05 +00:00
Doug Gregor
c10b1cef65 Allow trailing closures without pipes wherever we don't expect curly braces.
This moves trailing closures from expr-postfix up to the level of
expr, and introduces an intermediate level (expr-basic) for places
that need to parse expressions followed by curly braces, such as
if/while/switch/for. Trailing closures are still restricted to occur
after expr-postfix, although the parser itself parses a slightly more
general and then complains if it got more than an expr-postfix.


Swift SVN r5256
2013-05-21 22:30:25 +00:00
Doug Gregor
4d60bb7173 Implement trailing closure syntax.
Trailing closure syntax allows one to write a closure following any
other postfix expression, which passes the closure to that postfix
expression as an arguments. For example:

        sort(fruits) { |lhs, rhs|
          print("Comparing \(lhs) to \(rhs)\n")
          return lhs > rhs
        }

As a temporary limitation to work around the ambiguity with

  if foo { ... } { ... }

we require trailing closures to have an explicit parameter list, e.g.,

  if foo { || ... } { ... }



Swift SVN r5210
2013-05-17 19:16:18 +00:00
Doug Gregor
2138dc93e1 Update LangRef with a discussion of the Ruby-inspired closures.
Swift SVN r5204
2013-05-17 17:09:02 +00:00
Doug Gregor
6e2a99f189 Remove unnecessary commentary
Swift SVN r5050
2013-05-06 16:28:07 +00:00