-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parsing of simple method invocation with arguments
- Loading branch information
1 parent
de7dda9
commit 87947b3
Showing
6 changed files
with
79 additions
and
4 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/com/nurkiewicz/tsclass/parser/ast/expr/MethodCall.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.nurkiewicz.tsclass.parser.ast.expr | ||
|
||
data class MethodCall(val name: String, val parameters: List<Expression>): Expression { | ||
companion object { | ||
|
||
@JvmStatic | ||
fun call(name: String, vararg parameters: Expression): MethodCall { | ||
return MethodCall(name, parameters.toList()) | ||
} | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/com/nurkiewicz/tsclass/parser/visitors/ArgumentListVisitor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.nurkiewicz.tsclass.parser.visitors | ||
|
||
import com.nurkiewicz.tsclass.antlr.parser.TypeScriptBaseVisitor | ||
import com.nurkiewicz.tsclass.antlr.parser.TypeScriptParser | ||
import com.nurkiewicz.tsclass.parser.ast.expr.Expression | ||
|
||
class ArgumentListVisitor: TypeScriptBaseVisitor<List<Expression>>() { | ||
|
||
// override fun visitArgumentList(ctx: TypeScriptParser.ArgumentListContext): List<Expression> { | ||
// println(ctx.text) | ||
// return super.visitArgumentList(ctx) | ||
// } | ||
|
||
override fun defaultResult(): List<Expression> { | ||
return emptyList() | ||
} | ||
|
||
override fun visitAssignmentExpression(ctx: TypeScriptParser.AssignmentExpressionContext): List<Expression> { | ||
println(ctx.text) | ||
return listOf(ctx.accept(ExpressionVisitor())) | ||
} | ||
|
||
override fun aggregateResult(aggregate: List<Expression>, nextResult: List<Expression>): List<Expression> { | ||
return aggregate + nextResult | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/com/nurkiewicz/tsclass/parser/visitors/LeftHandSideExpressionVisitor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.nurkiewicz.tsclass.parser.visitors | ||
|
||
import com.nurkiewicz.tsclass.antlr.parser.TypeScriptBaseVisitor | ||
import com.nurkiewicz.tsclass.antlr.parser.TypeScriptParser | ||
import com.nurkiewicz.tsclass.parser.ast.expr.Expression | ||
import com.nurkiewicz.tsclass.parser.ast.expr.Identifier | ||
import com.nurkiewicz.tsclass.parser.ast.expr.MethodCall | ||
|
||
internal class LeftHandSideExpressionVisitor: TypeScriptBaseVisitor<Expression>() { | ||
|
||
override fun visitLeftHandSideExpression(ctx: TypeScriptParser.LeftHandSideExpressionContext): Expression { | ||
val call = ctx.callExpression() | ||
if (call != null) { | ||
val identifier = call.memberExpression().accept(MemberExpressionVisitor()) as Identifier | ||
val arguments = if (call.arguments() != null) | ||
call.arguments().accept(ArgumentListVisitor()) | ||
else | ||
emptyList() | ||
return MethodCall(identifier.name, arguments) | ||
} else { | ||
return ctx.accept(MemberExpressionVisitor()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters