-
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 #2 from 7hens/v0.2
V0.2
- Loading branch information
Showing
121 changed files
with
2,693 additions
and
2,092 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
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,5 @@ | ||
# Grule | ||
|
||
## Matcher | ||
|
||
![matcher.svg](matcher.svg) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
package io.grule | ||
|
||
import io.grule.lexer.Lexer | ||
import io.grule.lexer.LexerContext | ||
import io.grule.parser.Parser | ||
|
||
@Suppress("MemberVisibilityCanBePrivate") | ||
open class Grammar : Lexer { | ||
val lexer = Lexer.factory() | ||
val parser = Parser.factory() | ||
|
||
override fun lex(context: LexerContext) { | ||
return lexer.lex(context) | ||
} | ||
|
||
companion object { | ||
inline operator fun <T> invoke(crossinline fn: Grammar.() -> T): T { | ||
return fn(Grammar()) | ||
} | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,75 +1,33 @@ | ||
package io.grule.lexer | ||
|
||
abstract class Lexer { | ||
abstract fun match(charStream: CharStream, offset: Int = 0): Int | ||
|
||
open fun not(): Lexer { | ||
return LexerNot(this) | ||
} | ||
|
||
open operator fun plus(lexer: Lexer): Lexer { | ||
return LexerPlus(mutableListOf(this, lexer)) | ||
} | ||
|
||
operator fun plus(text: String): Lexer { | ||
return plus(LexerString(text)) | ||
} | ||
|
||
operator fun plus(char: Char): Lexer { | ||
return minus(listOf(char)) | ||
} | ||
|
||
operator fun minus(charSet: Iterable<Char>): Lexer { | ||
return plus(LexerCharSet(charSet)) | ||
} | ||
|
||
operator fun minus(charArray: CharArray): Lexer { | ||
return minus(charArray.toList()) | ||
} | ||
|
||
operator fun minus(text: String): Lexer { | ||
return minus(text.toList()) | ||
} | ||
|
||
operator fun div(text: String): Lexer { | ||
return plus(LexerRegex(text)) | ||
} | ||
|
||
open infix fun or(lexer: Lexer): Lexer { | ||
return LexerOr(mutableListOf(this, lexer)) | ||
} | ||
|
||
open fun repeat(minTimes: Int = 0, maxTimes: Int = Int.MAX_VALUE): Lexer { | ||
return LexerRepeat(this, minTimes, maxTimes) | ||
} | ||
|
||
fun join(separator: Lexer, minTimes: Int = 0, maxTimes: Int = Int.MAX_VALUE): Lexer { | ||
val min = maxOf(minTimes - 1, 0) | ||
val max = maxOf(maxTimes - 1, 0) | ||
return (LexerBuilder() + this + separator).untilGreedy(this, min, max) | ||
} | ||
|
||
fun optional(): Lexer { | ||
return repeat(0, 1) | ||
} | ||
|
||
fun interlace(separator: Lexer): Lexer { | ||
return LexerBuilder() + separator.optional() + join(separator) + separator.optional() | ||
} | ||
|
||
fun untilGreedy(terminal: Lexer, minTimes: Int = 0, maxTimes: Int = Int.MAX_VALUE): Lexer { | ||
return LexerUntilGreedy(this, terminal, minTimes, maxTimes) | ||
} | ||
|
||
fun untilNonGreedy(terminal: Lexer, minTimes: Int = 0, maxTimes: Int = Int.MAX_VALUE): Lexer { | ||
return LexerUntilNonGreedy(this, terminal, minTimes, maxTimes) | ||
} | ||
|
||
fun test(): Lexer { | ||
return LexerTest(this) | ||
} | ||
|
||
companion object { | ||
val EOF: Lexer = LexerEOF | ||
} | ||
} | ||
package io.grule.lexer | ||
|
||
import io.grule.node.KeyOwner | ||
import io.grule.token.CharStream | ||
import io.grule.token.TokenStream | ||
import io.grule.token.TokenStreamImpl | ||
|
||
@Suppress("MemberVisibilityCanBePrivate") | ||
interface Lexer : LexerMatcherExt, KeyOwner { | ||
override val key: Any get() = this | ||
|
||
fun lex(context: LexerContext) | ||
|
||
fun tokenStream(charStream: CharStream): TokenStream { | ||
return TokenStreamImpl(charStream, this) | ||
} | ||
|
||
fun tokenStream(text: String): TokenStream { | ||
return tokenStream(CharStream.fromString(text)) | ||
} | ||
|
||
companion object { | ||
val EOF: Lexer = LexerEOF | ||
|
||
fun indent(newLine: Lexer, indent: Lexer, dedent: Lexer): Lexer { | ||
return LexerIndent(newLine, indent, dedent) | ||
} | ||
|
||
fun factory(): LexerFactory { | ||
return LexerFactory() | ||
} | ||
} | ||
} |
Oops, something went wrong.