Text argument part order
Console program204 lines of .st300 lines of generated Cbuilds as C and Rust
<1 11 11> <1-3-11> 1 11 11 <a 7 bb> a 7 bb a7bb field <1 11 11> condition: 1, 11, 11
On this page
The .st files#
intent.st
structop {
type_app {
exec = {
lang = "C"
}
}
lib_provider {
core = {
source = "StructOp/core"
version = "@latest"
}
}
}main.st
# Language 8.4.1.3: the ${} parts of a text are evaluated left to right, once, in both targets: a part read before a
# part that calls a function shows the value from before the call (a String part included), in a call argument,
# nested inside another text, in print, in a set into a sized String, in a struct field and in a condition.
ability "value" "x" {
type = Int
initial = 1
}
data "value" "x" {
of = ability.value.x
}
ability "function" "bump" {
returns = Int
body = [ability.set.Bump, ability.return.Bumped]
}
ability "set" "Bump" {
target = ability.value.x
value = data.value.x.current + 10
}
ability "return" "Bumped" {
value = data.value.x.current
}
ability "function" "len" {
params = [{ name = "t", type = String }]
returns = Int
body = [ability.return.L]
}
ability "return" "L" {
value = length(t)
}
ability "function" "show" {
params = [{ name = "t", type = String }]
body = [ability.print.Show]
}
ability "print" "Show" {
message = "<${t}>"
}
ability "call" "Flat" {
function = ability.function.show
args = ["${data.value.x.current} ${bump()} ${data.value.x.current}"]
}
ability "set" "Reset" {
target = ability.value.x
value = 1
depends_on = [ability.call.Flat]
}
ability "call" "Nested" {
function = ability.function.show
args = ["${data.value.x.current}-${len(\"a${bump()}\")}-${data.value.x.current}"]
depends_on = [ability.set.Reset]
}
ability "set" "Reset2" {
target = ability.value.x
value = 1
depends_on = [ability.call.Nested]
}
ability "print" "Same" {
message = "${data.value.x.current} ${bump()} ${data.value.x.current}"
depends_on = [ability.set.Reset2]
}
ability "value" "s" {
type = String
size = 16
initial = "a"
}
data "value" "s" {
of = ability.value.s
}
ability "function" "app" {
returns = Int
body = [ability.set.App, ability.return.App]
}
ability "set" "App" {
target = ability.value.s
value = "bb"
}
ability "return" "App" {
value = 7
}
ability "call" "Str" {
function = ability.function.show
args = ["${data.value.s.current} ${app()} ${data.value.s.current}"]
depends_on = [ability.print.Same]
}
ability "set" "R1" {
target = ability.value.s
value = "a"
depends_on = [ability.call.Str]
}
ability "print" "P" {
message = "${data.value.s.current} ${app()} ${data.value.s.current}"
depends_on = [ability.set.R1]
}
ability "set" "R2" {
target = ability.value.s
value = "a"
depends_on = [ability.print.P]
}
ability "value" "u" {
type = String
size = 16
initial = ""
}
data "value" "u" {
of = ability.value.u
}
ability "set" "Sz" {
target = ability.value.u
value = "${data.value.s.current}${app()}${data.value.s.current}"
depends_on = [ability.set.R2]
}
ability "print" "Q" {
message = "${data.value.u.current}"
depends_on = [ability.set.Sz]
}
ability "struct" "Box" {
fields = [{ name = "t", type = String }]
}
ability "value" "box" {
type = Box
}
data "value" "box" {
of = ability.value.box
}
ability "set" "Reset3" {
target = ability.value.x
value = 1
depends_on = [ability.print.Q]
}
ability "set" "Field" {
target = ability.value.box
value = { t = "${data.value.x.current} ${bump()} ${data.value.x.current}" }
depends_on = [ability.set.Reset3]
}
ability "print" "FieldOut" {
message = "field <${data.value.box.current.t}>"
depends_on = [ability.set.Field]
}
ability "set" "Reset4" {
target = ability.value.x
value = 1
depends_on = [ability.print.FieldOut]
}
ability "if" "Cond" {
condition = len("${data.value.x.current}${bump()}${data.value.x.current}") == 5
then = [ability.print.Yes]
else = [ability.print.No]
depends_on = [ability.set.Reset4]
}
ability "print" "Yes" {
message = "condition: 1, 11, 11"
}
ability "print" "No" {
message = "condition: other order"
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.value.x
+ ability.function.bump
+ ability.set.Bump
+ ability.return.Bumped
+ ability.function.len
+ ability.return.L
+ ability.function.show
+ ability.print.Show
+ ability.call.Flat
+ ability.set.Reset
+ ability.call.Nested
+ ability.set.Reset2
+ ability.print.Same
+ ability.value.s
+ ability.function.app
+ ability.set.App
+ ability.return.App
+ ability.call.Str
+ ability.set.R1
+ ability.print.P
+ ability.set.R2
+ ability.value.u
+ ability.set.Sz
+ ability.print.Q
+ ability.struct.Box
+ ability.value.box
+ ability.set.Reset3
+ ability.set.Field
+ ability.print.FieldOut
+ ability.set.Reset4
+ ability.if.Cond
+ ability.print.Yes
+ ability.print.No
Plan: 1 to add, 0 to change, 0 to destroy.Generated main.c
To inspect this generated file, select C in intent.st, initialize the project and export its source.
Export locally
structop init
structop apply -source -no-runGenerated main.rs (the same .st built as Rust)
To inspect this generated file, select Rust in intent.st, initialize the project and export its source.
Export locally
structop init
structop apply -source -no-runTry it
cd text-argument-part-order # a folder holding the .st files above
structop init
structop plan
structop apply