An open API service indexing awesome lists of open source software.

https://github.com/theo-keyzer/core-gen

Generates code for code generators
https://github.com/theo-keyzer/core-gen

automation codegen core crystal-lang dartlang golang graph json knowledge-base knowledge-engine mojo python query-language schema training v-lang

Last synced: 2 months ago
JSON representation

Generates code for code generators

Awesome Lists containing this project

README

        

# Intro

Processes data with actor files (templates).
The data can be in files, json, database, web or its `def` files.
The `def` file format is defined in `unit` files.
The `unit` files are like a database schema and the `def` files
are like database data. Extra setup steps need to be done if needed.

Other template generators has the output as text with code embedded.
Here it has special commands to format and output text.

The document is for the python version.

# Startup
Start.
The generator takes a `,` separated list of actor files followed
by a `,` separated list of input def files. They each are all lumped together.

The first actor's name, is the starting actor. The `go_act` function
loop through all actors with this name.

All comand line arguments are store in the starting node instance as named entries.
They are `${0}, ${1}` variables. To access these variables else where, prefix it with
the starting actor's name like `${.main.1}`.

From here, other actors are called with the `All, That, This` commands.

The calling actor would then have a node instance it can use to output text
or to navigate further.

# Variable
Variable names.
Variable names are from the current node with options to get other values.
The ${name} gets replaced by the value of the name item.
The `${_.D}` is from the var D and`${_.D.build.domain.name}`, a route to name.
The routes are via a dict or def relations.

The following are variables from the actor window.

The `${}` is the current node.
The `${._key}` variable is the value of the key used for when all key and values are used ( `This list. actor` ).
The `${._lcnt} or ${.-}` is the loop counter.
The `${.+}` is the loop counter plus 1.
The `${._arg}` is the argument passes to the actor.
The `${.0.first} {.1.rest}` is the text first if the loop counter is 0 and rest if > 0.

The `${.main.1}`, uses the `main` actor in the window calling stack for its current node to get the varaible.
The other window variables are also available like `${.main..arg}`
The `Du` command, calls another actor, but should have the same variable values.

The following are global.

The `${._list.A}`, the value is the list item.
The `${._set}`, the value is the set dict.
The `${_.D}` is like `${._var.D}`.
The `${._ins}` is output captured between the `In on, In off` commands.

The format options, reformats the value. `${name:u}` converts it to upper case.
If the item is a list, `${:-}` is the value at the loop index.
The `${:sort:join}`, sorts the list and the output is `a,b,c` string.

