mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-02 12:50:55 +00:00
introduce impork, workload as cute import aliases (#10)
Co-authored-by: Violet White <violet.white.dammit@protonmail.com> Co-authored-by: Violet White <violet.white@espeon.social>
This commit is contained in:
parent
63e7203db9
commit
aadc8282a5
@ -55,7 +55,7 @@ enum class TokenType(vararg properties: TokenTypeProperty) {
|
||||
In(ManyChars("in"), KeywordFamily),
|
||||
Continue(ManyChars("continue"), KeywordFamily),
|
||||
Break(ManyChars("break"), KeywordFamily),
|
||||
Import(ManyChars("import"), KeywordFamily),
|
||||
Import(AnyOf("import", "impork", "porkload"), KeywordFamily),
|
||||
Export(ManyChars("export"), KeywordFamily),
|
||||
Func(ManyChars("func"), KeywordFamily),
|
||||
Native(ManyChars("native"), KeywordFamily),
|
||||
@ -70,6 +70,8 @@ enum class TokenType(vararg properties: TokenTypeProperty) {
|
||||
properties.filterIsInstance<Promotion>()
|
||||
val manyChars: ManyChars? =
|
||||
properties.filterIsInstance<ManyChars>().singleOrNull()
|
||||
val anyOf: AnyOf? =
|
||||
properties.filterIsInstance<AnyOf>().singleOrNull()
|
||||
val singleChar: SingleChar? =
|
||||
properties.filterIsInstance<SingleChar>().singleOrNull()
|
||||
val family: TokenFamily =
|
||||
@ -81,6 +83,7 @@ enum class TokenType(vararg properties: TokenTypeProperty) {
|
||||
properties.filterIsInstance<TokenUpgrader>().singleOrNull()
|
||||
|
||||
companion object {
|
||||
val AnyOf = entries.filter { item -> item.anyOf != null }
|
||||
val ManyChars = entries.filter { item -> item.manyChars != null }
|
||||
val SingleChars = entries.filter { item -> item.singleChar != null }
|
||||
val CharConsumers = entries.filter { item ->
|
||||
|
@ -4,6 +4,7 @@ interface TokenTypeProperty {
|
||||
class SingleChar(val char: Char) : TokenTypeProperty
|
||||
class Promotion(val nextChar: Char, val type: TokenType) : TokenTypeProperty
|
||||
class ManyChars(val text: String) : TokenTypeProperty
|
||||
class AnyOf(vararg val strings: String): TokenTypeProperty
|
||||
class CharConsumer(val isValid: (Char) -> Boolean) : TokenTypeProperty
|
||||
class CharIndexConsumer(val isValid: (Char, Int) -> Boolean) : TokenTypeProperty
|
||||
open class TokenUpgrader(val maybeUpgrade: (Token) -> Token?) : TokenTypeProperty
|
||||
@ -16,6 +17,15 @@ interface TokenTypeProperty {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (upgraded == null) {
|
||||
for (item in TokenType.AnyOf) {
|
||||
if (item.anyOf != null && item.anyOf.strings.contains(token.text)) {
|
||||
upgraded = Token(item, token.start, token.text)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
upgraded
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user