aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cocoa.rs13
-rw-r--r--src/lib.rs3
-rw-r--r--src/parser.rs11
3 files changed, 27 insertions, 0 deletions
diff --git a/src/cocoa.rs b/src/cocoa.rs
new file mode 100644
index 0000000..58d74d2
--- /dev/null
+++ b/src/cocoa.rs
@@ -0,0 +1,13 @@
+extern crate cocoa;
+
+use MapGroup;
+
+pub extern "C" fn x() {
+ let sample_maps = "map <up> k
+map <down> j";
+
+ let map_group = MapGroup::parse(sample_maps);
+
+ unsafe {
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index cf634d2..8e9a592 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,4 +1,7 @@
#[macro_use]
extern crate combine;
+mod cocoa;
mod parser;
+
+use parser::MapGroup;
diff --git a/src/parser.rs b/src/parser.rs
index e30c5f4..a34edff 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use combine::*;
+use combine::easy::Errors as CombineErrors;
use combine::parser::choice::or;
use combine::parser::char::{
newline,
@@ -10,6 +11,7 @@ use combine::parser::char::{
tab,
};
use combine::parser::repeat::take_until;
+use combine::stream::state::{SourcePosition, State};
#[derive(Debug, Hash, Eq, PartialEq)]
pub enum HeadphoneButton {
@@ -59,6 +61,15 @@ enum Definition {
Mode(Mode),
}
+impl MapGroup {
+ pub fn parse(
+ mappings: &str
+ ) -> Result<MapGroup, CombineErrors<char, &str, SourcePosition>> {
+ let input = State::new(mappings);
+ map_group().easy_parse(input).map(|t| t.0)
+ }
+}
+
fn map_kind<I>() -> impl Parser<Input = I, Output = MapKind>
where