-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from adriantodt/feature/v4
Version 4
- Loading branch information
Showing
29 changed files
with
502 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Module tartar | ||
|
||
A trie-based lexical analysis and pratt-parsing library, | ||
leveraging Kotlin Multiplatform and DSL patterns. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11
src/commonMain/kotlin/com/github/adriantodt/tartar/api/dsl/GrammarFunctionTypes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
package com.github.adriantodt.tartar.api.dsl | ||
|
||
import com.github.adriantodt.tartar.api.parser.ParserContext | ||
import com.github.adriantodt.tartar.api.parser.Token | ||
|
||
/** | ||
* Function used by [GrammarDSL] to configure a | ||
* [Prefix Parselet][com.github.adriantodt.tartar.api.parser.PrefixParselet] | ||
* [Prefix Parselet][com.github.adriantodt.tartar.api.grammar.PrefixParselet] | ||
* in a functional way. | ||
*/ | ||
public typealias PrefixFunction<T, E> = ParserContext<T, E>.(token: Token<T>) -> E | ||
public typealias PrefixFunction<T, K, E> = ParserContext<T, K, E>.(token: K) -> E | ||
|
||
/** | ||
* Function used by [GrammarDSL] to configure a | ||
* [Infix Parselet][com.github.adriantodt.tartar.api.parser.InfixParselet] | ||
* [Infix Parselet][com.github.adriantodt.tartar.api.grammar.InfixParselet] | ||
* in a functional way. | ||
*/ | ||
public typealias InfixFunction<T, E> = ParserContext<T, E>.(left: E, token: Token<T>) -> E | ||
public typealias InfixFunction<T, K, E> = ParserContext<T, K, E>.(left: E, token: K) -> E | ||
|
||
/** | ||
* Function which receives a [LexerDSL] as its receiver. | ||
*/ | ||
public typealias GrammarConfig<T, E> = GrammarDSL<T, E>.() -> Unit | ||
public typealias GrammarConfig<T, K, E> = GrammarDSL<T, K, E>.() -> Unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/commonMain/kotlin/com/github/adriantodt/tartar/api/parser/StringToken.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.github.adriantodt.tartar.api.parser | ||
|
||
import com.github.adriantodt.tartar.api.lexer.Section | ||
|
||
/** | ||
* A subclass of [Token] which holds a [String] as its [value]. | ||
* | ||
* @param T The type of the token. | ||
* @param type The type of the token. | ||
* @param value The value of this token. | ||
* @param section The section of this token. | ||
* @author An Tran, AdrianTodt | ||
* | ||
* @see Token | ||
*/ | ||
public class StringToken<out T>(type: T, public val value: String, section: Section) : Token<T>(type, section) { | ||
/** | ||
* Returns a string representation of the token. | ||
*/ | ||
override fun toString(): String { | ||
if (value.isNotEmpty()) { | ||
return "$type[$value] $section" | ||
} | ||
return super.toString() | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (other == null || this::class != other::class) return false | ||
if (!super.equals(other)) return false | ||
|
||
other as StringToken<*> | ||
|
||
if (value != other.value) return false | ||
|
||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return 31 * super.hashCode() + value.hashCode() | ||
} | ||
} |
Oops, something went wrong.