Crate cirru_parser

Crate cirru_parser 

Source
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 2

parses to:

[ ["defn" "fib" [ "x" ]
    [ "if" [ "<=" "x" "2" ] "1"
      [ "+" [ "fib" ["dec" "x"] ] [ "fib" ["-" "x" "2"] ] ]
    ]
] ]

find more on http://text.cirru.org/ .

Structs§

CirruError
Main error type for Cirru parsing
CirruWriterOptions
options for writer, use_inline for more compact format.
ErrorContext
Context information for better error messages
SourcePos
Position information in the source code

Enums§

Cirru
Cirru uses nested Vecters and Strings as data structure
CirruErrorKind
Different kinds of parse errors
CirruLexItem
internal control item during lexing

Traits§

CirruOneLinerExt
Extension trait for method-style one-liner formatting.
CirruOneLinerParseExt
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_inline option
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_simpleDeprecated
Backward compatibility function for lex that returns tokens with String error
parse
Parses a string of Cirru code into a tree of Cirru expressions.
parse_compatDeprecated
Backward compatibility function that returns Result with String error
parse_expr_one_liner
Parses a one-line Cirru expression into exactly one Cirru expression.
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 Open and Close tokens based on changes in indentation levels.

Type Aliases§

CirruLexItemList
a list to lex nodes