Skip to content

Commit 5ebbb7c

Browse files
reid-spencerreidspencer
andauthored
OSS-277-Claude-Inspired-Changes (ossuminc#716)
Changes Inspired By Claude * Fix some documentation in the AST and Pass modules * Functions no longer have readability words after requires/returns * Fix toEndOfLine to accept 0 characters too. * Improve validation to recognize empty functions properly. * Add ShopifyCart test case * Teach Finder to find values recursively from the container * Revise overload checking to be smarter so that only the overloads that refer to different kinds of definitions or fields that have different type definitions are noted. * Don't bother warning about missing author references. * Don't warn about modesl without streaming data. * Make checking for event and result message generation in on clauses better and recursively search the statements * Make function validation use a specialized check for emptiness because its contents are not definitions * Get all tests working with these changes --------- Co-authored-by: reidspencer <reid.spencer@yoppworks.com>
1 parent 00f1c7a commit 5ebbb7c

46 files changed

Lines changed: 825 additions & 874 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

commands/input/everything.riddl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ domain Everything is {
55

66
context APlant is {
77
source Source is { outlet Commands is DoAThing } with { described by "Data Source" }
8-
sink Sink is { inlet Commands is DoAThing } with { explained as "Data Sink" }
8+
sink Sink is { inlet Events is DoAThing } with { explained as "Data Sink" }
99
connector AChannel is {
10-
from outlet APlant.Source.Commands to inlet APlant.Sink.Commands
10+
from outlet APlant.Source.Commands to inlet APlant.Sink.Events
1111
} with { explained as "A Channel" }
1212
} with { explained as "A Plant" }
1313

@@ -24,7 +24,7 @@ domain Everything is {
2424

2525
sink Sink is { inlet input is type DoAThing }
2626

27-
connector foo is {
27+
connector con is {
2828
from outlet Everything.APlant.Source.Commands to inlet full.Sink.input
2929
}
3030

commands/input/rbbq.riddl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
domain ReactiveBBQ is {
22

3-
type CustomerId is Id(ReactiveBBQ.Customer.Customer) with { explained as {
3+
type CustomerId is Id(ReactiveBBQ.Customers.Customer) with { explained as {
44
"Unique identifier for a customer"
55
}}
66

7-
type OrderId is Id(ReactiveBBQ.Order.Order) with {
7+
type OrderId is Id(ReactiveBBQ.Orders.Order) with {
88
described as {
99
|# brief
1010
|Unique identifier for a customer's order
@@ -15,7 +15,7 @@ domain ReactiveBBQ is {
1515

1616
type Empty = Nothing
1717

18-
context Customer is {
18+
context Customers is {
1919
entity Customer is {
2020
state main of ReactiveBBQ.Empty
2121
handler input is { ??? }
@@ -86,12 +86,12 @@ domain ReactiveBBQ is {
8686
handler Inputs is { ??? }
8787
}
8888

89-
adaptor PaymentAdapter from context ReactiveBBQ.Payment is {
89+
adaptor PaymentAdapter from context ReactiveBBQ.Payments is {
9090
???
9191
}
9292
}
9393

94-
context Order is {
94+
context Orders is {
9595
entity Order is {
9696
record fields is {
9797
orderId is ReactiveBBQ.OrderId,
@@ -104,7 +104,7 @@ domain ReactiveBBQ is {
104104
}
105105
}
106106

107-
context Payment is {
107+
context Payments is {
108108
entity Payment is {
109109
record fields is {
110110
orderId is ReactiveBBQ.OrderId,
@@ -118,23 +118,23 @@ domain ReactiveBBQ is {
118118
}
119119
}
120120

121-
context Menu is {
121+
context Menus is {
122122
entity MenuItem is {
123123
record fields is { something: String }
124-
state MenuState of Menu.MenuItem.fields
124+
state MenuState of Menus.MenuItem.fields
125125
handler foo is {}
126126
}
127-
type MenuItemRef is reference to entity Menu.MenuItem
127+
type MenuItemRef is reference to entity Menus.MenuItem
128128
entity MenuEntity is {
129-
record fields is { items: many Menu.MenuItemRef }
129+
record fields is { items: many Menus.MenuItemRef }
130130
state typical of MenuEntity.fields
131131
handler foo is { ??? }
132132
} with {
133133
option is aggregate
134134
}
135135
}
136136

137-
context Reservation is {
137+
context Reservations is {
138138
type ReservationValue is {
139139
partyName is String,
140140
phoneNumber is String,

commands/jvm/src/test/scala/com/ossuminc/riddl/commands/hugo/mermaid/DataFlowDiagramTest.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DataFlowDiagramTest extends JVMAbstractValidatingTest {
3030
case Left(messages) => fail(messages.justErrors.format)
3131
case Right(passesResult: PassesResult) =>
3232
val dfd = DataFlowDiagram(passesResult)
33-
val domains =
33+
val domains =
3434
passesResult.root match
3535
case root1: Root => AST.getTopLevelDomains(root1)
3636
case nebula: Nebula => nebula.contents.filter[Domain]
@@ -40,11 +40,11 @@ class DataFlowDiagramTest extends JVMAbstractValidatingTest {
4040
val actual = dfd.generate(contexts.head)
4141
val expected =
4242
"""flowchart LR
43-
|Commands[\"Outlet Source.Commands"\]
44-
|Commands[/"Inlet Sink.Commands"/]
43+
|OutCommands[\"Outlet Source.OutCommands"\]
44+
|InCommands[/"Inlet Sink.InCommands"/]
4545
|APlant[{"Context Everything.APlant"}]
4646
|command ACommand["OnMessageClause adaptCommands.command ACommand"]
47-
|Commands -- Type 'DoAThing' --> Commands
47+
|OutCommands -- Type 'DoAThing' --> InCommands
4848
|""".stripMargin
4949
actual must be(expected)
5050
}

language/input/dokn.riddl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ domain dokn is {
1515
"^[a-zA-Z0-9_+&*-] + (?:\\.[a-zA-Z0-9_+&*-] + )*@(?:[a-zA-Z0-9-]+\\.) + [a-zA-Z]{2,7}"
1616
)
1717
type LoadingMethod = any of { dock, tailgate, forklift, none }
18-
type CompanyId = Id(dokn.Company.Company)
18+
type CompanyId = Id(dokn.Companies.Company)
1919
type DriverId = MobileNumber
20-
type NoteId = Id(dokn.Note.Note)
21-
type MediaId is Id(dokn.Media.Media)
22-
type LocationId is Id(dokn.Location.Location)
23-
type NoteList is reference to entity dokn.Note.Note
20+
type NoteId = Id(dokn.Notes.Note)
21+
type MediaId is Id(dokn.Media.Medium)
22+
type LocationId is Id(dokn.Locations.Location)
23+
type NoteList is reference to entity dokn.Notes.Note
2424

25-
context Company is {
25+
context Companies is {
2626
flow events is {
27-
inlet CompanyEvents_in is event dokn.Company.Company.CompanyEvent
28-
outlet CompanyEvents_out is event dokn.Company.Company.CompanyEvent
27+
inlet CompanyEvents_in is event dokn.Companies.Company.CompanyEvent
28+
outlet CompanyEvents_out is event dokn.Companies.Company.CompanyEvent
2929
}
3030
connector CompanyEvents is {
3131
from outlet CompanyEvents_out to inlet CompanyEvents_in
@@ -61,7 +61,7 @@ domain dokn is {
6161
}
6262
}
6363

64-
context Driver is {
64+
context Drivers is {
6565
flow DriverMessages is {
6666
inlet Driver_in is type DriverCommands
6767
outlet Driver_out is type DriverEvents
@@ -103,7 +103,7 @@ domain dokn is {
103103
}
104104
}
105105

106-
context Note is {
106+
context Notes is {
107107
entity Note is {
108108
record fields is {
109109
noteId: NoteId,
@@ -122,20 +122,20 @@ domain dokn is {
122122
}
123123

124124
context Media is {
125-
entity Media is {
125+
entity Medium is {
126126
record fields is {
127127
mediaId: MediaId,
128128
path: String,
129129
companyId: CompanyId
130130
}
131-
state MediaBase of Media.fields
131+
state MediaBase of Medium.fields
132132
handler MediaBaseHandler is { ??? }
133133
} with {
134134
option consistent
135135
}
136136
}
137137

138-
context Location is {
138+
context Locations is {
139139
entity Location is {
140140

141141
type AddDeliveryLocation is command {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
context APlant is {
2-
source Source is { outlet Commands is type DoAThing } with { described as "Data Source" }
3-
sink Sink is { inlet Commands is type DoAThing } with { described as "Data Sink" }
2+
source Source is { outlet OutCommands is type DoAThing } with { described as "Data Source" }
3+
sink Sink is { inlet InCommands is type DoAThing } with { described as "Data Sink" }
44

55
connector AChannel is {
6-
from outlet Source.Commands
7-
to inlet Sink.Commands
6+
from outlet Source.OutCommands
7+
to inlet Sink.InCommands
88
} with { described as "A Channel" }
99
} with { described as "A bunch of data flow connections" }
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
context Whatever is {
2-
record Identity is { name: String, id: UUID, age: Integer }
2+
record Identity is { name: String, uuid: UUID, age: Integer }
33
group AcquireIdentity is {
4-
form Identity takes record Whatever.Identity
4+
form GetIdentity takes record Whatever.Identity
55
}
66
handler DoIt is { ??? }
77
}

language/input/everything_full.riddl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ context full is {
6161
adaptor fromAPlant to context APlant is {
6262
handler adaptCommands is {
6363
on command ACommand {
64-
send command DoAThing to outlet APlant.Source.Commands
64+
send command DoAThing to outlet APlant.Source.OutCommands
6565
}
6666
}
6767
}

language/input/rbbq.riddl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
domain ReactiveBBQ is {
22

3-
type CustomerId is Id(ReactiveBBQ.Customer.Customer) with {
3+
type CustomerId is Id(ReactiveBBQ.Customers.Customer) with {
44
described as {
55
"Unique identifier for a customer"
66
}
77
}
88

9-
type OrderId is Id(ReactiveBBQ.Order.Order) with {
9+
type OrderId is Id(ReactiveBBQ.Orders.Order) with {
1010
described as {
1111
|# brief
1212
|Unique identifier for a customer's order
@@ -17,7 +17,7 @@ domain ReactiveBBQ is {
1717

1818
type Empty = Nothing
1919

20-
context Customer is {
20+
context Customers is {
2121
entity Customer is {
2222
state main of ReactiveBBQ.Empty
2323
handler Input is { ??? }
@@ -90,12 +90,12 @@ domain ReactiveBBQ is {
9090
handler Inputs is { ??? }
9191
}
9292

93-
adaptor PaymentAdapter from context ReactiveBBQ.Payment is {
93+
adaptor PaymentAdapter from context ReactiveBBQ.Payments is {
9494
???
9595
}
9696
}
9797

98-
context Order is {
98+
context Orders is {
9999
entity Order is {
100100
record Fields is {
101101
orderId is OrderId,
@@ -108,7 +108,7 @@ domain ReactiveBBQ is {
108108
}
109109
}
110110

111-
context Payment is {
111+
context Payments is {
112112
entity Payment is {
113113
record Fields is {
114114
orderId is OrderId,
@@ -122,7 +122,7 @@ domain ReactiveBBQ is {
122122
}
123123
}
124124

125-
context Menu is {
125+
context Menus is {
126126
entity MenuItem is {
127127
record Fields is { something: String }
128128
state MenuState of MenuItem.Fields
@@ -138,7 +138,7 @@ domain ReactiveBBQ is {
138138
}
139139
}
140140

141-
context Reservation is {
141+
context Reservations is {
142142
type ReservationValue is {
143143
partyName is String,
144144
phoneNumber is String,

language/shared/src/main/scala/com/ossuminc/riddl/language/AST.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ object AST:
200200
d.isInstanceOf[WithIdentifier] && d.asInstanceOf[WithIdentifier].id.value == name
201201
)
202202

203-
/** Find the first element of the [[Contents]] that */
203+
/** Find the first element of the [[Contents]] that have identifiers */
204204
def identifiedValues: Seq[WithIdentifier] =
205205
container
206206
.filter(d => d.isInstanceOf[WithIdentifier])

language/shared/src/main/scala/com/ossuminc/riddl/language/Finder.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,31 @@ case class Finder[CV <: RiddlValue](root: Container[CV]) {
4949
result.asInstanceOf[Seq[T]]
5050
end findByType
5151

52+
def recursiveFindByType[T <: AST.RiddlValue: ClassTag]: Seq[T] =
53+
import scala.reflect.classTag
54+
val lookingFor = classTag[T].runtimeClass
55+
def consider(list: Seq[T], child: RiddlValue): Seq[T] =
56+
val nested = {
57+
child match
58+
case c: Container[?] =>
59+
c.contents.foldLeft(list) { case (next, child) => consider(next, child) }
60+
case IfThenElseStatement(_, _, thens, elses) =>
61+
val r1 = thens.foldLeft(list) { case (next, child) => consider(next, child) }
62+
elses.foldLeft(r1) { case (next, child) => consider(next, child) }
63+
case ForEachStatement(_, _, do_) =>
64+
do_.foldLeft(list) { case (next, child) => consider(next, child) }
65+
case SagaStep(_, _, dos, undos, _) =>
66+
val r2 = dos.foldLeft(list) { case (next, child) => consider(next, child) }
67+
undos.foldLeft(r2) { case (next, child) => consider(next, child) }
68+
case _ => list
69+
end match
70+
}
71+
if lookingFor.isAssignableFrom(child.getClass) then nested :+ child.asInstanceOf[T]
72+
else nested
73+
end consider
74+
root.contents.foldLeft(Seq.empty) { case (list, child) => consider(list, child) }
75+
end recursiveFindByType
76+
5277
/** The return value for the [[Finder.findWithParents()]] function */
5378
type DefWithParents[T <: RiddlValue] = Seq[(T, Parents)]
5479

0 commit comments

Comments
 (0)