aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2018-08-22 19:09:08 +0200
committerTeddy Wing2018-08-22 19:09:08 +0200
commit6624aea48840df2714b968d8a6d40579eaf41b86 (patch)
tree795d1918b89b713dba53038ddbb90f3571453f0d /src
parent5f670cf87ac217930babb0b8ef0f953fd2ee3447 (diff)
downloaddome-key-map-6624aea48840df2714b968d8a6d40579eaf41b86.tar.bz2
Add `MapGroup::parse()`; Start Cocoa function
Add a new `cocoa` module which will hold code to be called from Objective-C. Currently contains a sketch of a function that will be called via FFI from Objective-C. Haven't thought of a name for it yet. For now contains a sample map definition "file" in a hard-coded string. Tells `MapGroup` to parse the map definitions. Will try to create some Cocoa objects in the `unsafe` block. `MapGroup`: Add `parse()` method. Given a map definition string, this new function will parse the string into a `MapGroup` and return the result. It will serve as the entry point to parsing DomeKey map definitions. Thanks to these references for Combine parser error handling: - https://github.com/ordian/toml_edit/blob/b02bc3/src/parser/document.rs - https://github.com/ordian/toml_edit/blob/ee6895f/src/parser/errors.rs - https://github.com/Marwes/combine/blob/54bcfed/examples/ini.rs
Diffstat (limited to 'src')
-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