blob: 9b4a5571f176e9f944eb94de03a830cb374aea6a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# Usage
There is a central client to interface the commands for generation, called cli.
To use an existing generator just provide the path to the generator script.
./cli.py generator --generator generator/csv --input input --output output
You can also create a YAML configuration file (e.g csv.yaml):
generator: generator/csv
input: input
output: output
And then call the client with:
./cli.py generate --runner csv.yaml
To enable auto-live reloading just use the monitor target:
./cli.py generator_monitor --runner csv.yaml
This will observe the generator folder and the input folder for changes and re-run the generator.
# Grammar
The IDL grammar is described in the grammar file (see qface/parser/idl/T.g4)
module <identifier> <version>;
[import <identifier> <version>];
interface <identifier> {
(readonly) <type> <property>;
<type> <operation>([type name]);
signal <signal>([type name]);
list<type> <property>;
model<type> <property>;
}
enum <identifier> {
<name> = <value>
}
flag <identifier> {
<name> = <value>
}
struct <identifier> {
<type> <name>;
}
# Domain Model
The IDL is converted into an in memory domain model (see qface/idl/domain.py).
System
Module
Import
Service
Property
Operation
Enum
Struct
The domain model is the base for the code generation.
# Code Generation
The code generation is driven by a small script which iterates over the domain model and writes files using a template language (see http://jinja.pocoo.org) and espcially the template designer documentation (http://jinja.pocoo.org/docs/dev/templates/).
from qface.generator import FileSystem, Generator
def generate(input, output):
system = FileSystem.parse_dir(input)
generator = Generator(searchpath='templates')
ctx = {'output': output, 'system': system}
generator.write('{{output}}/modules.csv', 'modules.csv', ctx)
This script reads the input directory returns a system object form the domain model. This is used as the root object for the code generation inside the template language.
{% for module in system.modules %}
{%- for interface in module.interfaces -%}
SERVICE, {{module}}.{{interface}}
{% endfor -%}
{%- for struct in module.structs -%}
STRUCT , {{module}}.{{struct}}
{% endfor -%}
{%- for enum in module.enums -%}
ENUM , {{module}}.{{enum}}
{% endfor -%}
{% endfor %}
The template iterates over the domain objects and generates text which is written into a file. The file name is also adjustable using the same template language.
|