Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues in the grammar, add Swift 2.0 support #47

Merged
merged 8 commits into from
Jun 29, 2015

Conversation

a4sriniv
Copy link
Member

Grammar fixes:

  • array/dictionary types
  • use symbols directly instead of setting them to a variable
  • ... operator not recognized
  • & operator not recognized
  • operators can be passed for function expecting closure (bug in apple's grammar)
  • implicit member expressions ( .EnumCaseType )
  • declaration modifiers (eg: 'lazy')
  • access specifiers (eg: 'public')
  • capture specifiers fix (bug in apple's grammar)
  • add class-requirement to type-inheritance-clause
  • getter/setter fixes
  • operator declaration fix

Swift 2.0

  • replace guard-clause with where-clause
  • update conditions for while, if and guard statements
  • repeat-while loops
  • guard statements
  • availability conditions
  • update while loops
  • update for in statement
  • throw statements
  • try operator
  • do-catch statements
  • defer statements
  • extensions with a requirement clause (not mentioned in apple's grammar)

Grammar fixes:

- array/dictionary types
- use symbols directly instead of setting them to a variable
- ... operator not recognized
- & operator not recognized
- operators can be passed for function expecting closure (bug in apple's grammar)
- implicit member expressions ( .EnumCaseType )
- declaration modifiers (eg: 'lazy')
- access specifiers (eg: 'public')
- capture specifiers fix (bug in apple's grammar)
- add class-requirement to type-inheritance-clause
- getter/setter fixes
- operator declaration fix

Swift 2.0

- replace guard-clause with where-clause
- update conditions for while, if and guard statements
- repeat-while loops
- guard statements
- availability conditions
- update while loops
- update for in statement
- throw statements
- try operator
- do-catch statements
- defer statements
- extensions with a requirement clause (not mentioned in apple's grammar)
@@ -532,7 +593,7 @@ closureSignature
| captureList 'in'
;

captureList : '[' captureSpecifier expression ']' ;
captureList : '[' captureSpecifier expression (',' captureSpecifier expression)? ']' ;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compile complains about the following code (unable to infer closure type in the current context)

var someInts = []()

However the linter does not break. Is this an error with the supplied grammar or is the swift compiler broken?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this a syntactic error, but a semantic one. The compiler does not catch syntactic errors during the parsing stage. Think back to CS 241 where we would check if variables were being declared before use only after we generated a parse tree (by creating symbol tables).

The following two lines would be valid syntactically and semantically:

var someInts: [Int]
someInts = []()

I don't think the linter should worry about semantic errors just yet, and let the compiler catch them.

@adityatrivedi
Copy link
Member

👍

@a4sriniv a4sriniv assigned alykhank and unassigned adityatrivedi Jun 26, 2015
@@ -38,12 +38,14 @@ topLevel : (statement | expression)* EOF ;
// GRAMMAR OF A STATEMENT

statement
: expression ';'?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was expression moved to the bottom of the list for a semantic purpose? Or just an artifact of removing/adding lines?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semantic. Rules mentioned earlier will be given higher priority when trying to parse input. For a non-ambiguous grammar this wouldn't have made a difference. But because we a line can be matched with two different rules sometimes, we want the more specific rule to be given higher priority. This fixed a particular scenario (I think it was setters).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, do you mind adding an explanation/comment in the source so that we know to keep it at the bottom?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -414,7 +467,8 @@ balancedToken

expressionList : expression (',' expression)* ;

expression : prefixExpression binaryExpression* ;
expression : tryOperator? prefixExpression binaryExpression+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be simplified to tryOperator? prefixExpression binaryExpression* ; instead of splitting into two grammar rule expansions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it can, this was just me trying to fix the operator situation. Safe to say that it didn't work.

@alykhank
Copy link
Member

👍

a4sriniv added a commit that referenced this pull request Jun 29, 2015
Fix issues in the grammar, add Swift 2.0 support
@a4sriniv a4sriniv merged commit 77dc4e8 into master Jun 29, 2015
@a4sriniv a4sriniv deleted the as-46-swift-grammar-fix branch June 29, 2015 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade grammar to Swift 2.0 Fix grammar for setter declarations Fix "for loop" grammar
4 participants