pub struct CParser { /* private fields */ }Expand description
C parser using clang-sys.
§Examples
use decy_parser::parser::CParser;
let parser = CParser::new()?;
let ast = parser.parse("int main() { return 0; }")?;
assert_eq!(ast.functions().len(), 1);Implementations§
Source§impl CParser
impl CParser
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Create a new C parser.
This automatically discovers system include paths from the clang compiler.
§Examples
use decy_parser::parser::CParser;
let parser = CParser::new()?;Sourcepub fn parse_file(&self, path: &Path) -> Result<Ast>
pub fn parse_file(&self, path: &Path) -> Result<Ast>
Parse a C file into an AST.
§Arguments
path- Path to the C file
§Returns
Ok(Ast)- The parsed ASTErr(anyhow::Error)- If parsing fails
Parse C source code from a file path.
DECY-237: This method allows includes to resolve properly by parsing from the actual file path instead of an in-memory string.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CParser
impl RefUnwindSafe for CParser
impl !Send for CParser
impl !Sync for CParser
impl Unpin for CParser
impl UnwindSafe for CParser
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