rawk_core/awk.rs
1//! Facade for running AWK scripts with rawk-core.
2//!
3//! This module wires together the lexer, parser, and evaluator so callers only
4//! need to provide a program string and input lines. The lexer tokenizes the
5//! script, the parser builds an AST `Program`, and the evaluator walks that
6//! program against the provided data to produce output lines.
7//!
8//! Example:
9//! ```
10//! use rawk_core::awk;
11//!
12//! let output = awk::execute("{print}", vec!["foo".into(), "bar".into()]);
13//! assert_eq!(output, vec!["foo".to_string(), "bar".to_string()]);
14//! ```
15use crate::{Evaluator, Lexer, Parser};
16
17/// Execute an AWK script against the given input lines and return the output.
18///
19/// `script` is the raw AWK program text (e.g., `{print}`) and `input`
20/// contains the lines to process. The script is lexed, parsed, and then
21/// evaluated; the resulting output lines are returned in order.
22pub fn execute(script: &str, input: Vec<String>) -> Vec<String> {
23 let lexer = Lexer::new(script);
24 let mut parser = Parser::new(lexer);
25 let program = parser.parse_program();
26 let mut evaluator = Evaluator::new(program, input);
27
28 evaluator.eval()
29}