Skip to content

Commit

Permalink
refactor(protobuf): extract field construction to function and add ex…
Browse files Browse the repository at this point in the history
…tendDef spike TODO #31
  • Loading branch information
phodal committed Oct 25, 2024
1 parent f856656 commit beadbcd
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 -> {
Expand All @@ -56,7 +56,7 @@ class ProtobufFullIdentListener(var fileName: String) : Protobuf3BaseListener()
}

is Protobuf3Parser.ExtendDefContext -> {

// skip
}

is Protobuf3Parser.OptionStatementContext -> {
Expand All @@ -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(
Expand Down

0 comments on commit beadbcd

Please sign in to comment.