Module rsjsonnet_lang::parser

source ·
Expand description

A parser for the Jsonnet language.

§Example

let source = b"local add_one(x) = x + 1; add_one(2)";

let str_interner = rsjsonnet_lang::interner::StrInterner::new();
let mut span_mgr = rsjsonnet_lang::span::SpanManager::new();
let (span_ctx, _) = span_mgr.insert_source_context(source.len());

// First, lex the source excluding whitespace and comments.
let lexer = rsjsonnet_lang::lexer::Lexer::new(&str_interner, &mut span_mgr, span_ctx, source);
let tokens = lexer.lex_to_eof(false).unwrap();

// Create the parser.
let parser = rsjsonnet_lang::parser::Parser::new(&str_interner, &mut span_mgr, tokens);

// Parse the source.
let ast_root = parser.parse_root_expr().unwrap();

Structs§

Enums§