From 6624aea48840df2714b968d8a6d40579eaf41b86 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 22 Aug 2018 19:09:08 +0200 Subject: 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 --- src/parser.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/parser.rs') 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> { + let input = State::new(mappings); + map_group().easy_parse(input).map(|t| t.0) + } +} + fn map_kind() -> impl Parser where -- cgit v1.2.3