The `strs` function in gen.py`, replaces the variable names of a string with their values.
Some of the actor commands, calls this function for an item so that the item can be combined with variables.
This is not done for every item, and can be added if needed.

### Purpose
The use cases.
- Output - print variable value.
- Match - compare value.
### Special
Special variable names are prefixed by (.).
- Window - .actor, the def of the actor.
- Collections - .\_set, .\_var, .\_list
- Counters - .+, loop counter.
- Depth - .\_depth, the actor stack depth.
- Arg - .\_arg, argument passed from previous actor.
- Conditional - .0, first or rest of loop counter.
- Eval - \$, the content is re evaluated.
- Optional - ?, no error on var.
### Errors
Variable name errors.
The errors land up in the generated code to track down the error.
Some commands make use of the `s_get_var, strs` functions that would return
the error, but the commands ignore them. The errors are printed though.

# Actor
The actors
The actor are like functions that can be called
and a case like statement that matches.
The match is (var exp string), the string can have variables in it.
Actors of the same name, are the case items.
They are given an input node to operate on.
The actor has a list of commands it runs through.

The actor match also has a `?` to match the variable no error. The `??`, matches the not found error.
There is no error reported when using it. The error can be on both sides of the equation. `name = ${name}`

```
----------------------------------------------------------------
Actor a . model.name ?= test
----------------------------------------------------------------
```

Here the `?=` match for if no error.

```
----------------------------------------------------------------
Actor a . model.name ??
Break
Actor a . model.name = test
----------------------------------------------------------------
```

Here the `Break` will break out of the actor match on error and not get to next one.

```
----------------------------------------------------------------
Actor a . model = test
----------------------------------------------------------------
```

Or in some cases, this would also work as the values are the same for both.

The `?model?` error is no `model` field where as `?model.?`, is no reference to the `model`.

### Purpose
Use cases.
- Navigate - call actor with a def.
- Collect - collect defs or strings.
- Limit - break out of loops.
- Print - print output text.
### Name
Command names.
- All - actor call with all nodes of type.
- Its - actor call with defs related to current node.
- Du - actor call with the current node.
- This - actor call with data from collections
- That - actor call with nodes from external data like url,db,json,file.
- C - print output line.
- Cs - print output with no new line.
- Break - break out of the actor.
- Out - delay or omitting output based on further output.
- Add - Add to collections
- Clear - Clear collections
- Check - Check unique in collection
#### Collect
Collection commands.
The `Add` command is to add data to the `var,set,list` collections.
It can also add to `me`, the current node, or `node`, some other node.
It has command options `(Add.)` as what to add. It defaults to adding a string.
The options are `node,me,json` The node has a path to a node.

`Add.me var N` is to add the current node and `Add var Z this is ${name}` to add a string value.
To use it is `${_.N.name}` or `${_.Z}`.
`Add.me set S` and `Add set B abc` is to is to add to a set. Sets do not have duplicates.
A flag gets set in the window stack if a duplicate was added.
`Break cmds for . True` will end this actor is the flag is set.
`Check set B abc` does not add, only checks.
The `Add.break, Check.break`, will break the actor loop like the single `Break` command.
To get more break options, use a separate `Break` command.
The `Add var` also does a check to see if the value added is the same. Like `Add.break var done`
The `Add me` is to add to the value to the current node if it is a list,set or dict.
The `Add.me` is a way to differentiate between using the current node or the string value.
A empty string now no longer defaults to the current node.
The order of the command options does not matter. `Add.me.break` is the same as `Add.break.me`
Add list always adds, but it could break before adding a duplicate.
For now, use the `Check list` for duplicates.

The `Add.json var E {"ids": [4,5,6], "userId": 7}` puts a json node in E.
`C ${_.E:} - ${_.E.userId:} ${_.E.ids:} ${_.E.ids:0}` outputs `{'ids': [4, 5, 6], 'userId': 7} - 7 [4, 5, 6] 4`.
The `(:)` has the variable formating options. Here it converts the object to a string.
It is now possible now to add to this dict with `Add.me var J.${name}`
The `me` is the current node item or it can be a string like `Add var J.${name} ${value}`
The `Add.node var J.${name} _.F`, can add the var F to this dict.
Or `Add.node me ${name} _.F` to add the F var node to the current node.
The `${_.F}` is a string whereas `_.F` is the value in it. This to navigate the a node tree,
save it in F with `Add.me var F`, then navigate in another node tree and save it there.

The `Add node:_.J ${name} ${value}` is the same as `Add var J.${name} ${value}`

#### Break
Break command.
The `Break` command is the same as `Break actor` as it is the default.

The codes returned by the break is 1 for loops, 2 for actor and 3 for commands.
The `go_act` function in `gen.py`, will continue the actor loop if the break was for the comands.
It will return 0 if its is for the actor. Else return the value.

The generated code for the `Its` will continue as long is the return is 0, else returns the returned value.
The commands in the `go_cmd` function that deal with loops, will continue if the return is for the loops or 0.
Else it returns the returned value. There is no need for a loop continue as a break for the actor will continue the loop if there was one
or continue with the calling actor.

When the `Break` command specifies the actor the break applies to, it makes the return value negative
and puts a flag on the actor one up in the calling stack. The actor with the flag on in the `go_act` function will return this value as positive.
Then all the calling code will react in the same way as before. The break is then for the actor one down.

`Add.me set S` and `Add set B abc` is to is to add to a set. Sets do not have duplicates.
A flag gets set in the window stack if a duplicate was added.
`Break cmds for . True` will end this actor is the flag is set.
`Check set B abc` does not add, only checks.
The `Add.break, Check.break`, will break the actor loop like the single `Break` command.
To get more break options, use a separate `Break` command.
The `Add var` also does a check to see if the value added is the same. Like `Add.break var done`

### Call
Actor calls.
The `All, Its, This, That and Du` commands, calls the `new_act` function to set up
a new actor window on the stack. It passes the `arg` string.
The `Du` command calls `go_act` with the current node instance, the others, the generated code that call `go_act`.
The `go_act` function uses the new node instance. The match uses this instance
and return if the match failed. Then it loops through all actors with its given name.
Each of these actors, have there own match data and skips the ones that do not match.

The `Its`, uses the current node, whereas `This`, uses a node from the collection.
They join up to complete a path route.

The `That` uses data from external sources.

#### That
Actor calls.
```
That db from test.db rows SELECT * from ship
That file at inlet/startup.md include
That json of id.json list_act0
That url.get at https://jsonplaceholder.typicode.com/posts/1 response_list
That re_sub ${._var.replace} ${._var.input} output (?