Skip to main content

Crate newter_compiler

Crate newter_compiler 

Source
Expand description

Newt — design canvas compiler and live renderer.

Parses .newt UI source, builds a layout tree, and renders to a wgpu canvas.

Re-exports§

pub use ast::ImportDecl;
pub use ast::Program;
pub use ast::ProgramItem;
pub use ast::ScreenDecl;
pub use ast::ThemeDecl;
pub use error::format_error;
pub use error::NewtError;
pub use error::Source;
pub use error::Span;
pub use html::layout_to_html;
pub use html::layout_to_reactive_html;
pub use react::layout_to_react;
pub use layout::layout_tree;
pub use layout::LayoutNode;
pub use layout::Rect;
pub use lexer::TokenCategory;
pub use lexer::TokenKind;
pub use parser::Parser;
pub use app::App;
pub use value::EvalContext;
pub use value::Value;
pub use value::value_to_json;

Modules§

app
Application loop: winit window, file watch, and render.
ast
Abstract Syntax Tree for the Newt UI language.
error
Error types and source span handling for the Newt compiler.
html
Export layout to standalone HTML so you can open it in a browser (no GPU needed).
layout
Flex-like layout engine: computes bounds for each element from the AST.
lexer
Lexer for the Newt UI language.
parser
Recursive descent parser for the Newt UI language.
react
Generate React JSX from the Newt layout tree.
renderer
wgpu-based 2D canvas renderer for layout nodes.
serve
Canvas IDE server: HTTP + WebSocket for live-reload canvas.
value
Runtime values for the Newt interpreter (used during layout).

Enums§

SymbolKind
Symbol kind for LSP (hover, completion, go-to-definition).

Constants§

DEFAULT_SERVE_PORT
Default port for the canvas IDE server.
DEFAULT_VIEWPORT_H
DEFAULT_VIEWPORT_W
Default viewport size for IDE and export (width, height).

Functions§

check_all
Collect all parse errors from the source. Returns an empty vec on success. Designed for LSP use where all diagnostics should appear at once.
compile
Single compile entry: parse → resolve_imports (when path is set) → EvalContext → get_screen → layout_tree. Use this from CLI, serve, LSP, and app so behavior and diagnostics are consistent. Viewport is (0, 0, DEFAULT_VIEWPORT_W, DEFAULT_VIEWPORT_H) unless overridden later by the consumer.
compile_with_state
Like compile() but accepts state overrides and returns the effective state. State overrides are applied to variables matching state declarations in the program.
completion_element_names
Element names for completion (row, column, card, button, etc.).
completion_keywords
Keywords for completion (top-level and expression context).
completion_prop_names
Prop names valid for elements (layout, style, content).
get_screen
Get a screen by name. If name is None, returns the first screen. Use for multi-screen apps: Home, Dashboard, Settings, etc.
has_state_vars
Returns true if the program contains any state declarations.
parse
Parse source code into an AST. Returns the first error for backward compatibility. Use parse_all for all errors.
parse_all
Parse source code, returning all errors at once instead of stopping at the first.
parse_file
Parse a file into an AST.
resolve_imports
Resolve all import "path.newt" declarations by loading and merging those files. Avoids circular imports. base_dir is the directory of the current file.
screen_names
All screen names in the program (order preserved).
symbol_table
Build a symbol table from a program: name → (span, kind). Later definitions shadow earlier.
theme_css_vars
Collect color variables from the program for CSS export (:root { –name: #hex; }).
tokenize
Tokenize source for syntax highlighting. Returns (span, category) for each token until Eof.