-
Notifications
You must be signed in to change notification settings - Fork 47
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
Conversation
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)? ']' ; | |||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
👍 |
…6-swift-grammar-fix
- Fix check for setter name length, add test - Change do while loop to repeat while loop
@@ -38,12 +38,14 @@ topLevel : (statement | expression)* EOF ; | |||
// GRAMMAR OF A STATEMENT | |||
|
|||
statement | |||
: expression ';'? |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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+ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
👍 |
Fix issues in the grammar, add Swift 2.0 support
Grammar fixes:
Swift 2.0