pub struct FlowParser { /* private fields */ }Expand description
A reusable Flow parser instance backed by QuickJS.
Create once, parse many times. The QuickJS context is reused across calls.
Implementations§
Source§impl FlowParser
impl FlowParser
Sourcepub fn new() -> Result<Self, Error>
pub fn new() -> Result<Self, Error>
Create a new parser instance.
Loads the Flow parser JS into a QuickJS context.
Sourcepub fn parse_json(&self, source: &str) -> Result<String, Error>
pub fn parse_json(&self, source: &str) -> Result<String, Error>
Parse Flow source and return the raw JSON AST.
Sourcepub fn parse(&self, source: &str) -> Result<Program, Error>
pub fn parse(&self, source: &str) -> Result<Program, Error>
Parse Flow source and return the typed AST.
Sourcepub fn validate(&self, source: &str) -> Result<(), Error>
pub fn validate(&self, source: &str) -> Result<(), Error>
Validate that source is syntactically valid Flow.
Returns Ok(()) if the source parses without errors, Err otherwise.
Sourcepub fn diagnostics(&self, source: &str) -> Result<Vec<ParseError>, Error>
pub fn diagnostics(&self, source: &str) -> Result<Vec<ParseError>, Error>
Parse source and return all diagnostics (parse errors with location).
Returns Ok(vec![]) for valid source. Returns Ok(errors) when the
source has parse errors — each error carries a message and source location.
Returns Err only on runtime or deserialization failure.
Sourcepub fn validate_declaration(&self, decl: &str) -> Result<Program, Error>
pub fn validate_declaration(&self, decl: &str) -> Result<Program, Error>
Validate a Flow type declaration by wrapping it in a // @flow file.
Accepts a bare declaration like type Foo = string; and wraps it as:
// @flow
export type Foo = string;Declarations starting with declare export are wrapped without adding
export (they already include it).