Skip to content

Commit

Permalink
Fix failed test cases
Browse files Browse the repository at this point in the history
Signed-off-by: reidspencer <reid.spencer@yoppworks.com>
  • Loading branch information
reid-spencer committed Oct 24, 2023
1 parent d4ba211 commit a6e7e27
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,8 @@ object AST { // extends ast.AbstractDefinitions with ast.Definitions with ast.Op

case class ContextTechnologyOption(loc: At, override val args: Seq[LiteralString]) extends ContextOption("technology")

case class ContextColorOption(loc: At, override val args: Seq[LiteralString]) extends ContextOption("color")

//////////////////////////////////////////////////////////////////// PROCESSOR

sealed abstract class StreamletOption(val name: String) extends OptionValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private[parsing] trait CommonParser extends NoWhiteSpaceParsers {
): P[(At, String, Seq[LiteralString])] = {
P(
location ~ validOptions ~
(Punctuation.roundOpen ~ literalString.rep(0, P(Punctuation.comma)) ~
(Punctuation.roundOpen ~ literalString.rep(0, Punctuation.comma) ~
Punctuation.roundClose).?
).map {
case (loc, opt, Some(maybeArgs)) => (loc, opt, maybeArgs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ private[parsing] trait ContextParser {
Options.gateway,
Options.service,
Options.package_,
Options.technology
Options.technology,
Options.color
).!
) {
case (loc, Options.wrapper, _) => WrapperOption(loc)
case (loc, Options.gateway, _) => GatewayOption(loc)
case (loc, Options.service, _) => ServiceOption(loc)
case (loc, Options.package_, args) => ContextPackageOption(loc, args)
case (loc, Options.technology, args) => ContextTechnologyOption(loc, args)
case (loc, Options.color, args) => ContextColorOption(loc, args)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private[parsing] trait StreamingParser {
maxOutlets: Int = 0
): P[Streamlet] = {
P(
location ~ identifier ~ authorRefs ~ is ~ open ~
location ~ keyword ~ identifier ~ authorRefs ~ is ~ open ~
streamletOptions ~ streamletBody(minInlets, maxInlets, minOutlets, maxOutlets) ~
close ~ briefly ~ description
)./.map { case (loc, id, authors, options, definitions, brief, description) =>
Expand Down Expand Up @@ -162,15 +162,14 @@ private[parsing] trait StreamingParser {
private val MaxStreamlets = 100

def source[u: P]: P[Streamlet] = {
Keywords.source ~/ streamletTemplate(Keywords.source, minOutlets = 1, maxOutlets = 1)
streamletTemplate(Keywords.source, minOutlets = 1, maxOutlets = 1)
}

def sink[u: P]: P[Streamlet] = {
Keywords.sink ~/ streamletTemplate(Keywords.sink, minInlets = 1, maxInlets = 1)
streamletTemplate(Keywords.sink, minInlets = 1, maxInlets = 1)
}

def flow[u: P]: P[Streamlet] = {
Keywords.flow ~/
streamletTemplate(
Keywords.flow,
minInlets = 1,
Expand All @@ -181,8 +180,7 @@ private[parsing] trait StreamingParser {
}

def split[u: P]: P[Streamlet] = {
Keywords.split ~/
streamletTemplate(
streamletTemplate(
Keywords.split,
minInlets = 1,
maxInlets = 1,
Expand All @@ -192,8 +190,7 @@ private[parsing] trait StreamingParser {
}

def merge[u: P]: P[Streamlet] = {
Keywords.merge ~/
streamletTemplate(
streamletTemplate(
Keywords.merge,
minInlets = 2,
maxInlets = MaxStreamlets,
Expand All @@ -203,8 +200,7 @@ private[parsing] trait StreamingParser {
}

def router[u: P]: P[Streamlet] = {
Keywords.router ~/
streamletTemplate(
streamletTemplate(
Keywords.router,
minInlets = 2,
maxInlets = MaxStreamlets,
Expand All @@ -213,7 +209,7 @@ private[parsing] trait StreamingParser {
)
}

def void[u: P]: P[Streamlet] = { Keywords.void ~/ streamletTemplate(Keywords.void) }
def void[u: P]: P[Streamlet] = { streamletTemplate(Keywords.void) }

def streamlet[u: P]: P[Streamlet] =
P(source | flow | sink | merge | split | router | void)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ object Terminals {
final val aggregate = "aggregate"
final val async = "async"
final val available = "available"
final val color = "color"
final val concept = "concept"
final val consistent = "consistent"
final val device = "device"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package com.reactific.riddl.passes.validate
import com.reactific.riddl.language.AST.*
import com.reactific.riddl.language.Messages
import com.reactific.riddl.language.Messages.{Message, MissingWarning, StyleWarning, error, missing}
import com.reactific.riddl.language.parsing.Terminals.Options
import com.reactific.riddl.passes.{Pass, PassInfo, PassInput, PassesOutput}
import com.reactific.riddl.passes.resolve.{ResolutionOutput, ResolutionPass}
import com.reactific.riddl.passes.symbols.{SymbolsOutput, SymbolsPass}
Expand Down Expand Up @@ -592,6 +593,17 @@ case class ValidationPass(
): Unit = {
checkContainer(parents, c)
checkOptions[ContextOption](c.options, c.loc)
c.options.find(_.name == Options.color) match
case Some(option) =>
check(option.args.size == 1, "The 'color' option must have a single value", Messages.Error, option.loc)
option.args.headOption match
case Some(value) =>
val regex = "^([a-z]+)|(#\\p{XDigit}{6})$".r
if !regex.matches(value.s) then
messages.addError(value.loc, "The value of the color option must be a valid HTML color")
case None =>
messages.addError(option.loc, "The color option requires a single value but none provided")
case None =>
checkDescription(c)
}

Expand Down
Loading

0 comments on commit a6e7e27

Please sign in to comment.