Migrate function definition argument parser to Kotlin
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package dsl.ast.model.node
|
||||
|
||||
class OptionalFunctionDefinitionArgumentNode(identifier: Node, type: Node, defaultValue: Node) : Node(3, identifier.position) {
|
||||
val identifier: Node
|
||||
get() = children[0]
|
||||
|
||||
val type: Node
|
||||
get() = children[1]
|
||||
|
||||
val defaultValue: Node
|
||||
get() = children[2]
|
||||
|
||||
init {
|
||||
children[0] = identifier
|
||||
children[1] = type
|
||||
children[2] = defaultValue
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package dsl.ast.model.node
|
||||
|
||||
class RegularFunctionDefinitionArgumentNode(identifier: Node, type: Node, vararg: Node) : Node(3, identifier.position) {
|
||||
val identifier
|
||||
get() = children[0]
|
||||
|
||||
val type
|
||||
get() = children[1]
|
||||
|
||||
val vararg
|
||||
get() = children[2]
|
||||
|
||||
init {
|
||||
children[0] = identifier
|
||||
children[1] = type
|
||||
children[2] = vararg
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package dsl.ast.parser
|
||||
|
||||
import dsl.ast.model.entity.ParserOutput
|
||||
import dsl.ast.model.node.OptionalFunctionDefinitionArgumentNode
|
||||
import dsl.token.model.entity.TokenList
|
||||
import dsl.token.model.enumeration.TokenType
|
||||
|
||||
class OptionalFunctionDefinitionArgumentParser : Parser() {
|
||||
override fun tryToParse(input: TokenList): ParserOutput {
|
||||
return allOf(listOf(
|
||||
SimpleIdentifierParser(),
|
||||
optional(allOf(listOf(
|
||||
terminal(TokenType.COLON),
|
||||
TypeParser()
|
||||
)){ it[1] }),
|
||||
terminal(TokenType.ASSIGN),
|
||||
assert(ExpressionParser(), "expression")
|
||||
)) {
|
||||
OptionalFunctionDefinitionArgumentNode(it[0], it[1], it[3])
|
||||
}.parse(input)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package dsl.ast.parser
|
||||
|
||||
import dsl.ast.model.entity.ParserOutput
|
||||
import dsl.ast.model.node.RegularFunctionDefinitionArgumentNode
|
||||
import dsl.token.model.entity.TokenList
|
||||
import dsl.token.model.enumeration.TokenType
|
||||
|
||||
class RegularFunctionDefinitionArgumentParser : Parser() {
|
||||
override fun tryToParse(input: TokenList): ParserOutput {
|
||||
return allOf(listOf(
|
||||
optional(terminal(TokenType.DOTS)),
|
||||
SimpleIdentifierParser(),
|
||||
optional(allOf(listOf(
|
||||
terminal(TokenType.COLON),
|
||||
TypeParser()
|
||||
)){ it[1] })
|
||||
)) {
|
||||
RegularFunctionDefinitionArgumentNode(it[1], it[2], it[0])
|
||||
}.parse(input)
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ enum class TokenType(val token: String) {
|
||||
PERCENT("%"),
|
||||
ASSIGN("="),
|
||||
ARROW("->"),
|
||||
COLON(":"),
|
||||
COMMA(","),
|
||||
SLASH("/"),
|
||||
MINUS("-"),
|
||||
|
||||
@@ -31,6 +31,7 @@ class DefaultTokenizer : Tokenizer {
|
||||
default(TokenType.ASTERISK),
|
||||
default(TokenType.PERCENT),
|
||||
default(TokenType.ASSIGN),
|
||||
default(TokenType.COLON),
|
||||
default(TokenType.COMMA),
|
||||
default(TokenType.SLASH),
|
||||
default(TokenType.MINUS),
|
||||
|
||||
Reference in New Issue
Block a user