Skip to content

Commit bbabc75

Browse files
authored
Merge pull request #118 from iamgio/regex-recompile-fix
2 parents c9243df + af7b5a8 commit bbabc75

File tree

8 files changed

+375
-376
lines changed

8 files changed

+375
-376
lines changed

quarkdown-core/src/main/kotlin/com/quarkdown/core/flavor/base/BaseMarkdownFlavor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import com.quarkdown.core.flavor.TreeIteratorFactory
1010
* The vanilla [CommonMark](https://spec.commonmark.org) Markdown with several [GFM](https://github.github.com/gfm) features and extensions.
1111
*/
1212
object BaseMarkdownFlavor : MarkdownFlavor {
13-
override val lexerFactory: LexerFactory = BaseMarkdownLexerFactory()
13+
override val lexerFactory: LexerFactory = BaseMarkdownLexerFactory
1414
override val parserFactory: ParserFactory = BaseMarkdownParserFactory()
1515
override val rendererFactory: RendererFactory = BaseMarkdownRendererFactory
1616
override val treeIteratorFactory: TreeIteratorFactory = BaseMarkdownTreeIteratorFactory()

quarkdown-core/src/main/kotlin/com/quarkdown/core/flavor/base/BaseMarkdownLexerFactory.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ import com.quarkdown.core.lexer.tokens.PlainTextToken
1010
/**
1111
* [BaseMarkdownFlavor] lexer factory.
1212
*/
13-
class BaseMarkdownLexerFactory : LexerFactory {
13+
object BaseMarkdownLexerFactory : LexerFactory {
14+
private val blockPatterns = BaseMarkdownBlockTokenRegexPatterns()
15+
private val inlinePatterns = BaseMarkdownInlineTokenRegexPatterns()
16+
1417
override fun newBlockLexer(source: CharSequence): StandardRegexLexer =
15-
with(BaseMarkdownBlockTokenRegexPatterns()) {
18+
with(blockPatterns) {
1619
StandardRegexLexer(
1720
source,
1821
listOf(
@@ -35,7 +38,7 @@ class BaseMarkdownLexerFactory : LexerFactory {
3538
}
3639

3740
override fun newListLexer(source: CharSequence): StandardRegexLexer =
38-
with(BaseMarkdownBlockTokenRegexPatterns()) {
41+
with(blockPatterns) {
3942
StandardRegexLexer(
4043
source,
4144
listOf(listItem, newline),
@@ -44,7 +47,7 @@ class BaseMarkdownLexerFactory : LexerFactory {
4447

4548
override fun newInlineLexer(source: CharSequence): StandardRegexLexer =
4649
newLinkLabelInlineLexer(source).updatePatterns { patterns ->
47-
with(BaseMarkdownInlineTokenRegexPatterns()) {
50+
with(inlinePatterns) {
4851
listOf(
4952
diamondAutolink,
5053
link,
@@ -55,7 +58,7 @@ class BaseMarkdownLexerFactory : LexerFactory {
5558
}
5659

5760
override fun newLinkLabelInlineLexer(source: CharSequence): StandardRegexLexer =
58-
with(BaseMarkdownInlineTokenRegexPatterns()) {
61+
with(inlinePatterns) {
5962
StandardRegexLexer(
6063
source,
6164
listOf(

quarkdown-core/src/main/kotlin/com/quarkdown/core/flavor/quarkdown/QuarkdownFlavor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import com.quarkdown.core.flavor.TreeIteratorFactory
1717
* And more.
1818
*/
1919
object QuarkdownFlavor : MarkdownFlavor {
20-
override val lexerFactory: LexerFactory = QuarkdownLexerFactory()
20+
override val lexerFactory: LexerFactory = QuarkdownLexerFactory
2121
override val parserFactory: ParserFactory = QuarkdownParserFactory()
2222
override val rendererFactory: RendererFactory = QuarkdownRendererFactory()
2323
override val treeIteratorFactory: TreeIteratorFactory = QuarkdownTreeIteratorFactory()

quarkdown-core/src/main/kotlin/com/quarkdown/core/flavor/quarkdown/QuarkdownLexerFactory.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import com.quarkdown.core.lexer.tokens.PlainTextToken
1111
/**
1212
* [QuarkdownFlavor] lexer factory.
1313
*/
14-
class QuarkdownLexerFactory : LexerFactory {
15-
private val base = BaseMarkdownLexerFactory()
14+
object QuarkdownLexerFactory : LexerFactory {
15+
private val blockPatterns = QuarkdownBlockTokenRegexPatterns()
16+
private val inlinePatterns = QuarkdownInlineTokenRegexPatterns()
17+
private val base = BaseMarkdownLexerFactory
1618

1719
/**
1820
* Inserts patterns of Quarkdown's inline extensions into the base inline lexer (produced by [BaseMarkdownLexerFactory]).
@@ -21,7 +23,7 @@ class QuarkdownLexerFactory : LexerFactory {
2123
private fun StandardRegexLexer.insertInlineExtensions(): Lexer {
2224
// New inline patterns introduced by this flavor on top of the base patterns.
2325
val inlineExtensions =
24-
with(QuarkdownInlineTokenRegexPatterns()) {
26+
with(inlinePatterns) {
2527
listOf(
2628
inlineFunctionCall,
2729
inlineMath,
@@ -36,7 +38,7 @@ class QuarkdownLexerFactory : LexerFactory {
3638
}
3739

3840
override fun newBlockLexer(source: CharSequence): Lexer =
39-
with(QuarkdownBlockTokenRegexPatterns()) {
41+
with(blockPatterns) {
4042
StandardRegexLexer(
4143
source,
4244
listOf(
@@ -72,7 +74,7 @@ class QuarkdownLexerFactory : LexerFactory {
7274
source: CharSequence,
7375
allowBlockFunctionCalls: Boolean,
7476
): Lexer =
75-
with(QuarkdownInlineTokenRegexPatterns()) {
77+
with(inlinePatterns) {
7678
// A function call argument contains textual content (string/number/...)
7779
// and possibly other nested function calls.
7880
StandardRegexLexer(

0 commit comments

Comments
 (0)