Expand description
This module contains parser of the code.
Parse steps are:
fn split_code()
- Split code into characters.fn find_blocks()
- Find blocks from the code.fn connect_blocks()
- Connect blocks by following edges.
§Example:
use trees_lang::compile::{split_code, find_blocks, connect_blocks, CompileConfig};
let splited_code = split_code(
&vec![
" ".to_owned(),
" ┌───────┐".to_owned(),
" │ abc │ ".to_owned(),
" └───┬───┘ ".to_owned(),
" │ ".to_owned(),
" ┌───┴──┐".to_owned(),
" │ def │ ".to_owned(),
" └──────┘ ".to_owned(),
],
&CompileConfig::DEFAULT,
);
let mut blocks = find_blocks(&splited_code, &CompileConfig::DEFAULT);
let head = connect_blocks(&splited_code, &mut blocks, &CompileConfig::DEFAULT).unwrap();
assert_eq!(head.proc_name, "abc".to_owned());
Modules§
- errors
- Module containing error types for the compiler.
Structs§
- ArgPlug
- An argument plug in a
CompilingBlock
, indicating where an argument can be connected. - Block
Plug - A plug point for a block, where it can be connected to other blocks.
- Code
Character - A single character in the source code with layout metadata.
- Compile
Config - Stores settings used during code compilation.
- Compiling
Block - A parsed visual block in the code, including its position, size, and connections.
- Edge
- An edge connecting two blocks, including fragments and plug information.
- Edge
Fragment - A fragment of an edge in the code’s flow, with position and direction.
- Splited
Code - A code that has been split into lines and characters for processing
Enums§
- Char
Width Mode - Determines how character widths are calculated during code parsing.
- Orientation
- Direction/orientation used for argument and edge routing.
- Quote
Style - Quote style of block.
Functions§
- connect_
blocks - Connects the blocks by resolving edges between argument plugs and block plugs.
- find_
blocks - Finds all the blocks in a given split code according to configuration.
- split_
code - Splits a list of code lines into a
SplitedCode
representation.