Skip to content

Commit cfa6b13

Browse files
amari-calipsoftomassetti
authored andcommitted
Restore proper content
1 parent 43e9b2b commit cfa6b13

20 files changed

+1443
-609
lines changed

docs/docs/ast-representation.md

Lines changed: 549 additions & 14 deletions
Large diffs are not rendered by default.

docs/docs/ast-traversal-and-querying.md

Lines changed: 630 additions & 32 deletions
Large diffs are not rendered by default.

docs/docs/chisel-method.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,24 @@ The Chisel method allows to build parsers consistently using the same approach w
1111
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.
1212

1313
The Chisel method is based on the following principles:
14+
1415
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.
1516
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.
1617
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-
![The Chisel Method](/img/chiselMethod.png)
18+
![image.png](chiselMethod.png)
1919

2020
The Chisel method is based on the following steps:
2121

2222
1. Create a parser using the StarLasu Libraries and Starlasu Tools, for that you need to:
2323

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+
2930
2. Write a semantics module for more advanced codebase analysis and symbol resolution (optional).
3031
3. Write a code generation module this if the final goal is to generate the code for a target language (optional).
3132

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.

docs/docs/code-generation.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ Code Generation modules are useful to generate new files programmatically. This
1010

1111
Currently, Code Generation modules can be written with Kolasu and SharpLasu.
1212

13-
## Setup
13+
## Setup
1414

1515
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.
1616
Note that currently the gradle starlasu plugin is private.
17-
18-
```kotlin
17+
``` kotlin
1918
import com.strumenta.starlasugradleplugin.addGitHubPackagesRepo
2019

2120
plugins {
@@ -46,7 +45,7 @@ dependencies {
4645

4746
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.
4847

49-
```kotlin
48+
``` kotlin
5049
class MyCodeGenerator : ASTCodeGenerator() {
5150
override fun registerRecordPrinters() {
5251
recordPrinter<MyNode> {
@@ -66,30 +65,30 @@ The methods to generate code are quite simple and intuitive to use:
6665
- `println` is used to print a string followed by a new line;
6766
- `printList` is used to print a list of nodes; You can specify a prefix, suffix and separator;
6867
- `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;
7069
- `dedent` is used to decrease the indentation level which will be checked by the `print` and `println` methods.
7170

7271
## Testing
7372

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.
7574

7675
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.
7776

7877
It is also a good practise to have end-to-end tests, and one can follow 2 methods:
7978

80-
1. **AST to AST testing**:
79+
1. AST to AST testing:
8180

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.
8685

8786
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.
8887

89-
2. **AST to code testing**:
88+
2. AST to code testing:
9089

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.
9493

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.

docs/docs/common-elements.md

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,16 @@ title: Common Elements
44
sidebar_label: Common Elements
55
---
66

7-
# Common Elements
7+
# AST Common Elements
88

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.
1010

11-
## Core Components
11+
They are:
1212

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
1816

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)_
2418

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._

docs/docs/cross-platform-parsers.md

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,14 @@ title: Cross-Platform Parsers
44
sidebar_label: Cross-Platform Parsers
55
---
66

7-
# Cross-Platform Parsers
7+
# Cross-platform parsers
88

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.
1010

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:
1212

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
1816

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
42-
- **Testing**: Shared test suites and validation
43-
44-
### Platform-Specific Features
45-
- **Performance Optimization**: Platform-specific optimizations
46-
- **Tool Integration**: Native platform tool integration
47-
- **Library Ecosystem**: Platform-specific library usage
48-
49-
## Use Cases
50-
51-
- **Multi-Platform Tools**: Tools that work on multiple platforms
52-
- **Language Servers**: Cross-platform language intelligence
53-
- **Code Analysis**: Platform-independent code analysis
54-
- **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.

docs/docs/dual-code-model-apis.md

Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,21 @@ title: Dual Code Model APIs
44
sidebar_label: Dual Code Model APIs
55
---
66

7-
# Dual Code Model APIs
7+
# The Dual Code Model APIs
88

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.
1011

11-
## Homogeneous API
12+
## Homogenous APIs
1213

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...
1416

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.
1919

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
2122

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.
24+
This is what we call a heterogeneous API.

docs/docs/emf-interoperability.md

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,21 @@ sidebar_label: EMF Interoperability
66

77
# EMF Interoperability
88

9-
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.
1010

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.
1213

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.
1715

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.
2218

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).
2422

25-
- **Eclipse Ecosystem**: Leverage existing Eclipse tools and plugins
26-
- **Visual Modeling**: Create graphical model editors
27-
- **Standards Compliance**: Follow EMF modeling standards
28-
- **Tool Integration**: Work with EMF-based development tools
29-
30-
## Implementation
31-
32-
Starlasu provides:
33-
34-
- **ECore Adapters**: Convert between Starlasu and EMF models
35-
- **XMI Support**: Import/export models in XMI format
36-
- **Validation Integration**: Use EMF validation with Starlasu models
37-
- **Editor Support**: Create EMF-based visual editors
23+
Read more about this topic in:
24+
- [Kolasu](https://javadoc.io/doc/com.strumenta.kolasu/kolasu-emf/latest/index.html) ([source code](https://github.com/Strumenta/kolasu/tree/master/emf))
25+
- [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._
26+
- [Tylasu](https://strumenta.github.io/tylasu/modules/interop_ecore.html) ([source code](https://github.com/Strumenta/tylasu/blob/master/src/interop/ecore.ts))

docs/docs/naming.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
id: naming
3+
title: Naming
4+
sidebar_label: Naming
5+
---
6+
7+
# Naming
8+
9+
Two interfaces are defined:
10+
11+
- 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

Comments
 (0)