Skip to content

Commit

Permalink
Add number as primitive type
Browse files Browse the repository at this point in the history
  • Loading branch information
wilmveel committed Nov 11, 2023
1 parent 2e19d5a commit 9160f98
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class JavaEmitter(
is Reference.Primitive -> when (type) {
Reference.Primitive.Type.String -> "String"
Reference.Primitive.Type.Integer -> "Integer"
Reference.Primitive.Type.Number -> "Double"
Reference.Primitive.Type.Boolean -> "Boolean"
}
}.sanitizeSymbol()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class KotlinEmitter(
is Reference.Primitive -> when (type) {
Reference.Primitive.Type.String -> "String"
Reference.Primitive.Type.Integer -> "Int"
Reference.Primitive.Type.Number -> "Double"
Reference.Primitive.Type.Boolean -> "Boolean"
}
}.sanitizeSymbol()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ScalaEmitter(
is Reference.Primitive -> when (type) {
Reference.Primitive.Type.String -> "String"
Reference.Primitive.Type.Integer -> "Int"
Reference.Primitive.Type.Number -> "Double"
Reference.Primitive.Type.Boolean -> "Boolean"
}
}.let { if (isIterable) "List[$it]" else it }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class TypeScriptEmitter(logger: Logger = noLogger) : Emitter(logger) {
is Reference.Primitive -> when (type) {
Reference.Primitive.Type.String -> "string"
Reference.Primitive.Type.Integer -> "number"
Reference.Primitive.Type.Number -> "number"
Reference.Primitive.Type.Boolean -> "boolean"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class WirespecEmitter(logger: Logger = noLogger) : Emitter(logger) {
is Reference.Primitive -> when (type) {
Reference.Primitive.Type.String -> "String"
Reference.Primitive.Type.Integer -> "Integer"
Reference.Primitive.Type.Number -> "Number"
Reference.Primitive.Type.Boolean -> "Boolean"
}
}.let { if (isIterable) "$it[]" else it }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import community.flock.wirespec.compiler.core.tokenize.types.TRACE
import community.flock.wirespec.compiler.core.tokenize.types.WirespecType
import community.flock.wirespec.compiler.core.tokenize.types.WsBoolean
import community.flock.wirespec.compiler.core.tokenize.types.WsInteger
import community.flock.wirespec.compiler.core.tokenize.types.WsNumber
import community.flock.wirespec.compiler.core.tokenize.types.WsString
import community.flock.wirespec.compiler.utils.Logger

Expand Down Expand Up @@ -131,6 +132,7 @@ class EndpointParser(logger: Logger) : AbstractParser(logger) {
is WsString -> Primitive(Primitive.Type.String, isIterable)

is WsInteger -> Primitive(Primitive.Type.Integer, isIterable)
is WsNumber -> Primitive(Primitive.Type.Number, isIterable)

is WsBoolean -> Primitive(Primitive.Type.Boolean, isIterable)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import community.flock.wirespec.compiler.core.tokenize.types.RightCurly
import community.flock.wirespec.compiler.core.tokenize.types.WirespecType
import community.flock.wirespec.compiler.core.tokenize.types.WsBoolean
import community.flock.wirespec.compiler.core.tokenize.types.WsInteger
import community.flock.wirespec.compiler.core.tokenize.types.WsNumber
import community.flock.wirespec.compiler.core.tokenize.types.WsString
import community.flock.wirespec.compiler.utils.Logger

Expand Down Expand Up @@ -96,6 +97,11 @@ class TypeParser(logger: Logger) : AbstractParser(logger) {
isIterable
)

is WsNumber -> Type.Shape.Field.Reference.Primitive(
Type.Shape.Field.Reference.Primitive.Type.Number,
isIterable
)

is WsBoolean -> Type.Shape.Field.Reference.Primitive(
Type.Shape.Field.Reference.Primitive.Type.Boolean,
isIterable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data class Type(val name: String, val shape: Shape) : Definition {
override val isIterable: Boolean,
override val isMap: Boolean = false
) : Reference {
enum class Type { String, Integer, Boolean }
enum class Type { String, Integer, Number, Boolean }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ data object WsEndpointDef : WirespecDefinition
sealed interface WirespecType : Keyword
data object WsString : WirespecType
data object WsInteger : WirespecType
data object WsNumber : WirespecType
data object WsBoolean : WirespecType
data object CustomType : WirespecType

Expand Down
2 changes: 2 additions & 0 deletions src/lsp/intellij-plugin/src/main/kotlin/Lexer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import community.flock.wirespec.compiler.core.tokenize.types.WsBoolean
import community.flock.wirespec.compiler.core.tokenize.types.WsEndpointDef
import community.flock.wirespec.compiler.core.tokenize.types.WsEnumTypeDef
import community.flock.wirespec.compiler.core.tokenize.types.WsInteger
import community.flock.wirespec.compiler.core.tokenize.types.WsNumber
import community.flock.wirespec.compiler.core.tokenize.types.WsRefinedTypeDef
import community.flock.wirespec.compiler.core.tokenize.types.WsString
import community.flock.wirespec.compiler.core.tokenize.types.WsTypeDef
Expand Down Expand Up @@ -59,6 +60,7 @@ class Lexer : IntellijLexer() {
is CustomType -> Types.CUSTOM_TYPE
is WsBoolean -> Types.BOOLEAN
is WsInteger -> Types.INTEGER
is WsNumber -> Types.NUMBER
is WsString -> Types.STRING
is LeftCurly -> Types.LEFT_CURLY
is QuestionMark -> Types.QUESTION_MARK
Expand Down
1 change: 1 addition & 0 deletions src/lsp/intellij-plugin/src/main/kotlin/Types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface Types {
val CUSTOM_TYPE = ElementType("CUSTOM_TYPE")
val BOOLEAN = ElementType("BOOLEAN")
val INTEGER = ElementType("INTEGER")
val NUMBER = ElementType("NUMBER")
val STRING = ElementType("STRING")
val TYPE_DEF = ElementType("TYPE_DEF")
val ENUM_DEF = ElementType("ENUM_DEF")
Expand Down
9 changes: 2 additions & 7 deletions src/lsp/node/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class OpenApiParser(private val openApi: SwaggerObject) {
private fun OpenapiType.toPrimitive() = when (this) {
OpenapiType.STRING -> Reference.Primitive.Type.String
OpenapiType.INTEGER -> Reference.Primitive.Type.Integer
OpenapiType.NUMBER -> Reference.Primitive.Type.Integer
OpenapiType.NUMBER -> Reference.Primitive.Type.Number
OpenapiType.BOOLEAN -> Reference.Primitive.Type.Boolean
else -> error("Type is not a primitive")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ class OpenApiParser(private val openApi: OpenAPIObject) {
private fun OpenapiType.toPrimitive() = when (this) {
OpenapiType.STRING -> Primitive.Type.String
OpenapiType.INTEGER -> Primitive.Type.Integer
OpenapiType.NUMBER -> Primitive.Type.Integer
OpenapiType.NUMBER -> Primitive.Type.Number
OpenapiType.BOOLEAN -> Primitive.Type.Boolean
else -> error("Type is not a primitive")
}
Expand Down

0 comments on commit 9160f98

Please sign in to comment.