Crate nyandere

Crate nyandere 

Source
Expand description

§General structure

Nyandere is a language. A language generally consists of:

PartDescriptionImplementation
AlphabetThe building blocks of structures/sentences.syntax::lex
SyntaxHow structures are formed and look like.syntax
SemanticsWhat 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:

  1. Load source code as a string.
  2. Parse string into a Script using syntax::parse.
    • Script serves as the AST root
  3. Run the Script in the Runtime using Runtime::run

§Adding new commands

Task list for adding a new command nya:

§1. Syntax

  1. Think of one (where is it used? what are its arguments?)
  2. Update doc/syntax.abnf appropriately
  3. Expand the AST in syntax::ast to include nya below Stmt in the tree
  4. Parse it in syntax::parse

§2. Semantics

  1. Add a submodule nya in runtime::cmd for the command
  2. In there, write a type Nya with the type-restricted fields for the command
  3. Implement runtime::cmd::Command for Nya

§3. Testing

Try to cover both edge cases and typical use cases.


  1. 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 parse generated for it, returning Result<Self, crate::error::Construction>.

Functions§

eval
Parses and runs the given script, returning the final runtime state.
run

Type Aliases§

Map
Name
NameRef
Set