Expand description
§Cirru Parser
This tiny parser parses indentation based syntax into nested a vector, then it could used as S-Expressions for evaluation or codegen.
defn fib (x)
if (<= x 2) 1
+
fib $ dec x
fib $ - x 2parses to:
[ ["defn" "fib" [ "x" ]
[ "if" [ "<=" "x" "2" ] "1"
[ "+" [ "fib" ["dec" "x"] ] [ "fib" ["-" "x" "2"] ] ]
]
] ]find more on http://text.cirru.org/ .
Structs§
- Cirru
Error - Main error type for Cirru parsing
- Cirru
Writer Options - options for writer,
use_inlinefor more compact format. - Error
Context - Context information for better error messages
- Source
Pos - Position information in the source code
Enums§
- Cirru
- Cirru uses nested Vecters and Strings as data structure
- Cirru
Error Kind - Different kinds of parse errors
- Cirru
LexItem - internal control item during lexing
Traits§
- Cirru
OneLiner Ext - Extension trait for method-style one-liner formatting.
- Cirru
OneLiner Parse Ext - Extension trait for method-style parsing of a one-line Cirru expression.
Functions§
- cirru_
to_ lisp - Converts a string of Cirru code directly to a Lisp-like string.
- escape_
cirru_ leaf - common API for turning Cirru leaf with strings escaped
- format
- format Cirru code, use options to control
use_inlineoption - format_
expr_ one_ liner - Format a single Cirru expression as a single line without newlines or indentation.
- format_
to_ lisp - format to Cirru to WAT
- lex
- The lexer for Cirru syntax. It scans the code and returns a flat list of tokens. It uses a state machine to handle different parts of the syntax, such as strings, tokens, and indentation.
- lex_
simple Deprecated - Backward compatibility function for lex that returns tokens with String error
- parse
- Parses a string of Cirru code into a tree of
Cirruexpressions. - parse_
compat Deprecated - Backward compatibility function that returns Result with String error
- parse_
expr_ one_ liner - Parses a one-line Cirru expression into exactly one
Cirruexpression. - print_
error - Helper function to format and print a detailed error
- resolve_
indentations - This function transforms a flat list of tokens into a tree structure
by handling indentation. It inserts
OpenandClosetokens based on changes in indentation levels.
Type Aliases§
- Cirru
LexItem List - a list to lex nodes