Expand description
§General structure
Nyandere is a language. A language generally consists of:
| Part | Description | Implementation |
|---|---|---|
| Alphabet | The building blocks of structures/sentences. | syntax::lex |
| Syntax | How structures are formed and look like. | syntax |
| Semantics | What built structures mean. | Rest of this crate |
§Why the distinction?
In short, while syntax is concerned with accurately representing the source code via types, it doesn’t cover the actual meaning. Semantics on the other hand encode what makes sense. This is not automatically given.
§Example: Valid syntax, semantically meaningful
create entity A # (1)
create entity B # (2)
balance from=A to=B # (3)While (1) and (2) don’t rely on past state, (3) does:
Entities A and B must exist for the command to be valid.
In the above case that is given: Both A and B exist and are entities.
§Example: Valid syntax, semantically nonsense
balance from=C to=D # (4)Neither entity C nor entity D exist!
Hence, while this is syntactically valid,
it is semantically invalid!
More concretely:
While syntax is able to encode (4),
it is not possible to create a runtime::cmd of (4)
without having C and D defined first.1
§Pipeline
The general processing pipeline is:
- Load source code as a string.
- Parse string into a
Scriptusingsyntax::parse.Scriptserves as the AST root
- Run the
Scriptin theRuntimeusingRuntime::run
§Adding new commands
Task list for adding a new command nya:
§1. Syntax
- Think of one (where is it used? what are its arguments?)
- Update
doc/syntax.abnfappropriately - Expand the AST in
syntax::astto includenyabelowStmtin the tree - Parse it in
syntax::parse
§2. Semantics
- Add a submodule
nyainruntime::cmdfor the command - In there, write a type
Nyawith the type-restricted fields for the command - Implement
runtime::cmd::CommandforNya
§3. Testing
Try to cover both edge cases and typical use cases.
If you do find a way, that is a bug and should be fixed. Please report it at https://codeberg.org/MultisampledNight/nyandere! ↩
Re-exports§
pub use runtime::Runtime;
Modules§
- aux
- Auxiliary macros and the works.
- error
- All kinds of runtime errors.
- ext
- Interact with and construct the outside world.
- runtime
- Process and understand.
- syntax
- Parse text into an AST.
Macros§
- cmd_
args - Define the arguments expected by a command.
The wrapped struct has an associated function
parsegenerated for it, returningResult<Self, crate::error::Construction>.