ldscript_parser/
lib.rs

1//! Linker Script parser
2//!
3//! # Usage
4//!
5//! ```
6//! extern crate ldscript_parser as lds;
7//!
8//! use std::fs::File;
9//! use std::io::Read;
10//!
11//! fn main() {
12//!     let script = &mut String::new();
13//!     File::open("tests/msp430bt5190.ld").unwrap()
14//!                 .read_to_string(script).unwrap();
15//!
16//!     println!("{:#?}", lds::parse(script).unwrap());
17//! }
18//! ```
19//!
20//! # References
21//!
22//! - [GNU binutils documentation](https://sourceware.org/binutils/docs/ld/Scripts.html#Scripts)
23//!
24
25extern crate nom;
26
27#[macro_use]
28mod utils;
29#[macro_use]
30mod whitespace;
31mod commands;
32mod expressions;
33mod idents;
34mod memory;
35mod numbers;
36mod script;
37mod sections;
38mod statements;
39
40pub use commands::Command;
41pub use expressions::BinaryOperator;
42pub use expressions::Expression;
43pub use expressions::UnaryOperator;
44pub use memory::Region;
45pub use script::RootItem;
46pub use sections::DataType;
47pub use sections::OutputSectionCommand;
48pub use sections::OutputSectionConstraint;
49pub use sections::OutputSectionType;
50pub use sections::SectionCommand;
51pub use sections::SectionPattern;
52pub use statements::AssignOperator;
53pub use statements::Statement;
54
55/// Parses the string that contains a linker script
56pub fn parse(ldscript: &str) -> Result<Vec<RootItem>, String> {
57    match script::parse(ldscript) {
58        Ok((_, result)) => Ok(result),
59        //TODO: add error handling
60        Err(e) => Err(format!("Parsing failed, error: {:?}", e)),
61    }
62}