Skip to content

Commit

Permalink
Various Fixes From Authoring Improving.app (#301)
Browse files Browse the repository at this point in the history
* Remove a require that should be handled in validation

* Validate compound expression types

Make the "info" command print out JVM and OS info

Signed-off-by: reidspencer <reid.spencer@yoppworks.com>

* No change code cleanup

Signed-off-by: reidspencer <reid.spencer@yoppworks.com>

* Fix a location problem that failed a test.

Signed-off-by: reidspencer <reid.spencer@yoppworks.com>

Signed-off-by: reidspencer <reid.spencer@yoppworks.com>
  • Loading branch information
reid-spencer committed Nov 12, 2022
1 parent 81ea095 commit 628260e
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1324,17 +1324,29 @@ object Validation {
Error,
loc
).checkExpressions(operands, defn, parents)
case Comparison(_, _, arg1, arg2) => checkExpression(arg1, defn, parents)
.checkExpression(arg2, defn, parents)
case Comparison(loc, comp, arg1, arg2) =>
checkExpression(arg1, defn, parents)
.checkExpression(arg2, defn, parents).check(
arg1.expressionType.isAssignmentCompatible(arg2.expressionType),
s"Incompatible expression types in ${comp.format} expression",
Messages.Error,
loc
)
case AggregateConstructionExpression(_, pid, args) =>
checkPathRef[Type](pid, defn, parents)()()
.checkArgList(args, defn, parents)
case EntityIdExpression(_, entityRef) =>
checkPathRef[Entity](entityRef, defn, parents)()()
case Ternary(_, condition, expr1, expr2) =>
case Ternary(loc, condition, expr1, expr2) =>
checkExpression(condition, defn, parents)
.checkExpression(expr1, defn, parents)
.checkExpression(expr2, defn, parents)
.checkExpression(expr2, defn, parents).check(
expr1.expressionType.isAssignmentCompatible(expr2.expressionType),
"Incompatible expression types in Ternary expression",
Messages.Error,
loc
)

case NotCondition(_, cond1) => checkExpression(cond1, defn, parents)
case condition: MultiCondition =>
checkExpressions(condition.conditions, defn, parents)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ trait Expressions extends TypeExpression {
expr1: Expression,
expr2: Expression)
extends Expression {
require(expr1.expressionType.isAssignmentCompatible(expr2.expressionType))
override def format: String =
s"if(${condition.format},${expr1.format},${expr2.format})"

Expand Down Expand Up @@ -346,7 +345,6 @@ trait Expressions extends TypeExpression {
expr1: Expression,
expr2: Expression)
extends Condition(loc) {
require(expr1.expressionType.isAssignmentCompatible(expr2.expressionType))
override def format: String = op.format + Seq(expr1.format, expr2.format)
.mkString("(", ",", ")")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ trait CommonParser extends Terminals with NoWhiteSpaceParsers {
}

def description[u: P]: P[Option[Description]] = P(
StringIn(Keywords.described, Keywords.explained) ~
StringIn(Keywords.described, Keywords.explained) ~/
((as ~ blockDescription) | (Readability.in ~ fileDescription))
).?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,26 @@ trait TypeParser extends CommonParser {
))
}

def defOfMessage[u:P]: P[Type] = {
P(location ~ messageKind ~/ identifier ~ is ~ aggregation ~
briefly ~
description
).map { case (loc, mk, id, agg, b, d) =>
val mt = MessageType(agg.loc, mk, agg.fields)
Type(loc, id, mt, b, d)
}
}

def defOfType[u:P]: P[Type] = {
P(location ~ Keywords.`type` ~/ identifier ~ is ~ typeExpression ~ briefly ~
description
).map { case (loc, id, typEx, b, d) =>
Type(loc, id, typEx, b, d)
}
}

def typeDef[u: P]: P[Type] = {
P(
(location ~ Keywords.`type` ~/ identifier ~ is ~ typeExpression ~
briefly ~ description).map { tpl => (Type.apply _).tupled(tpl) } |
(location ~ messageKind ~/ identifier ~ is ~ location ~ aggregation ~
briefly ~ description).map { case (loc, mk, id, loc2, agg, b, d) =>
val mt = makeMessageType(loc2, mk, agg)
Type(loc, id, mt, b, d)
}
)
defOfType | defOfMessage
}

def types[u: P]: P[Seq[Type]] = { typeDef.rep(0) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class TypeParserTest extends ParsingTest {
}
"allow rename of Currency(US)" in {
val input = "type cur = Currency(US)"
val expected = Type(1 -> 1, Identifier(1 -> 6, "cur"),
Currency(1 -> 12, "US"))
val expected =
Type(1 -> 1, Identifier(1 -> 6, "cur"), Currency(1 -> 12, "US"))
checkDefinition[Type, Type](input, expected, identity)
}
"allow rename of Length" in {
Expand All @@ -54,7 +54,8 @@ class TypeParserTest extends ParsingTest {
}
"allow rename of Luminosity" in {
val input = "type lum = Luminosity"
val expected = Type(1 -> 1, Identifier(1 -> 6, "lum"), Luminosity(1 -> 12))
val expected =
Type(1 -> 1, Identifier(1 -> 6, "lum"), Luminosity(1 -> 12))
checkDefinition[Type, Type](input, expected, identity)
}
"allow rename of Mass" in {
Expand All @@ -69,8 +70,8 @@ class TypeParserTest extends ParsingTest {
}
"allow rename of Temperature" in {
val input = "type tmp = Temperature"
val expected = Type(1 -> 1, Identifier(1 -> 6, "tmp"),
Temperature(1 -> 12))
val expected =
Type(1 -> 1, Identifier(1 -> 6, "tmp"), Temperature(1 -> 12))
checkDefinition[Type, Type](input, expected, identity)
}
"allow renames of Id(path)" in {
Expand Down
3 changes: 3 additions & 0 deletions riddlc/src/main/scala/com/reactific/riddl/InfoCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class InfoCommand extends CommandPlugin[InfoCommand.Options]("info") {
log.info(s" organization: ${RiddlBuildInfo.organizationName}")
log.info(s" scala version: ${RiddlBuildInfo.scalaVersion}")
log.info(s" sbt version: ${RiddlBuildInfo.sbtVersion}")
log.info(s" jvm name: ${System.getProperty("java.vm.name")}")
log.info(s" jvm version: ${System.getProperty("java.runtime.version")}")
log.info(s" operating sys: ${System.getProperty("os.name")}")
Right(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RiddlCommandsTest extends RunCommandSpecBase {
(name: String) => s"riddlc/target/test/$name"

"Riddlc Commands" should {
"generate info" in { runCommand(Array("--quiet", "info")) }
"generate info" in { runCommand(Array("info")) }
"provide help" in { runCommand(Array("--quiet", "help")) }
"print version" in { runCommand(Array("--quiet", "version")) }
"handle parse" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import java.nio.file.Path
/** Run a "from" command on a specific .conf file */
class RunRiddlcOnArbitraryTest extends RunCommandSpecBase {

val cwd = "/Users/reid/Code/Improving/improving-app/riddl"
val config = "src/main/riddl/ImprovingApp.conf"
val cwd = "/Users/reid/Code/improving.app/riddl"
val config = "src/main/riddl/KalixStudy.conf"

"riddlc" should {
s"run --show-times from $config hugo" in {
Expand Down

0 comments on commit 628260e

Please sign in to comment.