Skip to content

Commit

Permalink
feat(go): add parse for parimaryexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 9, 2022
1 parent d1f49a5 commit 3962805
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package chapi.ast.goast

import chapi.ast.antlr.GoParser
import chapi.domain.core.*
import org.antlr.v4.runtime.tree.TerminalNodeImpl

class GoFullIdentListener(var fileName: String) : GoAstListener() {
private var codeContainer: CodeContainer = CodeContainer(FullName = fileName)
Expand Down Expand Up @@ -159,6 +160,22 @@ class GoFullIdentListener(var fileName: String) : GoAstListener() {

is GoParser.PrimaryExprContext -> {
CodeCall(NodeName = child.text)
when(val subchild = child.getChild(1)) {
// primaryExpr '.' IDENTIFIER
is TerminalNodeImpl -> {
// todo: verify child1
val child1 = child.getChild(0)
val identifier = child.getChild(2).text

CodeCall(
NodeName = child1.text,
FunctionName = identifier
)
}
else -> {
CodeCall(NodeName = child.text)
}
}
}

else -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package chapi.ast.goast

import chapi.domain.core.*
import chapi.domain.core.CodeCall
import chapi.domain.core.CodeDataStruct
import chapi.domain.core.CodeFunction
import chapi.domain.core.CodeProperty
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.junit.jupiter.api.Test
Expand All @@ -24,7 +27,8 @@ func main() {
Name = "main", Package = "main",
FunctionCalls = arrayOf(
CodeCall(
NodeName = "fmt.Println",
NodeName = "fmt",
FunctionName = "Println",
Parameters = arrayOf(CodeProperty(TypeValue = "\"hello world\"", TypeType = ""))
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (a *Animal) Move() {
assertEquals(codeFile.DataStructures.size, 1)
assertEquals(codeFile.DataStructures[0].Functions.size, 1)
assertEquals(codeFile.DataStructures[0].Functions[0].FunctionCalls.size, 1)
assertEquals(codeFile.DataStructures[0].Functions[0].FunctionCalls[0].NodeName, "fmt.Println")
assertEquals(codeFile.DataStructures[0].Functions[0].FunctionCalls[0].NodeName, "fmt")
assertEquals(codeFile.DataStructures[0].Functions[0].FunctionCalls[0].Parameters.size, 1)
}

Expand All @@ -215,7 +215,7 @@ func main() {
assertEquals(codeFile.DataStructures.size, 1)
assertEquals(codeFile.DataStructures[0].Functions.size, 1)
assertEquals(codeFile.DataStructures[0].Functions[0].FunctionCalls.size, 1)
assertEquals(codeFile.DataStructures[0].Functions[0].FunctionCalls[0].NodeName, "fmt.Println")
assertEquals(codeFile.DataStructures[0].Functions[0].FunctionCalls[0].NodeName, "fmt")
assertEquals(codeFile.DataStructures[0].Functions[0].FunctionCalls[0].Parameters.size, 1)
}

Expand Down

0 comments on commit 3962805

Please sign in to comment.