Skip to main content

parse_source

Function parse_source 

Source
pub fn parse_source(source: &str) -> (Program, DiagnosticBag)
Expand description

Lex and parse a CJC source string in a single call.

This is the recommended entry point for most callers. It creates a cjc_lexer::Lexer, tokenizes the input, feeds the tokens into a Parser, and returns the resulting AST with merged lexer and parser diagnostics.

§Arguments

  • source - The raw CJC source code to parse.

§Returns

A tuple of:

  • Program - The parsed AST (may be partial when errors are present).
  • DiagnosticBag - Combined lexer and parser diagnostics.

§Example

let (program, diags) = cjc_parser::parse_source("fn main() { 42 }");
assert!(!diags.has_errors());
assert_eq!(program.declarations.len(), 1);