diff --git a/parser/src/main/kotlin/gay/pizza/pork/parser/TokenType.kt b/parser/src/main/kotlin/gay/pizza/pork/parser/TokenType.kt index ba26b33..fd4fa52 100644 --- a/parser/src/main/kotlin/gay/pizza/pork/parser/TokenType.kt +++ b/parser/src/main/kotlin/gay/pizza/pork/parser/TokenType.kt @@ -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() val manyChars: ManyChars? = properties.filterIsInstance().singleOrNull() + val anyOf: AnyOf? = + properties.filterIsInstance().singleOrNull() val singleChar: SingleChar? = properties.filterIsInstance().singleOrNull() val family: TokenFamily = @@ -81,6 +83,7 @@ enum class TokenType(vararg properties: TokenTypeProperty) { properties.filterIsInstance().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 -> diff --git a/parser/src/main/kotlin/gay/pizza/pork/parser/TokenTypeProperty.kt b/parser/src/main/kotlin/gay/pizza/pork/parser/TokenTypeProperty.kt index 3ab799c..fe0fa62 100644 --- a/parser/src/main/kotlin/gay/pizza/pork/parser/TokenTypeProperty.kt +++ b/parser/src/main/kotlin/gay/pizza/pork/parser/TokenTypeProperty.kt @@ -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 }) }