summaryrefslogtreecommitdiffstats
path: root/src/parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.rs')
-rw-r--r--src/parser.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/parser.rs b/src/parser.rs
new file mode 100644
index 0000000..4b78944
--- /dev/null
+++ b/src/parser.rs
@@ -0,0 +1,49 @@
+use nom::{
+ IResult,
+ character::complete::alphanumeric0,
+ character::complete::alphanumeric1,
+ character::complete::anychar,
+ bytes::complete::tag,
+ multi::many1,
+ multi::many0,
+ //branch::alt,
+ //combinator::opt,
+ sequence::tuple
+};
+
+fn command(i: &str) -> IResult<&str, String> {
+ match tuple((anychar,alphanumeric0))(i) {
+ Ok((rest, (c, s))) => {
+ let tmp = format!("{}{}", c, s);
+ Ok((rest, tmp))
+ },
+ Err(e) => Err(e)
+ }
+}
+
+fn parameter(i: &str) -> IResult<&str, &str> {
+ alphanumeric1(i)
+}
+
+fn ligature(i: &str) -> IResult<&str, char> {
+ match tag(";")(i) {
+ Ok((rest, c)) =>
+ Ok((rest, c.chars().nth(0).unwrap())),
+ Err(e) => Err(e)
+ }
+}
+
+fn command_line(i: &str) -> IResult<&str, Vec<String>> {
+ match tuple((command, many0(parameter)))(i) {
+ Ok((rest, (com, params))) => {
+ let mut cmd = vec!(com);
+ params.iter().for_each(|p| cmd.push(String::from(*p)));
+ Ok((rest, cmd))
+ },
+ Err(e) => Err(e)
+ }
+}
+
+fn command_string(i: &str) -> IResult<&str, Vec<(Vec<String>,char)>> {
+ many1(tuple((command_line, ligature)))(i)
+}