Compare commits
3 Commits
30365d76bd
...
82b2b4a6e1
Author | SHA1 | Date | |
---|---|---|---|
82b2b4a6e1 | |||
af093fa3bb | |||
666856b33a |
@ -200,6 +200,9 @@ testExpressionSimpleFieldAccess = TestCase $
|
|||||||
testExpressionFieldSubAccess = TestCase $
|
testExpressionFieldSubAccess = TestCase $
|
||||||
assertEqual "expect NameResolution without this" (BinaryOperation NameResolution (Reference "a") (Reference "b")) $
|
assertEqual "expect NameResolution without this" (BinaryOperation NameResolution (Reference "a") (Reference "b")) $
|
||||||
parseExpression [IDENTIFIER "a",DOT,IDENTIFIER "b"]
|
parseExpression [IDENTIFIER "a",DOT,IDENTIFIER "b"]
|
||||||
|
testExpressionConstructorCall = TestCase $
|
||||||
|
assertEqual "expect constructor call" (StatementExpressionExpression (ConstructorCall "Foo" [])) $
|
||||||
|
parseExpression [NEW,IDENTIFIER "Foo",LBRACE,RBRACE]
|
||||||
|
|
||||||
testStatementIfThen = TestCase $
|
testStatementIfThen = TestCase $
|
||||||
assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) Nothing] $
|
assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) Nothing] $
|
||||||
@ -217,7 +220,16 @@ testStatementAssign = TestCase $
|
|||||||
testStatementMethodCallNoParams = TestCase $
|
testStatementMethodCallNoParams = TestCase $
|
||||||
assertEqual "expect methodcall statement no params" [StatementExpressionStatement (MethodCall (Reference "this") "foo" [])] $
|
assertEqual "expect methodcall statement no params" [StatementExpressionStatement (MethodCall (Reference "this") "foo" [])] $
|
||||||
parseStatement [IDENTIFIER "foo",LBRACE,RBRACE,SEMICOLON]
|
parseStatement [IDENTIFIER "foo",LBRACE,RBRACE,SEMICOLON]
|
||||||
|
testStatementConstructorCall = TestCase $
|
||||||
|
assertEqual "expect constructor call" [StatementExpressionStatement (ConstructorCall "Foo" [])] $
|
||||||
|
parseStatement [NEW,IDENTIFIER "Foo",LBRACE,RBRACE,SEMICOLON]
|
||||||
|
testStatementConstructorCallWithArgs = TestCase $
|
||||||
|
assertEqual "expect constructor call" [StatementExpressionStatement (ConstructorCall "Foo" [Reference "b"])] $
|
||||||
|
parseStatement [NEW,IDENTIFIER "Foo",LBRACE,IDENTIFIER "b",RBRACE,SEMICOLON]
|
||||||
|
|
||||||
|
testStatementPreIncrement = TestCase $
|
||||||
|
assertEqual "expect increment" [StatementExpressionStatement $ PostIncrement $ Reference "a"] $
|
||||||
|
parseStatement [IDENTIFIER "a",INCREMENT,SEMICOLON]
|
||||||
|
|
||||||
|
|
||||||
tests = TestList [
|
tests = TestList [
|
||||||
@ -279,9 +291,13 @@ tests = TestList [
|
|||||||
testExpressionFieldAccess,
|
testExpressionFieldAccess,
|
||||||
testExpressionSimpleFieldAccess,
|
testExpressionSimpleFieldAccess,
|
||||||
testExpressionFieldSubAccess,
|
testExpressionFieldSubAccess,
|
||||||
|
testExpressionConstructorCall,
|
||||||
testStatementIfThen,
|
testStatementIfThen,
|
||||||
testStatementIfThenElse,
|
testStatementIfThenElse,
|
||||||
testStatementWhile,
|
testStatementWhile,
|
||||||
testStatementAssign,
|
testStatementAssign,
|
||||||
testStatementMethodCallNoParams
|
testStatementMethodCallNoParams,
|
||||||
|
testStatementConstructorCall,
|
||||||
|
testStatementConstructorCallWithArgs,
|
||||||
|
testStatementIncrement
|
||||||
]
|
]
|
@ -117,7 +117,7 @@ modifier : PUBLIC { }
|
|||||||
| STATIC { }
|
| STATIC { }
|
||||||
| ABSTRACT { }
|
| ABSTRACT { }
|
||||||
|
|
||||||
classtype : classorinterfacetype{ }
|
classtype : classorinterfacetype { $1 }
|
||||||
|
|
||||||
classbodydeclaration : classmemberdeclaration { $1 }
|
classbodydeclaration : classmemberdeclaration { $1 }
|
||||||
| constructordeclaration { $1 }
|
| constructordeclaration { $1 }
|
||||||
@ -249,12 +249,12 @@ assignment : lefthandside assignmentoperator assignmentexpression {
|
|||||||
|
|
||||||
|
|
||||||
statementexpression : assignment { $1 }
|
statementexpression : assignment { $1 }
|
||||||
-- | preincrementexpression { }
|
| preincrementexpression { $1 }
|
||||||
-- | predecrementexpression { }
|
| predecrementexpression { $1 }
|
||||||
-- | postincrementexpression { }
|
| postincrementexpression { $1 }
|
||||||
-- | postdecrementexpression { }
|
| postdecrementexpression { $1 }
|
||||||
| methodinvocation { $1 }
|
| methodinvocation { $1 }
|
||||||
-- | classinstancecreationexpression { }
|
| classinstancecreationexpression { $1 }
|
||||||
|
|
||||||
ifthenelsestatementnoshortif :IF LBRACE expression RBRACE statementnoshortif
|
ifthenelsestatementnoshortif :IF LBRACE expression RBRACE statementnoshortif
|
||||||
ELSE statementnoshortif { }
|
ELSE statementnoshortif { }
|
||||||
@ -292,8 +292,8 @@ methodinvocation : simplename LBRACE RBRACE { MethodCall (Reference "this") $
|
|||||||
| primary DOT IDENTIFIER LBRACE RBRACE { MethodCall $1 $3 [] }
|
| primary DOT IDENTIFIER LBRACE RBRACE { MethodCall $1 $3 [] }
|
||||||
| primary DOT IDENTIFIER LBRACE argumentlist RBRACE { MethodCall $1 $3 $5 }
|
| primary DOT IDENTIFIER LBRACE argumentlist RBRACE { MethodCall $1 $3 $5 }
|
||||||
|
|
||||||
classinstancecreationexpression : NEW classtype LBRACE RBRACE { }
|
classinstancecreationexpression : NEW classtype LBRACE RBRACE { ConstructorCall $2 [] }
|
||||||
| NEW classtype LBRACE argumentlist RBRACE { }
|
| NEW classtype LBRACE argumentlist RBRACE { ConstructorCall $2 $4 }
|
||||||
|
|
||||||
conditionalandexpression : inclusiveorexpression { $1 }
|
conditionalandexpression : inclusiveorexpression { $1 }
|
||||||
|
|
||||||
@ -318,7 +318,7 @@ inclusiveorexpression : exclusiveorexpression { $1 }
|
|||||||
primarynonewarray : literal { $1 }
|
primarynonewarray : literal { $1 }
|
||||||
| THIS { Reference "this" }
|
| THIS { Reference "this" }
|
||||||
| LBRACE expression RBRACE { $2 }
|
| LBRACE expression RBRACE { $2 }
|
||||||
-- | classinstancecreationexpression { }
|
| classinstancecreationexpression { StatementExpressionExpression $1 }
|
||||||
| fieldaccess { $1 }
|
| fieldaccess { $1 }
|
||||||
| methodinvocation { StatementExpressionExpression $1 }
|
| methodinvocation { StatementExpressionExpression $1 }
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ tokens :-
|
|||||||
-- end keywords
|
-- end keywords
|
||||||
$JavaLetter$JavaLetterOrDigit* { \s -> IDENTIFIER s }
|
$JavaLetter$JavaLetterOrDigit* { \s -> IDENTIFIER s }
|
||||||
-- Literals
|
-- Literals
|
||||||
[1-9]([0-9\_]*[0-9])* { \s -> case readMaybe $ filter ((/=) '_') s of Just a -> INTEGERLITERAL a; Nothing -> error ("failed to parse INTLITERAL " ++ s) }
|
[0-9]([0-9\_]*[0-9])* { \s -> case readMaybe $ filter ((/=) '_') s of Just a -> INTEGERLITERAL a; Nothing -> error ("failed to parse INTLITERAL " ++ s) }
|
||||||
"'"."'" { \s -> case (s) of _ : c : _ -> CHARLITERAL c; _ -> error ("failed to parse CHARLITERAL " ++ s) }
|
"'"."'" { \s -> case (s) of _ : c : _ -> CHARLITERAL c; _ -> error ("failed to parse CHARLITERAL " ++ s) }
|
||||||
-- separators
|
-- separators
|
||||||
"(" { \_ -> LBRACE }
|
"(" { \_ -> LBRACE }
|
||||||
|
Loading…
Reference in New Issue
Block a user