Skip to content

Commit 1a053ce

Browse files
committed
refactor: properly name lexers
1 parent 7f5ca72 commit 1a053ce

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

build.gradle.kts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ kotlin {
105105
tasks {
106106
val baseDir = "src/main/kotlin/com/github/lppedd/cc"
107107
val generateLangLexer by registering(GenerateLexerTask::class) {
108-
sourceFile = layout.projectDirectory.file("$baseDir/language/lexer/conventionalCommit.flex")
108+
sourceFile = layout.projectDirectory.file("$baseDir/language/lexer/languageConventionalCommit.flex")
109109
targetOutputDir = layout.projectDirectory.dir("src/main/gen/lang")
110110
purgeOldFiles = true
111111
}
112112

113-
val generateStrictLexer by registering(GenerateLexerTask::class) {
114-
sourceFile = layout.projectDirectory.file("$baseDir/parser/strictConventionalCommit.flex")
115-
targetOutputDir = layout.projectDirectory.dir("src/main/gen/strict")
113+
val generateSpecLexer by registering(GenerateLexerTask::class) {
114+
sourceFile = layout.projectDirectory.file("$baseDir/parser/specConventionalCommit.flex")
115+
targetOutputDir = layout.projectDirectory.dir("src/main/gen/spec")
116116
purgeOldFiles = true
117117
}
118118

@@ -128,7 +128,7 @@ tasks {
128128
sourceSets {
129129
main {
130130
java {
131-
srcDirs(generateLangLexer, generateStrictLexer)
131+
srcDirs(generateLangLexer, generateSpecLexer)
132132
}
133133
}
134134
}

src/main/kotlin/com/github/lppedd/cc/language/lexer/ConventionalCommitLexer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.intellij.lexer.FlexAdapter
55
/**
66
* @author Edoardo Luppi
77
*/
8-
public class ConventionalCommitLexer : FlexAdapter(ConventionalCommitFlexLexer(null)) {
8+
public class ConventionalCommitLexer : FlexAdapter(LanguageConventionalCommitFlexLexer(null)) {
99
override fun getFlex(): EofCapableFlexLexer =
1010
super.getFlex() as EofCapableFlexLexer
1111

src/main/kotlin/com/github/lppedd/cc/language/lexer/conventionalCommit.flex renamed to src/main/kotlin/com/github/lppedd/cc/language/lexer/languageConventionalCommit.flex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.intellij.psi.tree.IElementType;
66

77
%%
88

9-
%class ConventionalCommitFlexLexer
9+
%class LanguageConventionalCommitFlexLexer
1010
%implements EofCapableFlexLexer
1111
%function advance
1212
%type IElementType

src/main/kotlin/com/github/lppedd/cc/parser/ConventionalCommitParser.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ internal fun parseConventionalCommit(message: String, lenient: Boolean = false):
126126
}
127127

128128
private fun createReader(message: String): CCTokenReader {
129-
val lexer = StrictConventionalCommitFlexLexer(null)
130-
lexer.reset(message, 0, message.length, StrictConventionalCommitFlexLexer.YYINITIAL)
129+
val lexer = SpecConventionalCommitFlexLexer(null)
130+
lexer.reset(message, 0, message.length, SpecConventionalCommitFlexLexer.YYINITIAL)
131131
return CCTokenReader(lexer)
132132
}
133133

134-
private class CCTokenReader(private val lexer: StrictConventionalCommitFlexLexer) {
134+
private class CCTokenReader(private val lexer: SpecConventionalCommitFlexLexer) {
135135
var current: CCToken? = lexer.advance()
136136
private set
137137

src/main/kotlin/com/github/lppedd/cc/parser/strictConventionalCommit.flex renamed to src/main/kotlin/com/github/lppedd/cc/parser/specConventionalCommit.flex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.github.lppedd.cc.parser;
22

3-
// Note that while the name includes "strict", the strictness is only related
4-
// to how tokens are looked for: a message is conventional commits compliant
5-
// only if it has at least a type and a subject.
6-
// However, valid characters for tokens are not as restrictive as what the
7-
// specification mandates.
3+
// Note that while the name includes "spec", the lexer does not exactly adhere
4+
// to what the Conventional Commits spec mandates. This lexer *is* stricter
5+
// than the IDE language one, but it still expects cooperation from whatever
6+
// parser is going to consume tokens to actually respect (or not respect)
7+
// the specification.
88

99
%%
1010

11-
%class StrictConventionalCommitFlexLexer
11+
%class SpecConventionalCommitFlexLexer
1212
%type CCToken
1313
%function advance
1414
%public

0 commit comments

Comments
 (0)