Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree refactoring and basic text writing #90

Merged
merged 12 commits into from
Jan 15, 2022
19 changes: 17 additions & 2 deletions ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/KtomlConf.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
package com.akuleshov7.ktoml

import com.akuleshov7.ktoml.KtomlConf.Indentation.FOUR_SPACES

/**
* @property ignoreUnknownNames - a control to allow/prohibit unknown names during the deserialization
* @property emptyValuesAllowed - a control to allow/prohibit empty values: a = # comment
* @property escapedQuotesInLiteralStringsAllowed - a control to allow/prohibit escaping of single quotes in literal strings
* @property indentation
*/
public data class KtomlConf(
val ignoreUnknownNames: Boolean = false,
val emptyValuesAllowed: Boolean = true,
val escapedQuotesInLiteralStringsAllowed: Boolean = true
)
val escapedQuotesInLiteralStringsAllowed: Boolean = true,
val indentation: Indentation = FOUR_SPACES,
) {
/**
* @property value
*/
public enum class Indentation(public val value: String) {
FOUR_SPACES(" "),
NONE(""),
TAB("\t"),
TWO_SPACES(" "),
;
}
}
14 changes: 11 additions & 3 deletions ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/Toml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ package com.akuleshov7.ktoml
import com.akuleshov7.ktoml.decoders.TomlMainDecoder
import com.akuleshov7.ktoml.exceptions.MissingRequiredFieldException
import com.akuleshov7.ktoml.parsers.TomlParser
import com.akuleshov7.ktoml.parsers.node.TomlFile
import com.akuleshov7.ktoml.tree.TomlFile
import com.akuleshov7.ktoml.writers.TomlWriter

import kotlin.native.concurrent.ThreadLocal
import kotlinx.serialization.*

import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.StringFormat

import kotlinx.serialization.modules.EmptySerializersModule
import kotlinx.serialization.modules.SerializersModule

Expand All @@ -22,8 +28,10 @@ public open class Toml(
private val config: KtomlConf = KtomlConf(),
override val serializersModule: SerializersModule = EmptySerializersModule
) : StringFormat {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you plan to implement encodeToString?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, when an Encoder implementation is completed

// parser is created once after the creation of the class, to reduce the number of created parsers for each toml
// parser and writer are created once after the creation of the class, to reduce
// the number of created parsers and writers for each toml
public val tomlParser: TomlParser = TomlParser(config)
public val tomlWriter: TomlWriter = TomlWriter(config)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add some comment to this writer for newbies?

Copy link
Collaborator Author

@NightEule5 NightEule5 Jan 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Perhaps editing the comment above tomlParser to apply to both the parser and the writer would suffice? Or do you mean description of its function?


// ================== basic overrides ===============

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.akuleshov7.ktoml.decoders

import com.akuleshov7.ktoml.exceptions.IllegalTomlTypeException
import com.akuleshov7.ktoml.exceptions.TomlCastException
import com.akuleshov7.ktoml.parsers.node.TomlKeyValue
import com.akuleshov7.ktoml.tree.TomlKeyValue
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.encoding.AbstractDecoder

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.akuleshov7.ktoml.decoders

import com.akuleshov7.ktoml.KtomlConf
import com.akuleshov7.ktoml.parsers.node.TomlKeyValue
import com.akuleshov7.ktoml.parsers.node.TomlKeyValueArray
import com.akuleshov7.ktoml.parsers.node.TomlKeyValuePrimitive
import com.akuleshov7.ktoml.parsers.node.TomlNull
import com.akuleshov7.ktoml.parsers.node.TomlValue
import com.akuleshov7.ktoml.tree.TomlKeyValue
import com.akuleshov7.ktoml.tree.TomlKeyValueArray
import com.akuleshov7.ktoml.tree.TomlKeyValuePrimitive
import com.akuleshov7.ktoml.tree.TomlNull
import com.akuleshov7.ktoml.tree.TomlValue
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.CompositeDecoder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ package com.akuleshov7.ktoml.decoders

import com.akuleshov7.ktoml.KtomlConf
import com.akuleshov7.ktoml.exceptions.*
import com.akuleshov7.ktoml.parsers.node.*
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
import kotlinx.serialization.modules.*
import com.akuleshov7.ktoml.tree.*
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.elementNames
import kotlinx.serialization.encoding.CompositeDecoder
import kotlinx.serialization.modules.EmptySerializersModule
import kotlinx.serialization.modules.SerializersModule

/**
* Main entry point into the decoding process. It can create less common decoders inside, for example:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.akuleshov7.ktoml.decoders

import com.akuleshov7.ktoml.parsers.node.TomlKeyValue
import com.akuleshov7.ktoml.parsers.node.TomlKeyValuePrimitive
import com.akuleshov7.ktoml.tree.TomlKeyValue
import com.akuleshov7.ktoml.tree.TomlKeyValuePrimitive
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.modules.EmptySerializersModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public sealed class KtomlException(message: String) : Exception(message)

internal class TomlParsingException(message: String, lineNo: Int) : KtomlException("Line $lineNo: $message")

internal class TomlWritingException(message: String) : KtomlException(message)

internal class InternalDecodingException(message: String) : KtomlException(message)

internal class InternalAstException(message: String) : KtomlException(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package com.akuleshov7.ktoml.parsers

import com.akuleshov7.ktoml.KtomlConf
import com.akuleshov7.ktoml.exceptions.InternalAstException
import com.akuleshov7.ktoml.parsers.node.TomlFile
import com.akuleshov7.ktoml.parsers.node.TomlKeyValue
import com.akuleshov7.ktoml.parsers.node.TomlKeyValueArray
import com.akuleshov7.ktoml.parsers.node.TomlKeyValuePrimitive
import com.akuleshov7.ktoml.parsers.node.TomlNode
import com.akuleshov7.ktoml.parsers.node.TomlStubEmptyNode
import com.akuleshov7.ktoml.parsers.node.TomlTable
import com.akuleshov7.ktoml.parsers.node.splitKeyValue
import com.akuleshov7.ktoml.tree.TomlFile
import com.akuleshov7.ktoml.tree.TomlKeyValue
import com.akuleshov7.ktoml.tree.TomlKeyValueArray
import com.akuleshov7.ktoml.tree.TomlKeyValuePrimitive
import com.akuleshov7.ktoml.tree.TomlNode
import com.akuleshov7.ktoml.tree.TomlStubEmptyNode
import com.akuleshov7.ktoml.tree.TomlTable
import com.akuleshov7.ktoml.tree.splitKeyValue

/**
* @property ktomlConf - object that stores configuration options for a parser
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.akuleshov7.ktoml.parsers.node
package com.akuleshov7.ktoml.tree

import com.akuleshov7.ktoml.parsers.splitKeyToTokens
import com.akuleshov7.ktoml.parsers.trimQuotes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.akuleshov7.ktoml.parsers.node
package com.akuleshov7.ktoml.tree

import com.akuleshov7.ktoml.KtomlConf
import com.akuleshov7.ktoml.exceptions.TomlParsingException
Expand Down
Loading