Module compile

Source
Expand description

This module contains parser of the code.

Parse steps are:

  1. fn split_code() - Split code into characters.
  2. fn find_blocks() - Find blocks from the code.
  3. 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.
BlockPlug
A plug point for a block, where it can be connected to other blocks.
CodeCharacter
A single character in the source code with layout metadata.
CompileConfig
Stores settings used during code compilation.
CompilingBlock
A parsed visual block in the code, including its position, size, and connections.
Edge
An edge connecting two blocks, including fragments and plug information.
EdgeFragment
A fragment of an edge in the code’s flow, with position and direction.
SplitedCode
A code that has been split into lines and characters for processing

Enums§

CharWidthMode
Determines how character widths are calculated during code parsing.
Orientation
Direction/orientation used for argument and edge routing.
QuoteStyle
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.