query in Name renamed to index
This commit is contained in:
parent
2aee38793c
commit
d562352a03
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,9 +1,9 @@
|
||||
|
||||
.idea/
|
||||
*.iws
|
||||
*/out/**
|
||||
out/
|
||||
.gradle
|
||||
*/build/**
|
||||
build/
|
||||
|
||||
|
||||
!gradle-wrapper.jar
|
||||
|
@ -40,7 +40,7 @@ allprojects {
|
||||
}
|
||||
|
||||
group = "hep.dataforge"
|
||||
version = "0.1.1-dev-5"
|
||||
version = "0.1.2-dev-1"
|
||||
|
||||
// apply bintray configuration
|
||||
apply(from = "${rootProject.rootDir}/gradle/bintray.gradle")
|
||||
|
@ -80,8 +80,8 @@ fun Meta.getAll(name: Name): Map<String, MetaItem<out Meta>> {
|
||||
val (body, query) = name.last()!!
|
||||
val regex = query.toRegex()
|
||||
return (this[name.cutLast()] as? NodeItem<*>)?.node?.items
|
||||
?.filter { it.key.body == body && (query.isEmpty() || regex.matches(it.key.query)) }
|
||||
?.mapKeys { it.key.query }
|
||||
?.filter { it.key.body == body && (query.isEmpty() || regex.matches(it.key.index)) }
|
||||
?.mapKeys { it.key.index }
|
||||
?: emptyMap()
|
||||
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ fun <M : MutableMeta<M>> M.setIndexed(
|
||||
val tokens = name.tokens.toMutableList()
|
||||
val last = tokens.last()
|
||||
items.forEachIndexed { index, meta ->
|
||||
val indexedToken = NameToken(last.body, last.query + queryFactory(index))
|
||||
val indexedToken = NameToken(last.body, last.index + queryFactory(index))
|
||||
tokens[tokens.lastIndex] = indexedToken
|
||||
set(Name(tokens), meta)
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ package hep.dataforge.names
|
||||
/**
|
||||
* The general interface for working with names.
|
||||
* The name is a dot separated list of strings like `token1.token2.token3`.
|
||||
* Each token could contain additional query in square brackets.
|
||||
* Each token could contain additional index in square brackets.
|
||||
*/
|
||||
inline class Name constructor(val tokens: List<NameToken>) {
|
||||
|
||||
@ -43,21 +43,21 @@ inline class Name constructor(val tokens: List<NameToken>) {
|
||||
/**
|
||||
* A single name token. Body is not allowed to be empty.
|
||||
* Following symbols are prohibited in name tokens: `{}.:\`.
|
||||
* A name token could have appendix in square brackets called *query*
|
||||
* A name token could have appendix in square brackets called *index*
|
||||
*/
|
||||
data class NameToken(val body: String, val query: String = "") {
|
||||
data class NameToken(val body: String, val index: String = "") {
|
||||
|
||||
init {
|
||||
if (body.isEmpty()) error("Syntax error: Name token body is empty")
|
||||
}
|
||||
|
||||
override fun toString(): String = if (hasQuery()) {
|
||||
"$body[$query]"
|
||||
override fun toString(): String = if (hasIndex()) {
|
||||
"$body[$index]"
|
||||
} else {
|
||||
body
|
||||
}
|
||||
|
||||
fun hasQuery() = query.isNotEmpty()
|
||||
fun hasIndex() = index.isNotEmpty()
|
||||
}
|
||||
|
||||
fun String.toName(): Name {
|
||||
@ -84,7 +84,7 @@ fun String.toName(): Name {
|
||||
'[' -> bracketCount++
|
||||
']' -> error("Syntax error: closing bracket ] not have not matching open bracket")
|
||||
else -> {
|
||||
if (queryBuilder.isNotEmpty()) error("Syntax error: only name end and name separator are allowed after query")
|
||||
if (queryBuilder.isNotEmpty()) error("Syntax error: only name end and name separator are allowed after index")
|
||||
bodyBuilder.append(it)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user