I am a newbie to rust.I am trying to use Nom to parse Teradata MLoad Files. I am stuck in how to implement this regex [a-zA-z_.]+ in Nom.
The above regex matches this example "Schema_Name.Table_name".
Could you also let me know whether NOM is right tool to parse Teradata Mload files and convert into another database format or I have to use any other parser in Rust.
A combinator such as take_while1 accepts a Boolean function or a closure which gets called for every input byte or character. Nom provides several such functions (is_alphabetic, is_digit etc.), but you can supply your own. The following uses nom 4 and Rust 2018 edition syntax:
use nom::is_alphabetic;
use nom::{call, named, recognize, take_while1};
use nom::types::CompleteStr;
named!(schema_table<CompleteStr, CompleteStr>,
recognize!(
take_while1!(sct_regex)
)
);
fn sct_regex(c: char) -> bool {
is_alphabetic(c as u8) || c == '.' || c == '_'
}
fn main() {
assert!(schema_table(CompleteStr("Schema_name.Table_name")).is_ok());
}