You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Writerside/topics/ChiselMethod.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# The Chisel Method
2
2
3
-
The Chisel method for writing parsers allows to build parsers consistently using the same approach which allows to achieve a consistency on the architectural decisions and enables developers to get familiar with a project easily.
3
+
The Chisel method allows to build parsers consistently using the same approach which allows to achieve a consistency on the architectural decisions and enables developers to get familiar with a project easily.
4
4
5
5
This method is called Chisel because building parsers is about getting the information out of the code, as when you use a chisel you "take" the statue out of the marble. Also, since Strumenta means tools in Latin, Chisel takes the place as one of the most important tool in the company's toolset.
6
6
@@ -12,7 +12,8 @@ The Chisel method is based on the following principles:
12
12
13
13
The Chisel method is based on the following steps:
14
14
15
-
1. Create a parser using the StarLasu Libraries, for that you need to:
15
+
1. Create a parser using the StarLasu Libraries and Starlasu Tools, for that you need to:
Copy file name to clipboardExpand all lines: Writerside/topics/CodeGeneration.md
+10-8Lines changed: 10 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# Code Generation
2
2
3
-
Code Generation modules are usefull to generate new files programmatically. This is the case when building a transpiler, where there is the need to generate text (code) from an AST representation.
3
+
Code Generation modules are useful to generate new files programmatically. This is the case when building a transpiler, where there is the need to generate text (code) from an AST representation.
4
4
5
-
Currently Code Generation modules can be written only with Kolasu.
5
+
Currently, Code Generation modules can be written with Kolasu and SharpLasu.
@@ -67,18 +66,21 @@ The methods to generate code are quite simple and intuitive to use:
67
66
68
67
There is the need to know how the generated code should look like.
69
68
70
-
Unit testing can be done by writing the expected output in a file/string and comparing the generated output with the expected output using as input a manually created AST.
69
+
For that unit testing can be done by writing the expected output in a file/string and comparing the generated output with the expected output using as input a manually created AST.
71
70
72
71
It is also a good practise to have end-to-end tests, and one can follow 2 methods:
73
72
74
73
1. AST to AST testing:
75
-
- Parse an input file that contains the original code to the target AST representation;
76
-
- Parse an input file that contains the expected code to the expected AST representation;
77
-
- Compare the expected AST with the generated AST.
74
+
75
+
- Parse an input file that contains the original code, obtaining a first AST;
76
+
- Generate the code from this first AST, obtaining the generated code;
77
+
- Reparse the generated code, obtaining a second AST;
78
+
- Compare the first and the second AST.
78
79
79
80
This testing method is useful to test large examples, where it is hard to write the expected output manually. It allows to test the code generation in a more abstract way, where we check that the produced AST matches the one we expect. Of course it lacks coverage for code styling and formatting.
80
81
81
82
2. AST to code testing:
83
+
82
84
- Parse a string that contains the original code to the target AST representation;
83
85
- Generate the code from the target AST;
84
86
- Compare the expected output with the generated output.
Copy file name to clipboardExpand all lines: Writerside/topics/DualCodeModelAPIs.md
+7-4Lines changed: 7 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,17 @@
1
1
# The Dual Code Model APIs
2
2
3
-
This segment is more theoretical than the others. It is meant to provide a high-level overview of the dual code model APIs and the approach followed in the development of the starlasu tools.
4
-
It will approach the concepts of homogenous and heterogeneous APIs, and how to use and leveraged them in the starlasu tools.
3
+
This segment is more theoretical than the others. It is meant to provide a high-level overview of the dual code model APIs and the approach followed in the development of the StarLasu libraries.
4
+
It will approach the concepts of homogenous and heterogeneous APIs, and how to use and leveraged them in the StarLasu libraries.
5
5
6
6
## Homogenous APIs
7
7
8
8
In kolasu, [Nodes](https://github.com/Strumenta/kolasu/blob/main/core/src/main/kotlin/com/strumenta/kolasu/model/Node.kt) are the basic building blocks of an AST. They are used to represent the different elements of the language being parsed.
9
-
All the instances of nodes are the same and have a defined set of properties and methods, such as the origin, parent, etc... This is what we call a homogenous API.
9
+
All the instances of nodes are the same and have a defined set of properties and methods, such as the origin, parent, etc...
10
10
11
-
This homogenous APIs are important to develop generic tools, such as the current efforts to have an algorithm to find idioms within a language. Using the homogenous API, we can develop a tool that can be used for any language that has an AST representation.
11
+
There are also reflective capabilities: so that its possible to ask each node for its properties and for each property to have access to the name, type and multiplicity, which allows to write fully generic algorithms.
12
+
This is what we call a homogenous API.
13
+
14
+
This homogenous APIs are important to develop generic tools, like interpreters or semantic enrichment modules. Using the homogenous API, we can develop a tool that can be used for any language that has an AST representation.
12
15
## Heterogeneous APIs
13
16
14
17
On the other hand, each Node can also have its own specific set of properties and methods. For instance a Node that represents an if statement can have the condition and the body properties.
Copy file name to clipboardExpand all lines: Writerside/topics/Serialization.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
In addition to what is described here, there is also EMF serialization, which is discussed separately. See [EMF](EMFInteroperability.md).
4
4
5
-
StarLasu supports exporting ASTs to JSON and XML.
6
-
Additionally, kolasu supports import/export from the [Lionweb](https://github.com/Strumenta/kolasu/blob/main/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverter.kt)format.
5
+
StarLasu Tools supports exporting ASTs to JSON and XML.
6
+
Additionally, [kolasu](https://github.com/Strumenta/kolasu/blob/main/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverter.kt)and [tylasu](https://github.com/Strumenta/tylasu/blob/master/src/interop/lionweb.ts) support import/export from the LionWeb format
7
7
8
8
_See in [Kolasu](https://github.com/Strumenta/kolasu/tree/main/serialization/src/main/kotlin)_.
0 commit comments