mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
Refactor.
This commit is contained in:
parent
ff29413bb8
commit
c7e3d62228
1 changed files with 8 additions and 4 deletions
|
@ -24,6 +24,12 @@ class Profiles(val context: KobaltContext) {
|
||||||
return BuildFiles.SplitBuildFile(imports, code, containsProfiles)
|
return BuildFiles.SplitBuildFile(imports, code, containsProfiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Matches the new syntax: val debug by profile() */
|
||||||
|
val NEW_REGEXP = Regex(".*va[rl][ \\t]+([a-zA-Z0-9_]+)[ \\t]*.*profile\\(\\).*")
|
||||||
|
|
||||||
|
/** Matches the deprecated syntax: val debug = false */
|
||||||
|
val OLD_REGEXP = Regex(".*va[rl][ \\t]+([a-zA-Z0-9_]+)[ \\t]*=[ \\t]*[tf][ra][ul][es].*")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the current line matches one of the profiles, turn the declaration into
|
* If the current line matches one of the profiles, turn the declaration into
|
||||||
* val profile = true, otherwise return the same line.
|
* val profile = true, otherwise return the same line.
|
||||||
|
@ -33,10 +39,8 @@ class Profiles(val context: KobaltContext) {
|
||||||
fun correctProfileLine(line: String): Pair<String, Boolean> {
|
fun correctProfileLine(line: String): Pair<String, Boolean> {
|
||||||
var containsProfiles = false
|
var containsProfiles = false
|
||||||
(context.profiles as List<String>).forEach { profile ->
|
(context.profiles as List<String>).forEach { profile ->
|
||||||
val re = Regex(".*va[rl][ \\t]+([a-zA-Z0-9_]+)[ \\t]*.*profile\\(\\).*")
|
val matcher = NEW_REGEXP.matchEntire(line)
|
||||||
val oldRe = Regex(".*va[rl][ \\t]+([a-zA-Z0-9_]+)[ \\t]*=[ \\t]*[tf][ra][ul][es].*")
|
val oldMatcher = OLD_REGEXP.matchEntire(line)
|
||||||
val matcher = re.matchEntire(line)
|
|
||||||
val oldMatcher = oldRe.matchEntire(line)
|
|
||||||
|
|
||||||
fun profileMatch(matcher: MatchResult?) : Pair<Boolean, String?> {
|
fun profileMatch(matcher: MatchResult?) : Pair<Boolean, String?> {
|
||||||
val variable = if (matcher != null) matcher.groups[1]?.value else null
|
val variable = if (matcher != null) matcher.groups[1]?.value else null
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue