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: docs/docs/chisel-method.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
@@ -11,22 +11,24 @@ The Chisel method allows to build parsers consistently using the same approach w
11
11
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.
12
12
13
13
The Chisel method is based on the following principles:
14
+
14
15
1. We define a clear goal, which is shared by the Client and the Language Engineering Team. This goal is objective, and it is not subject to interpretation.
15
16
2. At each step, the Language Engineering Team should clearly understand where we are and what should be done next - parsing and then refining the produced AST. Tool support should facilitate each single step, removing friction due to repetitive tasks. For this the StarLasu Libraries can be used since it provides user-friendly APIs for seamless integration as well as cross-language integration.
16
17
3. Ensure frictionless adoption by providing all support needed to facilitate the adoption of the parser inside a Language Engineering Pipeline. By automatically generating documentation and having a method that simplifies training processes.
17
-
18
-

18
+

19
19
20
20
The Chisel method is based on the following steps:
21
21
22
22
1. Create a parser using the StarLasu Libraries and Starlasu Tools, for that you need to:
23
23
24
-
- Define a grammar;
25
-
- Use the starlasu libraries to generate the AST;
26
-
- Refine the AST;
27
-
- Have a testing strategy;
28
-
- Have a set of examples that can be used to measure the parser's progress;
24
+
- Define a grammar;
25
+
- Use the starlasu libraries to generate the AST;
26
+
- Refine the AST;
27
+
- Have a testing strategy;
28
+
- Have a set of examples that can be used to measure the parser's progress;
29
+
29
30
2. Write a semantics module for more advanced codebase analysis and symbol resolution (optional).
30
31
3. Write a code generation module this if the final goal is to generate the code for a target language (optional).
31
32
32
-
Chisel is a method and a transformative approach to parsers development, ensuring efficiency, adaptability, and sustainability.
33
+
Chisel is a method and a transformative approach to parsers development, ensuring efficiency, adaptability, and sustainability.
34
+
development, ensuring efficiency, adaptability, and sustainability.
Copy file name to clipboardExpand all lines: docs/docs/code-generation.md
+15-16Lines changed: 15 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,12 +10,11 @@ Code Generation modules are useful to generate new files programmatically. This
10
10
11
11
Currently, Code Generation modules can be written with Kolasu and SharpLasu.
12
12
13
-
## Setup
13
+
## Setup
14
14
15
15
The Code Generation implementation should be separated from any other modules and be called code-generation. This module will typically have as dependency an ast module. Next is presented an `build.gradle.kts` file example for a code generation module.
16
16
Note that currently the gradle starlasu plugin is private.
The Code Generator class should be a subclass of `ASTCodeGenerator`, this class needs to override the `registerRecordPrinters` function. This function will contain a `recordPrinter` for each AST node, the implementation of the recordPrinter will determine the output generated for the node type.
48
47
49
-
```kotlin
48
+
```kotlin
50
49
classMyCodeGenerator : ASTCodeGenerator() {
51
50
overridefunregisterRecordPrinters() {
52
51
recordPrinter<MyNode> {
@@ -66,30 +65,30 @@ The methods to generate code are quite simple and intuitive to use:
66
65
-`println` is used to print a string followed by a new line;
67
66
-`printList` is used to print a list of nodes; You can specify a prefix, suffix and separator;
68
67
-`printFlag` is used to print a string if a condition (flag which is a boolean value) is true;
69
-
-`indent` is used to increase the indentation level which will be checked by the `print` and `println` methods;
68
+
-`indent` is used to increase the indentation level which will be checked by the `print` and `println` methods;
70
69
-`dedent` is used to decrease the indentation level which will be checked by the `print` and `println` methods.
71
70
72
71
## Testing
73
72
74
-
There is the need to know how the generated code should look like.
73
+
There is the need to know how the generated code should look like.
75
74
76
75
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.
77
76
78
77
It is also a good practise to have end-to-end tests, and one can follow 2 methods:
79
78
80
-
1.**AST to AST testing**:
79
+
1. AST to AST testing:
81
80
82
-
- Parse an input file that contains the original code, obtaining a first AST;
83
-
- Generate the code from this first AST, obtaining the generated code;
84
-
- Reparse the generated code, obtaining a second AST;
85
-
- Compare the first and the second AST.
81
+
- Parse an input file that contains the original code, obtaining a first AST;
82
+
- Generate the code from this first AST, obtaining the generated code;
83
+
- Reparse the generated code, obtaining a second AST;
84
+
- Compare the first and the second AST.
86
85
87
86
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.
88
87
89
-
2.**AST to code testing**:
88
+
2. AST to code testing:
90
89
91
-
- Parse a string that contains the original code to the target AST representation;
92
-
- Generate the code from the target AST;
93
-
- Compare the expected output with the generated output.
90
+
- Parse a string that contains the original code to the target AST representation;
91
+
- Generate the code from the target AST;
92
+
- Compare the expected output with the generated output.
94
93
95
-
This testing method is useful to test smaller examples and cover styling and formatting of the code. It allows to test the code generation in a more concrete way, where we check that the produced code matches the one we expect.
94
+
This testing method is useful to test smaller examples and cover styling and formatting of the code. It allows to test the code generation in a more concrete way, where we check that the produced code matches the one we expect.
Copy file name to clipboardExpand all lines: docs/docs/common-elements.md
+8-42Lines changed: 8 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,50 +4,16 @@ title: Common Elements
4
4
sidebar_label: Common Elements
5
5
---
6
6
7
-
# Common Elements
7
+
# AST Common Elements
8
8
9
-
Common elements in Starlasu provide shared functionality and utilities that are used across different language engineering tools.
9
+
Most programming languages share some concepts. We identified these common concepts and defined marker types for them. In this way, we can treat these elements similary in all languages.
10
10
11
-
## Core Components
11
+
They are:
12
12
13
-
### AST Nodes
14
-
-**Base Classes**: Common functionality for all AST nodes
15
-
-**Position Tracking**: Source location information
16
-
-**Serialization**: Standard serialization support
17
-
-**Validation**: Common validation rules
13
+
* Statement: for example print statements, expression statements, or return statements
14
+
* Expression: for example, literals, mathematical expressions, boolean expressions
15
+
* Entity Declaration: for example, class declarations, top level function declarations
18
16
19
-
### Utilities
20
-
-**String Handling**: Text processing utilities
21
-
-**File Operations**: File reading and writing
22
-
-**Error Handling**: Standard error reporting
23
-
-**Logging**: Logging and debugging support
17
+
_See in [Kolasu](https://github.com/Strumenta/kolasu/blob/main/ast/src/commonMain/kotlin/com/strumenta/kolasu/model/CommonElements.kt)_
24
18
25
-
## Shared Patterns
26
-
27
-
### Design Patterns
28
-
-**Visitor Pattern**: Standard AST traversal
29
-
-**Builder Pattern**: AST construction utilities
30
-
-**Factory Pattern**: Node creation helpers
31
-
-**Observer Pattern**: Change notification
32
-
33
-
### Common Operations
34
-
-**AST Traversal**: Standard traversal algorithms
35
-
-**Node Comparison**: AST comparison utilities
36
-
-**Copy Operations**: Deep copying and cloning
37
-
-**Merge Operations**: AST merging utilities
38
-
39
-
## Benefits
40
-
41
-
-**Code Reuse**: Share common functionality across tools
42
-
-**Consistency**: Maintain consistent behavior
43
-
-**Maintenance**: Centralize common code
44
-
-**Testing**: Shared test utilities
45
-
46
-
## Implementation
47
-
48
-
Starlasu provides:
49
-
50
-
-**Base Classes**: Common base classes for all implementations
51
-
-**Utility Libraries**: Shared utility functions
52
-
-**Standard Interfaces**: Common interfaces and contracts
53
-
-**Testing Support**: Shared testing utilities
19
+
_This is not yet supported in other StarLasu libraries._
Copy file name to clipboardExpand all lines: docs/docs/cross-platform-parsers.md
+7-44Lines changed: 7 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,51 +4,14 @@ title: Cross-Platform Parsers
4
4
sidebar_label: Cross-Platform Parsers
5
5
---
6
6
7
-
# Cross-Platform Parsers
7
+
# Cross-platform parsers
8
8
9
-
Cross-platform parsers in Starlasu enable you to build language tools that work across different programming environments and platforms.
9
+
Different users may want to use our parsers from different platforms such as the browser, Python, the JVM, etc.
10
10
11
-
## Platform Support
11
+
On the other hand we want to avoid having to rewrite the parsers for the same languages across multiple platforms. For this reason we have developed an approach to use parsers across platforms. In essence, we write a parser for any platform we want, using Kolasu, Pylasu, or Tylasu. We then access the AST produced by such parsers on another platform by serializing the AST produced on one platform and unserializing it on another one. To make this possible we built tools to:
12
12
13
-
### JVM Platform
14
-
-**Java**: Native Java implementation
15
-
-**Kotlin**: Kotlin-based implementation
16
-
-**Scala**: Scala integration support
17
-
-**Android**: Mobile development support
13
+
- analyze the codebase of the original parser and extract a metamodel
14
+
- generate AST classes on the other platforms from the metamodel
15
+
- generate an AST unserializers from the metamodel
18
16
19
-
### Web Platform
20
-
-**Node.js**: Server-side JavaScript
21
-
-**Browser**: Client-side JavaScript
22
-
-**TypeScript**: Type-safe JavaScript
23
-
-**WebAssembly**: High-performance web execution
24
-
25
-
### Other Platforms
26
-
-**Python**: Python implementation
27
-
-**.NET**: C#, F#, VB.NET support
28
-
-**Native**: C/C++ integration
29
-
30
-
## Benefits
31
-
32
-
-**Code Reuse**: Share parser logic across platforms
33
-
-**Consistency**: Maintain consistent behavior across environments
34
-
-**Flexibility**: Choose the best platform for each use case
35
-
-**Ecosystem**: Leverage platform-specific tools and libraries
36
-
37
-
## Implementation
38
-
39
-
### Shared Components
40
-
-**Grammar Definitions**: Platform-independent language specifications
41
-
-**AST Models**: Common data structures across platforms
-**Documentation**: Generate docs for multiple platforms
17
+
In this way we could write a parser for RPG in Kotlin, using Kolasu. We would then automatically generate equivalent AST classes in Pylasu, and code to unserialize an AST instantiating those AST classes. In the end, we would obtain a parser usable from Python, which expose AST classes in Python. The implementation would call the parser written in Kotlin, obtain the AST serialized and unserialize it behind the scenes.
Copy file name to clipboardExpand all lines: docs/docs/dual-code-model-apis.md
+12-56Lines changed: 12 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,65 +4,21 @@ title: Dual Code Model APIs
4
4
sidebar_label: Dual Code Model APIs
5
5
---
6
6
7
-
# Dual Code Model APIs
7
+
# The Dual Code Model APIs
8
8
9
-
Starlasu provides two complementary APIs for working with ASTs: homogeneous and heterogeneous APIs.
9
+
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.
10
+
It will approach the concepts of homogenous and heterogeneous APIs, and how to use and leveraged them in the StarLasu libraries.
10
11
11
-
## Homogeneous API
12
+
## Homogenous APIs
12
13
13
-
The homogeneous API treats all AST nodes uniformly:
14
+
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.
15
+
All the instances of nodes are the same and have a defined set of properties and methods, such as the origin, parent, etc...
14
16
15
-
-**Type Safety**: All nodes have the same interface
16
-
-**Generic Operations**: Apply operations to any node type
17
-
-**Reflection**: Access properties dynamically
18
-
-**Flexibility**: Work with unknown node types
17
+
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.
18
+
This is what we call a homogenous API.
19
19
20
-
## Heterogeneous API
20
+
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.
21
+
## Heterogeneous APIs
21
22
22
-
The heterogeneous API provides type-specific operations:
23
-
24
-
-**Type-Specific Methods**: Access properties and methods specific to each node type
25
-
-**Compile-Time Safety**: Catch errors at compile time
26
-
-**IntelliSense**: Better IDE support and autocomplete
27
-
-**Performance**: Optimized for specific node types
28
-
29
-
## When to Use Each
30
-
31
-
### Use Homogeneous API when:
32
-
- Working with unknown or generic node types
33
-
- Implementing generic algorithms
34
-
- Building tools that work with any AST
35
-
- Need for dynamic property access
36
-
37
-
### Use Heterogeneous API when:
38
-
- Working with known node types
39
-
- Building type-specific functionality
40
-
- Need for compile-time safety
41
-
- Performance is critical
42
-
43
-
## Implementation
44
-
45
-
Starlasu libraries provide both APIs:
46
-
47
-
-**Base Classes**: Common functionality for all nodes
48
-
-**Type-Specific Classes**: Specialized behavior for each node type
49
-
-**Conversion Methods**: Switch between API styles
50
-
-**Hybrid Approaches**: Combine both APIs as needed
51
-
52
-
## Example
53
-
54
-
```kotlin
55
-
// Homogeneous API
56
-
val allNodes = ast.findAll<ASTNode>()
57
-
allNodes.forEach { node ->
58
-
val name = node.getProperty("name")
59
-
// Work with any node type
60
-
}
61
-
62
-
// Heterogeneous API
63
-
val functions = ast.findAll<FunctionDeclaration>()
64
-
functions.forEach { func ->
65
-
val name = func.name // Type-safe access
66
-
val params = func.parameters // Type-specific property
67
-
}
68
-
```
23
+
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.
EMF (Eclipse Modeling Framework) interoperability in Starlasu enables integration with the Eclipse ecosystem and EMF-based tools.
9
+
The Eclipse Modeling Framework (EMF) has been very successful in the MDE world. It can be regarded as an exchange format supported by different tools.
10
10
11
-
## EMF Integration
11
+
For this reason we built support for exporting Metamodels and Models to EMF. We in particular support the serialization to EMF-JSON. EMF-JSON is not as
12
+
well-defined and supported as XMI (based on XML), but the request for JSON-based formats on some of the platforms supported brought us to focus on it.
12
13
13
-
### Model Exchange
14
-
-**ECore Models**: Import and export EMF Ecore models
15
-
-**XMI Serialization**: Exchange models in XMI format
16
-
-**Model Validation**: Use EMF validation frameworks
14
+
In our case, _metamodels_ are the definition of the node types. For example, they specify which properties each node has.
17
15
18
-
### Tool Integration
19
-
-**Eclipse Plugins**: Build Eclipse-based language tools
20
-
-**EMF Editors**: Create visual model editors
21
-
-**Model Transformations**: Use EMF transformation frameworks
16
+
Instead, we can represent and serialize ASTs as _models_ (i.e., instances of metamodels). A model describes the value of each node's properties, and the
17
+
relationships among the nodes.
22
18
23
-
## Benefits
19
+
In some of the StarLasu libraries, we can also _import_ EMF metamodels and models (generated with other StarLasu libraries)
20
+
in order to _consume_ the results of a tool (e.g. a parser) from a different language. This is what the
21
+
[Strumenta Playground](https://playground.strumenta.com/) web app does, for example. This is also useful for [cross-platform parsers](parsers-cross-platform.md).
24
22
25
-
-**Eclipse Ecosystem**: Leverage existing Eclipse tools and plugins
26
-
-**Visual Modeling**: Create graphical model editors
-[Pylasu](https://pylasu.readthedocs.io/en/latest/pylasu.emf.html) ([source code](https://github.com/Strumenta/pylasu/tree/master/pylasu/emf)) _note: support in Pylasu is a work in progress._
- PossiblyNamed, which define an attribute name of type String with multiplicity 0..1
12
+
- Named, which extends PossiblyNamed and define an attribute name of type String with multiplicity 1..1
13
+
14
+
For example, a FunctionDeclaration will be PossiblyNamed in languages which permits anonymous functions.
15
+
16
+
In the StarLasu libraries we provide special support for things which are Named or PossiblyNamed. We can used these interfaces in [Symbol Resolution](SymbolResolution.md), for example.
0 commit comments