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). UseEngine::compileandEngine::eval_compiledto execute programs constructed from deserialized ASTs. When this feature is enabled,serdeandserde_jsondependencies 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
- Builtin
Function Doc - Builtin
Selector Doc - Compiled
Program - A compiled mq program bundled with its original source, returned by
Engine::compile. - Default
Module Resolver - 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.
- Ident
With Token - Lexer
Options - Module
- Module
Loader - 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.
- Runtime
Values - A collection of runtime values.
- Token
Enums§
- AstExpr
- AstLiteral
- AstPattern
- Attr
Kind - Represents an attribute that can be accessed from markdown nodes.
- Module
Error - Errors that can occur while loading or resolving mq modules.
- Optimization
Level - Controls which optimization passes are applied by the [
Optimizer]. - Runtime
Value - A value in the mq runtime.
- Selector
- A selector for matching specific types of markdown nodes.
- String
Segment - Token
Kind - Represents the kind of a token in the mq language.
Constants§
Statics§
Traits§
- Module
Resolver - Core interface for resolving mq module source code by name.
Functions§
- bytes_
input - Returns a vector containing a single
RuntimeValue::Bytesfor raw binary input. - null_
input - Returns a vector containing a single
Valuerepresenting an empty input. - parse
- parse_
html_ input - parse_
html_ input_ with_ options - parse_
markdown_ input - Parses a Markdown string and returns an iterator over
Valuenodes. - parse_
mdx_ input - Parses an MDX string and returns an iterator over
Valuenodes. - parse_
text_ input - Parses a plain text string and returns an iterator over
Valuenode. - raw_
input - Parses a raw input string and returns a vector containing a single
Valuenode.
Type Aliases§
- AstParams
- Default
Engine - Default
Module Loader - Module
Id - MqResult
- Program
- Shared
- Type alias for reference-counted pointer, switches between Shared and Arc depending on “sync” feature.
- Shared
Cell - Type alias for interior mutability, switches between SharedCell and RwLock depending on “sync” feature.