Commits

Tim Vernum committed 15429d5

Update to support java 8 lambdas

Comments (0)

Files changed (1)

parser/source/grammar/java.jjt

 | < RUNSIGNEDSHIFTASSIGN: ">>>=" >
 | < ELLIPSIS: "..." >
 | < DIAMOND: "<>" >
+| < ARROW: "->" >
 }
 
 /* >'s need special attention due to generics syntax. */
 void TernaryExpression() #void :
 {}
 {
-  ( LogicalOrExpression() [ "?" Expression() ":" Expression() ] ) #TernaryExpression(>1)
+  ( LogicalOrExpression() [ LOOKAHEAD(1) "?" Expression() ":" Expression() ] ) #TernaryExpression(>1)
 }
 
 void LogicalOrExpression() #void :
 {}
 {
-( LogicalAndExpression() ( "||" LogicalAndExpression() )*  ) #LogicalOrExpression(>1)
+( LogicalAndExpression() ( LOOKAHEAD(1) "||" LogicalAndExpression() )*  ) #LogicalOrExpression(>1)
 }
 
 void LogicalAndExpression() #void :
 {}
 {
-( InclusiveOrExpression() ( "&&" InclusiveOrExpression() )*  ) #LogicalAndExpression(>1)
+( InclusiveOrExpression() ( LOOKAHEAD(1) "&&" InclusiveOrExpression() )*  ) #LogicalAndExpression(>1)
 }
 
 void InclusiveOrExpression() #void :
 {}
 {
-( ExclusiveOrExpression() ( "|" ExclusiveOrExpression() )*  ) #InclusiveOrExpression(>1)
+( ExclusiveOrExpression() ( LOOKAHEAD(1) "|" ExclusiveOrExpression() )*  ) #InclusiveOrExpression(>1)
 }
 
 void ExclusiveOrExpression() #void :
 {}
 {
-( AndExpression() ( "^" AndExpression() )*  ) #ExclusiveOrExpression(>1)
+( AndExpression() ( LOOKAHEAD(1) "^" AndExpression() )*  ) #ExclusiveOrExpression(>1)
 }
 
 void AndExpression() #void:
 {}
 {
-( EqualityExpression() ( "&" EqualityExpression() )*  ) #AndExpression(>1)
+( EqualityExpression() ( LOOKAHEAD(1) "&" EqualityExpression() )*  ) #AndExpression(>1)
 }
 
 void EqualityExpression() #void:
 {}
 {
-  ( InstanceOfExpression() ( EqualityOperator() InstanceOfExpression() )* ) #EqualityExpression(>1)
+  ( InstanceOfExpression() ( LOOKAHEAD(1) EqualityOperator() InstanceOfExpression() )* ) #EqualityExpression(>1)
 }
 
 void EqualityOperator() #BinaryOperator :
 void InstanceOfExpression() #void :
 {}
 {
-( RelationalExpression() [ "instanceof" Type() ]  ) #InstanceOfExpression(>1)
+( RelationalExpression() [ LOOKAHEAD(1) "instanceof" Type() ]  ) #InstanceOfExpression(>1)
 }
 
 void RelationalExpression() #void :
 {}
 {
-( ShiftExpression() ( RelationalOperator() ShiftExpression() )*  ) #RelationalExpression(>1)
+( ShiftExpression() ( LOOKAHEAD(1) RelationalOperator() ShiftExpression() )*  ) #RelationalExpression(>1)
 }
 
 void RelationalOperator() #BinaryOperator :
 void ShiftExpression() #void :
 {}
 {
-    ( AdditiveExpression() ( ShiftOperator() AdditiveExpression() )*  ) #ShiftExpression(>1)
+    ( AdditiveExpression() ( LOOKAHEAD(1) ShiftOperator() AdditiveExpression() )*  ) #ShiftExpression(>1)
 }
 
 void ShiftOperator() #BinaryOperator :
 void AdditiveExpression() #void :
 {}
 {
-    ( MultiplicativeExpression() ( AdditiveOperator() MultiplicativeExpression() )*  ) #AdditiveExpression(>1)
+    ( MultiplicativeExpression() ( LOOKAHEAD(1) AdditiveOperator() MultiplicativeExpression() )*  ) #AdditiveExpression(>1)
 }
 
 void AdditiveOperator() #BinaryOperator :
 void MultiplicativeExpression() #void :
 {}
 {
-( UnaryExpression() ( MultiplicativeOperator() UnaryExpression() )*  ) #MultiplicativeExpression(>1)
+( UnaryExpression() ( LOOKAHEAD(1) MultiplicativeOperator() UnaryExpression() )*  ) #MultiplicativeExpression(>1)
 }
 
 void MultiplicativeOperator() #BinaryOperator :
 {
   ( "~" | "!" ) UnaryExpression() #UnaryExpression(true)
 |
-  LOOKAHEAD( CastLookahead() )
+  LOOKAHEAD( CastExpression() )
   CastExpression()
 |
   PostfixExpression()
 }
 
-// This production is to determine lookahead only.  The LOOKAHEAD specifications
-// below are not used, but they are there just to indicate that we know about
-// this.
-void CastLookahead() #void:
-{}
-{
-  LOOKAHEAD(2)
-  "(" PrimitiveType()
-|
-  LOOKAHEAD("(" Type() "[")
-  "(" Type() "[" "]"
-|
-  "(" Type() ")" ( "~" | "!" | "(" | <IDENTIFIER> | "this" | "super" | "new" | Literal() )
-}
-
 void PostfixExpression() #void:
 {}
 {
-    PrimaryExpression() [ ( "++" | "--" ) #PostfixExpression() ]
+    PrimaryExpression() [ LOOKAHEAD(1) ( "++" | "--" ) #PostfixExpression() ]
 }
 
 void CastExpression():
 |
   Super()
 |
+  LOOKAHEAD( ClassReference() )
+  ClassReference()
+|
+  LOOKAHEAD( LambdaParameters() "->" )
+  LambdaExpression()
+|
   "(" Expression() ")"
 |
   AllocationExpression()
 |
-  LOOKAHEAD( ClassReference() )
-  ClassReference()
-|
   QualifiedIdentifier()
 }
 
 {
   "default" MemberValue()
 }
+
+void LambdaExpression():
+{}
+{
+    LambdaParameters() "->" LambdaBody()
+}
+
+void LambdaParameters() :
+{}
+{
+    Identifier()
+|
+    "("  LambdaParameterList() ")"
+}
+
+void LambdaParameterList() :
+{}
+{
+    LOOKAHEAD(2)
+    ( Identifier() ( "," Identifier() ) * )
+|
+    ( FormalParameter() ( "," FormalParameter() ) * )
+}
+
+void LambdaBody() :
+{}
+{
+    Block()
+|
+    Expression()
+}
+