From beadbcdc3c227f7d8295959d55467f4ce16b2c77 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Fri, 25 Oct 2024 13:51:42 +0800 Subject: [PATCH] refactor(protobuf): extract field construction to function and add extendDef spike TODO #31 --- .../ast/protobuf/ProtobufFullIdentListener.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/chapi-ast-protobuf/src/main/kotlin/chapi/ast/protobuf/ProtobufFullIdentListener.kt b/chapi-ast-protobuf/src/main/kotlin/chapi/ast/protobuf/ProtobufFullIdentListener.kt index 93cce408..d4796e11 100644 --- a/chapi-ast-protobuf/src/main/kotlin/chapi/ast/protobuf/ProtobufFullIdentListener.kt +++ b/chapi-ast-protobuf/src/main/kotlin/chapi/ast/protobuf/ProtobufFullIdentListener.kt @@ -26,6 +26,10 @@ class ProtobufFullIdentListener(var fileName: String) : Protobuf3BaseListener() codeContainer.DataStructures += enumDs } + override fun enterExtendDef(ctx: Protobuf3Parser.ExtendDefContext?) { + /// todo spike for scene + } + private fun constructMessageDef(ctx: Protobuf3Parser.MessageDefContext): CodeDataStruct { val messageName = ctx.messageName().text val codeDataStruct = CodeDataStruct( @@ -38,11 +42,7 @@ class ProtobufFullIdentListener(var fileName: String) : Protobuf3BaseListener() ctx.messageBody().messageElement().map { context -> when (val child = context.getChild(0)) { is Protobuf3Parser.FieldContext -> { - codeDataStruct.Fields += CodeField( - TypeType = child.type_().text, - TypeKey = child.fieldName().text, - TypeValue = child.fieldNumber().text - ) + codeDataStruct.Fields += constructField(child) } is Protobuf3Parser.EnumDefContext -> { @@ -56,7 +56,7 @@ class ProtobufFullIdentListener(var fileName: String) : Protobuf3BaseListener() } is Protobuf3Parser.ExtendDefContext -> { - + // skip } is Protobuf3Parser.OptionStatementContext -> { @@ -83,6 +83,12 @@ class ProtobufFullIdentListener(var fileName: String) : Protobuf3BaseListener() return codeDataStruct } + private fun constructField(child: Protobuf3Parser.FieldContext) = CodeField( + TypeType = child.type_().text, + TypeKey = child.fieldName().text, + TypeValue = child.fieldNumber().text + ) + private fun constructEnum(child: Protobuf3Parser.EnumDefContext): CodeDataStruct { val name = child.enumName().text val enumDs = CodeDataStruct(