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/
|
.idea/
|
||||||
*.iws
|
*.iws
|
||||||
*/out/**
|
out/
|
||||||
.gradle
|
.gradle
|
||||||
*/build/**
|
build/
|
||||||
|
|
||||||
|
|
||||||
!gradle-wrapper.jar
|
!gradle-wrapper.jar
|
||||||
|
@ -40,7 +40,7 @@ allprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "hep.dataforge"
|
group = "hep.dataforge"
|
||||||
version = "0.1.1-dev-5"
|
version = "0.1.2-dev-1"
|
||||||
|
|
||||||
// apply bintray configuration
|
// apply bintray configuration
|
||||||
apply(from = "${rootProject.rootDir}/gradle/bintray.gradle")
|
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 (body, query) = name.last()!!
|
||||||
val regex = query.toRegex()
|
val regex = query.toRegex()
|
||||||
return (this[name.cutLast()] as? NodeItem<*>)?.node?.items
|
return (this[name.cutLast()] as? NodeItem<*>)?.node?.items
|
||||||
?.filter { it.key.body == body && (query.isEmpty() || regex.matches(it.key.query)) }
|
?.filter { it.key.body == body && (query.isEmpty() || regex.matches(it.key.index)) }
|
||||||
?.mapKeys { it.key.query }
|
?.mapKeys { it.key.index }
|
||||||
?: emptyMap()
|
?: emptyMap()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ fun <M : MutableMeta<M>> M.setIndexed(
|
|||||||
val tokens = name.tokens.toMutableList()
|
val tokens = name.tokens.toMutableList()
|
||||||
val last = tokens.last()
|
val last = tokens.last()
|
||||||
items.forEachIndexed { index, meta ->
|
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
|
tokens[tokens.lastIndex] = indexedToken
|
||||||
set(Name(tokens), meta)
|
set(Name(tokens), meta)
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ package hep.dataforge.names
|
|||||||
/**
|
/**
|
||||||
* The general interface for working with names.
|
* The general interface for working with names.
|
||||||
* The name is a dot separated list of strings like `token1.token2.token3`.
|
* 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>) {
|
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.
|
* A single name token. Body is not allowed to be empty.
|
||||||
* Following symbols are prohibited in name tokens: `{}.:\`.
|
* 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 {
|
init {
|
||||||
if (body.isEmpty()) error("Syntax error: Name token body is empty")
|
if (body.isEmpty()) error("Syntax error: Name token body is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String = if (hasQuery()) {
|
override fun toString(): String = if (hasIndex()) {
|
||||||
"$body[$query]"
|
"$body[$index]"
|
||||||
} else {
|
} else {
|
||||||
body
|
body
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasQuery() = query.isNotEmpty()
|
fun hasIndex() = index.isNotEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.toName(): Name {
|
fun String.toName(): Name {
|
||||||
@ -84,7 +84,7 @@ fun String.toName(): Name {
|
|||||||
'[' -> bracketCount++
|
'[' -> bracketCount++
|
||||||
']' -> error("Syntax error: closing bracket ] not have not matching open bracket")
|
']' -> error("Syntax error: closing bracket ] not have not matching open bracket")
|
||||||
else -> {
|
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)
|
bodyBuilder.append(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user