pub struct ParserConfig {
pub parse_expressions: bool,
pub language: Language,
}
Expand description
Configuration for IR generation and expression parsing
This controls how the parser converts syntax to IR, particularly how it handles expressions.
§Learning: Configuration Pattern
Rather than using global state or command-line flags, we pass configuration explicitly. This makes the code:
- Testable: Easy to test with different configs
- Composable: Multiple parsers with different configs
- Thread-safe: No global mutable state
§Example
use roup::ir::{ParserConfig, Language};
// Default: parse expressions
let default_config = ParserConfig::default();
assert!(default_config.parse_expressions);
// Custom: disable expression parsing
let string_only = ParserConfig {
parse_expressions: false,
language: Language::C,
};
Fields§
§parse_expressions: bool
Whether to attempt parsing expressions into structured form
true
(default): Parse expressions, fall back to string on failurefalse
: Keep all expressions as raw strings
language: Language
Source language (affects expression parsing rules)
Different languages have different expression syntax:
- C/C++:
arr[i]
,*ptr
,x->y
- Fortran:
arr(i)
, different operators
Implementations§
Source§impl ParserConfig
impl ParserConfig
Sourcepub const fn new(parse_expressions: bool, language: Language) -> Self
pub const fn new(parse_expressions: bool, language: Language) -> Self
Create a new configuration
Sourcepub const fn string_only(language: Language) -> Self
pub const fn string_only(language: Language) -> Self
Create config that keeps all expressions as strings
Sourcepub const fn with_parsing(language: Language) -> Self
pub const fn with_parsing(language: Language) -> Self
Create config that parses expressions
Trait Implementations§
Source§impl Clone for ParserConfig
impl Clone for ParserConfig
Source§fn clone(&self) -> ParserConfig
fn clone(&self) -> ParserConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ParserConfig
impl Debug for ParserConfig
Source§impl Default for ParserConfig
impl Default for ParserConfig
Source§impl PartialEq for ParserConfig
impl PartialEq for ParserConfig
impl Copy for ParserConfig
impl Eq for ParserConfig
impl StructuralPartialEq for ParserConfig
Auto Trait Implementations§
impl Freeze for ParserConfig
impl RefUnwindSafe for ParserConfig
impl Send for ParserConfig
impl Sync for ParserConfig
impl Unpin for ParserConfig
impl UnwindSafe for ParserConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more