Skip to content

Commit

Permalink
#59, parse "primitive" types
Browse files Browse the repository at this point in the history
  • Loading branch information
hauner committed Sep 24, 2023
1 parent 6b3bd25 commit 08924d9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion openapi-processor-core/src/main/antlr/Mapping.g4
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ annotate
;

anyType
: plainType | targetType
: plainType | primitiveType | targetType
;

plainType
: Plain
;

primitiveType
: Primitive
;

sourceType
: sourceIdentifier (':' formatIdentifier)?
;
Expand Down Expand Up @@ -99,6 +103,7 @@ Arrow: '=>';
Annotate: '@';

Plain: 'plain';
Primitive: 'byte' | 'short' | 'int' | 'long' | 'float' | 'double' | 'boolean' | 'char';
Boolean: 'true' | 'false';
Package: '{package-name}';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class MappingExtractor: MappingBaseListener(), Mapping {
targetType = ctx.text
}

override fun enterPrimitiveType(ctx: MappingParser.PrimitiveTypeContext) {
targetType = ctx.text
}

override fun enterSourceIdentifier(ctx: MappingParser.SourceIdentifierContext) {
sourceType = ctx.text
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,13 @@ class AntlrParserSpec: StringSpec({
mapping.sourceType shouldBe "array"
mapping.targetType shouldBe "plain"
}

"primitive byte array" {
val type = "byte"

val mapping = parseMapping(type)
mapping.kind shouldBe Mapping.Kind.TYPE
mapping.sourceType.shouldBeNull()
mapping.targetType shouldBe "byte"
}
})

0 comments on commit 08924d9

Please sign in to comment.