Skip to content
This repository was archived by the owner on Dec 24, 2021. It is now read-only.

Commit 202ee13

Browse files
committed
Remove musc stuff
1 parent 65545af commit 202ee13

File tree

9 files changed

+43
-153
lines changed

9 files changed

+43
-153
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.github.skriptinsight
2+
3+
import io.github.skriptinsight.file.SkriptFile
4+
import io.github.skriptinsight.file.node.SkriptNode
5+
import io.github.skriptinsight.file.node.indentation.computeIndentationLevelsForNode
6+
7+
fun SkriptFile.printStructuralTree(): String {
8+
return buildString {
9+
val fileRootNodes = rootNodes
10+
val indentationLevels =
11+
computeIndentationLevelsForNode(nodes.values)
12+
13+
fileRootNodes.forEach { it.printNodeChildren(this, indentationLevels) }
14+
}
15+
}
16+
17+
private fun SkriptNode.printNodeChildren(sb: StringBuilder, indentationLevels: List<Int>) {
18+
sb.apply {
19+
val parentSpace = parent?.normalizedIndentCount?.plus(1) ?: 0
20+
append(" ".repeat(parentSpace))
21+
22+
val dashAmount = (normalizedIndentCount - parentSpace).coerceAtLeast(0)
23+
if (dashAmount != 0)
24+
append('|')
25+
append("-".repeat(dashAmount))
26+
27+
append(content)
28+
append(comment)
29+
append(System.lineSeparator())
30+
31+
children?.forEach { it.printNodeChildren(this, indentationLevels) }
32+
}
33+
}

