Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ class SemanticDataRepository private constructor() {
validatorMap.putAll(ImagePolicyOptionValue.validators)
validatorMap.putAll(CPUWeightOptionValue.validators)
validatorMap.putAll(CPUSharesOptionValue.validators)

validatorMap.putAll(RlimitOptionValue.validators)
// Scopes are not supported since they aren't standard unit files.
fileClassToSectionNameToKeyValuesFromDoc["unit"]?.remove(SCOPE_KEYWORD)
fileClassToSectionToKeyAndValidatorMap["unit"]?.remove(SCOPE_KEYWORD)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues

import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.Validator
import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.grammar.*
import java.util.Optional

class RlimitOptionValue(grammar : Combinator) : GrammarOptionValue("config_parse_rlimit", grammar) {
companion object {

val GENERIC_SEQ =
AlternativeCombinator(
OptionalWhitespacePrefix(FlexibleLiteralChoiceTerminal("infinity")),
OptionalWhitespacePrefix(IntegerTerminal(0, Int.MAX_VALUE)))

val BYTE_SEQ = AlternativeCombinator(
FlexibleLiteralChoiceTerminal("infinity"),
SequenceCombinator(
OptionalWhitespacePrefix(IntegerTerminal(0, Int.MAX_VALUE)),
OptionalWhitespacePrefix(LiteralChoiceTerminal("K", "M", "G", "T", "P", "E"))
),
OptionalWhitespacePrefix(IntegerTerminal(0, Int.MAX_VALUE)))

val TIME_SEQ = AlternativeCombinator(
FlexibleLiteralChoiceTerminal("infinity"),
OneOrMore(
SequenceCombinator(
OptionalWhitespacePrefix(IntegerTerminal(0, Int.MAX_VALUE)),
OptionalWhitespacePrefix(FlexibleLiteralChoiceTerminal("usec", "us", "μs", "msec", "ms", "seconds", "second", "sec", "s", "minutes", "minute", "min", "m", "hours", "hour", "hr", "h", "days", "day", "d", "weeks", "week", "w", "months", "month", "M", "years", "year", "y"))
)
),
OptionalWhitespacePrefix(IntegerTerminal(0, Int.MAX_VALUE))
)

val NICE_SEQ = AlternativeCombinator(
SequenceCombinator(LiteralChoiceTerminal("+", "-"), IntegerTerminal(0, 21)),
OptionalWhitespacePrefix(SequenceCombinator(IntegerTerminal(0, 41))),
)

val COLON = LiteralChoiceTerminal(":")

val BYTE_RLIMIT = SequenceCombinator(AlternativeCombinator(SequenceCombinator(BYTE_SEQ, COLON, BYTE_SEQ), BYTE_SEQ), EOF())
val TIME_RLIMIT = SequenceCombinator(AlternativeCombinator(SequenceCombinator(TIME_SEQ, COLON, TIME_SEQ), TIME_SEQ), EOF())
val GENERIC_RLIMIT = SequenceCombinator(AlternativeCombinator(SequenceCombinator(GENERIC_SEQ, COLON, GENERIC_SEQ), GENERIC_SEQ), EOF())
val NICE_RLIMIT = SequenceCombinator(AlternativeCombinator(SequenceCombinator(NICE_SEQ, COLON, NICE_SEQ), NICE_SEQ), EOF())


val validators = mapOf(
// Exec.LimitCPU, config_parse_rlimit, RLIMIT_CPU, offsetof(Settings, rlimit)
Validator("config_parse_rlimit", "RLIMIT_CPU") to RlimitOptionValue(TIME_RLIMIT),
// Exec.LimitFSIZE, config_parse_rlimit, RLIMIT_FSIZE, offsetof(Settings, rlimit)
Validator("config_parse_rlimit", "RLIMIT_FSIZE") to RlimitOptionValue(BYTE_RLIMIT),
// Exec.LimitDATA, config_parse_rlimit, RLIMIT_DATA, offsetof(Settings, rlimit)
Validator("config_parse_rlimit", "RLIMIT_DATA") to RlimitOptionValue(BYTE_RLIMIT),
// Exec.LimitSTACK, config_parse_rlimit, RLIMIT_STACK, offsetof(Settings, rlimit)
Validator("config_parse_rlimit", "RLIMIT_STACK") to RlimitOptionValue(BYTE_RLIMIT),
// Exec.LimitCORE, config_parse_rlimit, RLIMIT_CORE, offsetof(Settings, rlimit)
Validator("config_parse_rlimit", "RLIMIT_CORE") to RlimitOptionValue(BYTE_RLIMIT),
// Exec.LimitRSS, config_parse_rlimit, RLIMIT_RSS, offsetof(Settings, rlimit)
Validator("config_parse_rlimit", "RLIMIT_RSS") to RlimitOptionValue(BYTE_RLIMIT),
// Exec.LimitNOFILE, config_parse_rlimit, RLIMIT_NOFILE, offsetof(Settings, rlimit)
Validator("config_parse_rlimit", "RLIMIT_NOFILE") to RlimitOptionValue(GENERIC_RLIMIT),
// Exec.LimitAS, config_parse_rlimit, RLIMIT_AS, offsetof(Settings, rlimit)
Validator("config_parse_rlimit", "RLIMIT_AS") to RlimitOptionValue(BYTE_RLIMIT),
// Exec.LimitNPROC, config_parse_rlimit, RLIMIT_NPROC, offsetof(Settings, rlimit)
Validator("config_parse_rlimit", "RLIMIT_NPROC") to RlimitOptionValue(GENERIC_RLIMIT),
// Exec.LimitMEMLOCK, config_parse_rlimit, RLIMIT_MEMLOCK, offsetof(Settings, rlimit)
Validator("config_parse_rlimit", "RLIMIT_MEMLOCK") to RlimitOptionValue(BYTE_RLIMIT),
// Exec.LimitLOCKS, config_parse_rlimit, RLIMIT_LOCKS, offsetof(Settings, rlimit)
Validator("config_parse_rlimit", "RLIMIT_LOCKS") to RlimitOptionValue(GENERIC_RLIMIT),
// Exec.LimitSIGPENDING, config_parse_rlimit, RLIMIT_SIGPENDING, offsetof(Settings, rlimit)
Validator("config_parse_rlimit", "RLIMIT_SIGPENDING") to RlimitOptionValue(GENERIC_RLIMIT),
// Exec.LimitMSGQUEUE, config_parse_rlimit, RLIMIT_MSGQUEUE, offsetof(Settings, rlimit)
Validator("config_parse_rlimit", "RLIMIT_MSGQUEUE") to RlimitOptionValue(BYTE_RLIMIT),
// Exec.LimitNICE, config_parse_rlimit, RLIMIT_NICE, offsetof(Settings, rlimit)
Validator("config_parse_rlimit", "RLIMIT_NICE") to RlimitOptionValue(NICE_RLIMIT),
// Exec.LimitRTPRIO, config_parse_rlimit, RLIMIT_RTPRIO, offsetof(Settings, rlimit)
Validator("config_parse_rlimit", "RLIMIT_RTPRIO") to RlimitOptionValue(GENERIC_RLIMIT),
// Exec.LimitRTTIME, config_parse_rlimit, RLIMIT_RTTIME, offsetof(Settings, rlimit)
Validator("config_parse_rlimit", "RLIMIT_RTTIME") to RlimitOptionValue(TIME_RLIMIT),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kotlin.math.max
/**
* This is a sequence of tokens that must match any of them.
*/
class AlternativeCombinator(vararg val tokens: Combinator) : Combinator {
open class AlternativeCombinator(vararg val tokens: Combinator) : Combinator {

fun match(value: String, offset: Int, f: (Combinator, String, Int) -> MatchResult): MatchResult {

Expand All @@ -20,8 +20,6 @@ class AlternativeCombinator(vararg val tokens: Combinator) : Combinator {
return match
}



if (match.tokens.size > longestTerminalMatch.size) {
longestTerminalMatch = match.terminals
longestTokenMatch = match.tokens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ open class GrammarOptionValue(
}

holder.registerProblem(property.valueNode.psi, "${property.key}'s value does not match the expected format. Possible reasons include unrecognized characters or premature end of input.", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, tr)


return
}

Expand Down Expand Up @@ -96,9 +94,9 @@ open class GrammarOptionValue(
}
}

holder.registerProblem(property.valueNode.psi, "${property.key}'s value is correctly format but seems invalid.", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, tr, *quickFixes.toTypedArray())
holder.registerProblem(property.valueNode.psi, "${property.key}'s value is correctly formatted but seems invalid.", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, tr, *quickFixes.toTypedArray())
} else {
holder.registerProblem(property.valueNode.psi, "${property.key}'s value is correctly format but seems invalid.", ProblemHighlightType.GENERIC_ERROR_OR_WARNING)
holder.registerProblem(property.valueNode.psi, "${property.key}'s value is correctly formatted but seems invalid.", ProblemHighlightType.GENERIC_ERROR_OR_WARNING)
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.grammar

class OptionalWhitespacePrefix(val combinator: Combinator):
AlternativeCombinator(
SequenceCombinator(WhitespaceTerminal(), combinator),
combinator
) {
//
// override fun SyntacticMatch(value: String, offset: Int): MatchResult {
// var newOffset = offset
// for(o in offset..<value.length) {
// if (value[o].isWhitespace()) {
// newOffset = o + 1
// } else {
// break
// }
// }
//
// return combinator.SyntacticMatch(value, newOffset)
// }
//
// override fun SemanticMatch(value: String, offset: Int): MatchResult {
// var newOffset = offset
// for(o in offset..<value.length) {
// if (value[o].isWhitespace()) {
// newOffset = o + 1
// } else {
// break
// }
// }
//
// return combinator.SemanticMatch(value, newOffset)
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kotlin.math.max
/**
* This is a sequence of tokens that must match all of them.
*/
class SequenceCombinator(vararg val tokens: Combinator) : Combinator {
open class SequenceCombinator(vararg val tokens: Combinator) : Combinator {

override fun SyntacticMatch(value: String, offset: Int): MatchResult {
var index = offset
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.grammar

class WhitespaceTerminal : TerminalCombinator {

private fun match(value: String, offset: Int): MatchResult {
var newOffset = offset
for (o in offset until value.length) {
if (value[o].isWhitespace()) {
newOffset = o + 1
} else {
break
}
}

if (newOffset == offset) {
return NoMatch.copy(longestMatch = offset)
}

return MatchResult(listOf(value.substring(offset, newOffset)), newOffset, listOf(this), newOffset)
}

override fun SyntacticMatch(value: String, offset: Int): MatchResult {
return match(value, offset)
}

override fun SemanticMatch(value: String, offset: Int): MatchResult {
return match(value, offset)
}
}
Loading
Loading