-
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 parsing of ArrayOfTables (#100)
### What's done: - Small refactoring related to sealed classes limitations - Initial test implemetation of parking for array of tables - Kotlin update to 1.6.10
- Loading branch information
Showing
40 changed files
with
603 additions
and
318 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
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
65 changes: 65 additions & 0 deletions
65
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,65 @@ | ||
/** | ||
* Array of tables https://toml.io/en/v1.0.0#array-of-tables | ||
*/ | ||
|
||
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 | ||
|
||
/** | ||
* @property isSynthetic | ||
*/ | ||
// 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 | ||
|
||
// short table name (only the name without parental prefix, like a - it is used in decoder and encoder) | ||
override val name: String | ||
|
||
// 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 | ||
|
||
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] } | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* This class is used to store elements of array of tables (bucket for key-value records) | ||
*/ | ||
public class TomlArrayOfTablesElement(lineNo: Int, config: TomlConfig = TomlConfig()) : TomlNode( | ||
EMPTY_TECHNICAL_NODE, | ||
lineNo, | ||
config | ||
) { | ||
override val name: String = EMPTY_TECHNICAL_NODE | ||
} |
18 changes: 18 additions & 0 deletions
18
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,18 @@ | ||
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
Oops, something went wrong.