skriptinsight-core/src/main/kotlin/io/github/skriptinsight/SyntaxFacts.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object SyntaxFacts {
3131

3232
@Language("Regexp")
3333
val varRegex =
34-
("((the )?var(iable)? )?\\{([^{}]|%\\{|\\}%)+\\}")
34+
("(?<varprefix>(?<theprefix>the )?var(?<iableprefix>iable)? )?\\{((?:[^{}]|%\\{|}%)+)}")
3535

3636
@Language("Regexp")
3737
val lineRegex = "^((?:[^#]|##)*)(\\s*#(?!#).*)$"
@@ -48,7 +48,7 @@ object SyntaxFacts {
4848
("<\\s*(?:(.+?)\\s*:\\s*)?(.+?)\\s*(?:=\\s*($wildcard))?\\s*>")
4949

5050
@Language("Regexp")
51-
val linkRegex = ("[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)")
51+
val linkRegex = ("[-a-zA-Z0-9@:%._+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_+.~#?&/=]*)")
5252

5353

5454
}

skriptinsight-core/src/main/kotlin/io/github/skriptinsight/editing/MatchContext.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@ package io.github.skriptinsight.editing
33
import java.util.regex.MatchResult
44
import java.util.regex.Matcher
55

6-
data class MatchContext(val matcher: Matcher, val matchResult: MatchResult, internal val indentCount: Int, internal val lineNumber: Int)
6+
data class MatchContext(
7+
val matcher: Matcher,
8+
val matchResult: MatchResult,
9+
internal val indentCount: Int,
10+
internal val lineNumber: Int
11+
) {
12+
13+
}

skriptinsight-tokens/src/main/kotlin/io/github/skriptinsight/SkriptFileExtensions.kt

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,6 @@ import io.github.skriptinsight.file.node.SkriptNode
55
import io.github.skriptinsight.file.node.indentation.computeIndentationLevelsForNode
66
import io.github.skriptinsight.tokens.TokenizedModel
77

8-
fun SkriptFile.printStructuralTree(): String {
9-
return buildString {
10-
val fileRootNodes = rootNodes
11-
val indentationLevels =
12-
computeIndentationLevelsForNode(nodes.values)
13-
14-
fileRootNodes.forEach { it.printNodeChildren(this, indentationLevels) }
15-
}
16-
}
17-
18-
private fun SkriptNode.printNodeChildren(sb: StringBuilder, indentationLevels: List<Int>) {
19-
sb.apply {
20-
val parentSpace = parent?.normalizedIndentCount?.plus(1) ?: 0
21-
append(" ".repeat(parentSpace))
22-
23-
val dashAmount = (normalizedIndentCount - parentSpace).coerceAtLeast(0)
24-
if (dashAmount != 0)
25-
append('|')
26-
append("-".repeat(dashAmount))
27-
28-
append(content)
29-
append(comment)
30-
append(System.lineSeparator())
31-
32-
children?.forEach { it.printNodeChildren(this, indentationLevels) }
33-
}
34-
}
35-
368
var SkriptFile.tokenizedModel: TokenizedModel
379
get() {
3810
return this[this::tokenizedModel] ?: TokenizedModel(this).also { tokenizedModel = it }

skriptinsight-tokens/src/main/kotlin/io/github/skriptinsight/tokens/impl/FunctionCallToken.kt

Lines changed: 0 additions & 20 deletions
This file was deleted.

skriptinsight-tokens/src/main/kotlin/io/github/skriptinsight/tokens/impl/StringToken.kt

Lines changed: 0 additions & 30 deletions
This file was deleted.

skriptinsight-tokens/src/main/kotlin/io/github/skriptinsight/tokens/impl/WhitespaceToken.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.

skriptinsight-tokens/src/main/kotlin/io/github/skriptinsight/tokens/impl/WordToken.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.

skriptinsight-tokens/src/main/kotlin/io/github/skriptinsight/tokens/work/impl/NodeTokenizeProcess.kt

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,13 @@
11
package io.github.skriptinsight.tokens.work.impl
22

3-
import io.github.skriptinsight.SyntaxFacts.functionCallRegex
4-
import io.github.skriptinsight.SyntaxFacts.stringMatcher
5-
import io.github.skriptinsight.SyntaxFacts.whitespaceRegex
6-
import io.github.skriptinsight.editing.extensions.getGroupRange
7-
import io.github.skriptinsight.editing.location.Range
83
import io.github.skriptinsight.file.SkriptFile
9-
import io.github.skriptinsight.editing.MatchContext
104
import io.github.skriptinsight.tokens.SkriptNodeToken
115
import io.github.skriptinsight.tokens.SkriptToken
12-
import io.github.skriptinsight.tokens.impl.FunctionCallToken
13-
import io.github.skriptinsight.tokens.impl.StringToken
14-
import io.github.skriptinsight.tokens.impl.WhitespaceToken
156
import io.github.skriptinsight.tokens.work.TokenizedModelProcess
167
import io.github.skriptinsight.tokens.work.TokenizedModelProcessData
17-
import org.intellij.lang.annotations.Language
18-
import java.util.regex.Pattern
198

209
object NodeTokenizeProcess : TokenizedModelProcess<SkriptNodeToken>() {
2110

22-
private val tokenDefinitions: MutableList<Pair<Pattern, TokenCompute>> = mutableListOf()
23-
24-
private fun <R : SkriptToken> token(
25-
pattern: Pattern,
26-
creator: TokenCompute
27-
) {
28-
tokenDefinitions.add(pattern to creator)
29-
}
30-
31-
private fun <R : SkriptToken> token(
32-
@Language("RegExp") pattern: String,
33-
creator: (SkriptFile, Range, String, MatchContext) -> SkriptToken
34-
) {
35-
token<R>(Pattern.compile(pattern), creator)
36-
}
37-
38-
init {
39-
token<StringToken>(functionCallRegex) { skriptFile, range, rawContent, matchResult ->
40-
FunctionCallToken(matchResult)
41-
}
42-
token<StringToken>(stringMatcher) { skriptFile, range, rawContent, matchResult ->
43-
StringToken(matchResult.matchResult.group(1))
44-
}
45-
token<WhitespaceToken>(whitespaceRegex) { skriptFile, range, rawContent, _ ->
46-
WhitespaceToken()
47-
}
48-
}
49-
5011
override fun doWork(
5112
file: SkriptFile,
5213
lineNumber: Int,
@@ -58,28 +19,6 @@ object NodeTokenizeProcess : TokenizedModelProcess<SkriptNodeToken>() {
5819
val node = file[lineNumber] ?: return outToken
5920
val content = node.rawContent
6021

61-
tokenDefinitions.forEach { (pattern, tokenComputeInstance) ->
62-
63-
val matcher = pattern.matcher(content)
64-
65-
while (matcher.find()) {
66-
val indentCount = node.indentCount
67-
val matchRange = matcher.getGroupRange(matcher.groupCount(), indentCount, lineNumber)
68-
//If this node isn't within a previously matched token, add it
69-
if (tokens.none { t -> t.range.contains(matchRange) }) {
70-
val matchResult = matcher.toMatchResult()
71-
val rawMatchContent = matcher.group()
72-
tokens.add(
73-
tokenComputeInstance.invoke(
74-
file,
75-
matchRange,
76-
rawMatchContent,
77-
MatchContext(matcher, matchResult, indentCount, lineNumber)
78-
).also { it.setupToken(matchRange, rawMatchContent, file) }
79-
)
80-
}
81-
}
82-
}
8322

8423
return outToken
8524
}

0 commit comments

Comments
 (0)