Skip to main content

Crate mq_lang

Crate mq_lang 

Source
Expand description

mq-lang provides a parser and evaluator for a mq.

§Examples

let code = "add(\"world!\")";
let input = vec![mq_lang::Value::Markdown(
  mq_markdown::Markdown::from_str("Hello,").unwrap()
)].into_iter();
let mut engine = mq_lang::DefaultEngine::default();

assert!(matches!(engine.eval(&code, input).unwrap(), mq_lang::Value::String("Hello,world!".to_string())));

// Parse code into AST nodes
use mq_lang::{tokenize, LexerOptions, AstParser, Arena};
use std::rc::Shared;
use std::cell::SharedCell;

let code = "1 + 2";
let token_arena = Shared::new(SharedCell::new(Arena::new()));
let ast = mq_lang::parse(code, token_arena).unwrap();

assert_eq!(ast.nodes.len(), 1);

// Parse code into CST nodes
use mq_lang::{tokenize, LexerOptions, CstParser};
use std::sync::Arc;

let code = "1 + 2";
let (cst_nodes, errors) = mq_lang::parse_recovery(code);

assert!(!errors.has_errors());
assert!(!cst_nodes.is_empty());

§Features

  • ast-json: Enables serialization and deserialization of the AST (Abstract Syntax Tree) to/from JSON format (ast_to_json / ast_from_json). Use Engine::compile and Engine::eval_compiled to execute programs constructed from deserialized ASTs. When this feature is enabled, serde and serde_json dependencies are included.

Structs§

Arena
An arena allocator for efficiently storing and accessing elements.
ArenaId
A type-safe identifier for elements stored in an Arena.
AstNode
AstParser
BuiltinFunctionDoc
BuiltinSelectorDoc
CompiledProgram
A compiled mq program bundled with its original source, returned by Engine::compile.
DefaultModuleResolver
The default resolver, combining standard library, local filesystem, and (optionally) HTTP sources.
Engine
The main execution engine for the mq.
Error
Represents a high-level error with diagnostic information for the user.
Ident
An interned string identifier for efficient storage and comparison.
IdentWithToken
LexerOptions
Module
ModuleLoader
Position
A position in source code, representing a line and column.
Range
A range in source code, spanning from a start position to an end position.
RuntimeValues
A collection of runtime values.
Token

Enums§

AstExpr
AstLiteral
AstPattern
AttrKind
Represents an attribute that can be accessed from markdown nodes.
ModuleError
Errors that can occur while loading or resolving mq modules.
OptimizationLevel
Controls which optimization passes are applied by the [Optimizer].
RuntimeValue
A value in the mq runtime.
Selector
A selector for matching specific types of markdown nodes.
StringSegment
TokenKind
Represents the kind of a token in the mq language.

Constants§

BUILTIN_MODULE_FILE

Statics§

BUILTIN_FUNCTION_DOC
BUILTIN_SELECTOR_DOC
INTERNAL_FUNCTION_DOC
STANDARD_MODULES

Traits§

ModuleResolver
Core interface for resolving mq module source code by name.

Functions§

bytes_input
Returns a vector containing a single RuntimeValue::Bytes for raw binary input.
null_input
Returns a vector containing a single Value representing an empty input.
parse
parse_html_input
parse_html_input_with_options
parse_markdown_input
Parses a Markdown string and returns an iterator over Value nodes.
parse_mdx_input
Parses an MDX string and returns an iterator over Value nodes.
parse_text_input
Parses a plain text string and returns an iterator over Value node.
raw_input
Parses a raw input string and returns a vector containing a single Value node.

Type Aliases§

AstParams
DefaultEngine
DefaultModuleLoader
ModuleId
MqResult
Program
Shared
Type alias for reference-counted pointer, switches between Shared and Arc depending on “sync” feature.
SharedCell
Type alias for interior mutability, switches between SharedCell and RwLock depending on “sync” feature.