-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of ArrayOfTables
### What's done: - Small refactoring related to sealed classes limitations - Initial test impplemetation of array of tables - Kotlin update to 1.6.10
- Loading branch information
Showing
33 changed files
with
482 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/tree/TomlArrayOfTables.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.akuleshov7.ktoml.tree | ||
|
||
import com.akuleshov7.ktoml.TomlConfig | ||
import com.akuleshov7.ktoml.exceptions.ParseException | ||
import com.akuleshov7.ktoml.parsers.splitKeyToTokens | ||
import com.akuleshov7.ktoml.parsers.trimDoubleBrackets | ||
import com.akuleshov7.ktoml.parsers.trimQuotes | ||
|
||
// FixMe: this class is mostly identical to the TomlTable - we should unify them together | ||
public class TomlArrayOfTables( | ||
content: String, | ||
lineNo: Int, | ||
config: TomlConfig = TomlConfig(), | ||
public val isSynthetic: Boolean = false | ||
) : TomlTable(content, lineNo, config) { | ||
public override val type: TableType = TableType.ARRAY | ||
|
||
// list of tables (including sub-tables) that are included in this table (e.g.: {a, a.b, a.b.c} in a.b.c) | ||
public override lateinit var tablesList: List<String> | ||
|
||
// full name of the table (like a.b.c.d) | ||
public override lateinit var fullTableName: String | ||
|
||
// short table name (only the name without parental prefix, like a - it is used in decoder and encoder) | ||
override val name: String | ||
|
||
internal val keyValues: MutableList<MutableList<TomlKeyValue>> = mutableListOf() | ||
|
||
internal fun insertKeyValue(keyValue: TomlKeyValue, isNewElementInArray: Boolean) { | ||
if (isNewElementInArray) { | ||
// creating a new bucket for the array | ||
keyValues.add(mutableListOf(keyValue)) | ||
} else { | ||
// adding new keyValue to the last bucket (it should have been created on the previous step) | ||
keyValues[keyValues.lastIndex].add(keyValue) | ||
} | ||
} | ||
|
||
init { | ||
// getting the content inside brackets ([a.b] -> a.b) | ||
val sectionFromContent = content.trim().trimDoubleBrackets().trim() | ||
|
||
if (sectionFromContent.isBlank()) { | ||
throw ParseException("Incorrect blank name for array of tables: $content", lineNo) | ||
} | ||
|
||
fullTableName = sectionFromContent | ||
|
||
val sectionsList = sectionFromContent.splitKeyToTokens(lineNo) | ||
name = sectionsList.last().trimQuotes() | ||
tablesList = sectionsList.mapIndexed { index, _ -> | ||
(0..index).joinToString(".") { sectionsList[it] } | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/tree/TomlFile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.akuleshov7.ktoml.tree | ||
|
||
import com.akuleshov7.ktoml.TomlConfig | ||
import com.akuleshov7.ktoml.exceptions.InternalAstException | ||
|
||
/** | ||
* A root node for TOML Abstract Syntax Tree | ||
*/ | ||
public class TomlFile(config: TomlConfig = TomlConfig()) : TomlNode( | ||
"rootNode", | ||
0, | ||
config) { | ||
override val name: String = "rootNode" | ||
|
||
override fun getNeighbourNodes(): MutableSet<TomlNode> = | ||
throw InternalAstException("Invalid call to getNeighbourNodes() for TomlFile node") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/tree/TomlKeyValueArray.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.akuleshov7.ktoml.tree | ||
|
||
import com.akuleshov7.ktoml.TomlConfig | ||
|
||
/** | ||
* Class for parsing and storing Array in AST. It receives a pair of two strings as an input and converts it to a pair | ||
* of TomlKey and TomlValue (as TomlArray) | ||
* @property lineNo | ||
* @property key | ||
* @property value | ||
* @property name | ||
*/ | ||
public class TomlKeyValueArray( | ||
override var key: TomlKey, | ||
override val value: TomlValue, | ||
override val lineNo: Int, | ||
override val name: String, | ||
config: TomlConfig = TomlConfig() | ||
) : TomlNode(key, value, lineNo, config), TomlKeyValue { | ||
// adaptor for a string pair of key-value | ||
public constructor( | ||
keyValuePair: Pair<String, String>, | ||
lineNo: Int, | ||
config: TomlConfig = TomlConfig() | ||
) : this( | ||
TomlKey(keyValuePair.first, lineNo), | ||
keyValuePair.second.parseList(lineNo, config), | ||
lineNo, | ||
TomlKey(keyValuePair.first, lineNo).content | ||
) | ||
} |
31 changes: 31 additions & 0 deletions
31
ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/tree/TomlKeyValuePrimitive.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.akuleshov7.ktoml.tree | ||
|
||
import com.akuleshov7.ktoml.TomlConfig | ||
|
||
/** | ||
* class for parsing and storing simple single value types in AST | ||
* @property lineNo | ||
* @property key | ||
* @property value | ||
* @property name | ||
*/ | ||
public class TomlKeyValuePrimitive( | ||
override var key: TomlKey, | ||
override val value: TomlValue, | ||
override val lineNo: Int, | ||
override val name: String, | ||
config: TomlConfig = TomlConfig() | ||
) : TomlNode(key, value, lineNo, config), TomlKeyValue { | ||
// adaptor for a string pair of key-value | ||
public constructor( | ||
keyValuePair: Pair<String, String>, | ||
lineNo: Int, | ||
config: TomlConfig = TomlConfig() | ||
) : this( | ||
TomlKey(keyValuePair.first, lineNo), | ||
keyValuePair.second.parseValue(lineNo, config), | ||
lineNo, | ||
TomlKey(keyValuePair.first, lineNo).content | ||
) | ||
} | ||
|
Oops, something went wrong.