aboutsummaryrefslogtreecommitdiffstats
path: root/src
AgeCommit message (Collapse)Author
2018-08-22Add `MapGroup::parse()`; Start Cocoa functionTeddy Wing
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
2018-08-22Move all code in `lib.rs` to `parser.rs`Teddy Wing
Put our parsing code in its own module. We'll be creating a new `cocoa` module and doing this allows us to keep `lib` free as a module container.
2018-08-20Parse whole map file stringsTeddy Wing
Very important: file must be terminated by a newline in order to parse correctly because of the way `Action`s are parsed. Will need to correct this to work for EOF also. We can now parse a whole file of map and mode definitions!
2018-08-20definitions(): Get rid of failed implementation attemptsTeddy Wing
Clear out the commented failed attempts from e96b453f33345ba08c8150192157077f310f1b01.
2018-08-20Parse multiple maps and modes intermixedTeddy Wing
Create a new `Definition` item type that groups `Map` and `Mode` into a single type that we can expect on a parser. This allows us to make a parser that can parse both modes & maps. A bunch of failed attempts, but finally managed to get something working, yay!
2018-08-20Try to parse a `MapGroup`Teddy Wing
No dice. Getting this error: thread 'tests::map_group_parses_a_whole_map_file_string' panicked at 'assertion failed: `(left == right)` left: `Err(Errors { position: PointerOffset(4376730950), errors: [Unexpected(Token('a')), Expected(Borrowed("mode"))] })`, right: `Ok(MapGroup { maps: {[Down]: MapAction { action: "/bin/echo nothing", kind: Command }, [Play]: MapAction { action: "/usr/bin/say hello", kind: Command }}, modes: {[Down, Up]: {[Play]: MapAction { action: "p", kind: Map }}} })`', src/lib.rs:421:9 I need a way to parse modes and maps in any order. Here the code is trying to parse first modes, then maps.
2018-08-19Parse modesTeddy Wing
Add a new `Mode` type to parse into, similar to the `Map` type we made recently. Parse a mode definition, which contains a `MapCollection`. Modes cannot contain other modes, so we don't bother worrying about recursive parsers.
2018-08-19map_collection(): Handle whitespace between map definitionsTeddy Wing
Add support for blank, whitespace, and comment lines between and around map definition lines. Fiddled with the existing functions I had for this, but finally managed to get it working, still using Combine's `examples/ini.rs` as a reference.
2018-08-17Parse a single-element `MapCollection`Teddy Wing
Managed to get `MapCollection` parsing working, but only for a single mapping for now. Need to figure out what I'm doing wrong. Here's the result of my test: thread 'tests::map_collection_parses_maps' panicked at 'assertion failed: `(left == right)` left: `Ok({[Up, Down]: MapAction { action: "test", kind: Map }})`, right: `Ok({[Down]: MapAction { action: "/usr/bin/say \'hello\'", kind: Command }, [Up, Down]: MapAction { action: "test", kind: Map }})`', src/lib.rs:265:9 note: Run with `RUST_BACKTRACE=1` for a backtrace. test tests::map_collection_parses_maps ... FAILED At first the assertion in the test wasn't working, failing to compile with this error: error[E0369]: binary operation `==` cannot be applied to type `std::collections::HashMap<std::vec::Vec<HeadphoneButton>, MapAction>` --> src/lib.rs:266:9 | 266 | assert_eq!(result.unwrap(), expected); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: an implementation of `std::cmp::PartialEq` might be missing for `std::collections::HashMap<std::vec::Vec<HeadphoneButton>, MapAction>` = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) Finally realised that I needed to derive `PartialEq` on `MapAction` to make it work. Added a comment parser, based on the `examples/ini.rs` example from Combine: fn whitespace<I>() -> impl Parser<Input = I> where I: Stream<Item = char>, I::Error: ParseError<I::Item, I::Range, I::Position>, { let comment = (token(';'), skip_many(satisfy(|c| c != '\n'))).map(|_| ()); // Wrap the `spaces().or(comment)` in `skip_many` so that it skips alternating whitespace and // comments skip_many(skip_many1(space()).or(comment)) } Tried writing a test for `comment()`, but couldn't get it to work, presumably because `comment()` doesn't have any output: #[test] fn comment_parses_line_comments() { let text = "# This is a comment "; let result = comment().parse(text).map(|t| t.0); // print!("{:?}", result); assert_eq!(result, Ok(())); }
2018-08-16Parse single map definitionsTeddy Wing
Parse a map definition line into a `Map`. Got so stuck on this error: error[E0277]: the trait bound `(): combine::Parser` is not satisfied --> src/lib.rs:107:16 | 107 | fn map<I>() -> impl Parser<Input = I, Output = Map> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `combine::Parser` is not implemented for `()` | = note: the return type of a function must have a statically known size error: aborting due to previous error For more information about this error, try `rustc --explain E0277`. Turns out the problem was that I had put a semicolon at the end of the expression in `map()`. Geez. Took hours to finally see that.
2018-08-16New `Map` struct; Rename existing `Map` struct to `MapAction`Teddy Wing
Add a new `Map` type that includes a field for `trigger`. This allows us to parse a single map definition line into a single struct, making parsing more granular than going directly to `MapCollection`. Rename the existing `Map` type to `MapAction` to support this change.
2018-08-16Try to parse a `MapCollection`Teddy Wing
Can't get this to work. Right now I'm getting this error when running my test: Err(Errors { position: PointerOffset(4522385157), errors: [Unexpected(Token('m')), Expected(Borrowed("lf newline")), Expected(Borrowed("whitespace")), Expected(Borrowed("tab"))] }) It's supposed to parse a set of map lines, including whitespace and comments, into a `MapCollection`. Right now I'm thinking I should split this up more and make a more fine-grained parser for just a single map line, then build up to the collection from there.
2018-08-09Add parser for map actionTeddy Wing
For now just parses a string to a newline. In the future this will have to be more complicated to deal with `<...>`-style special characters and escaping (darn).
2018-08-09Ignore case when parsing `HeadphoneButton`Teddy Wing
Should work with `<play>`, `<Play>`, `<PLAY>`, `<PlAy>`.
2018-08-09Parse a `Trigger`, or sequence of `HeadphoneButton`sTeddy Wing
So cool! I love parser combinators.
2018-08-09Parse headphone buttons (`<play>`, `<up>`, `<down>`)Teddy Wing
Parses a headphone button into the `HeadphoneButton` enum.
2018-08-09map_kind(): Remove old commented codeTeddy Wing
These were early tests to figure out how to parse my tokens.
2018-08-09Parser for `map` and `cmd` keywordsTeddy Wing
This parser reads those tokens and parses them to `MapKind` types. Took a bit of struggling and researching, but it's so cool to see it working now!
2018-08-08Add `MapCollection` type aliasTeddy Wing
Further cleans up the `HashMap` definition in `DKMapGroup`.
2018-08-08Make `Trigger` a list of headphone buttonsTeddy Wing
Cleans up the `HashMap` definition in `DKMapGroup`.
2018-08-08Make `Trigger` an enum instead of a `String`Teddy Wing
`Trigger` can only be one of three values, so it should really be an enum. But of course, the actual trigger is a set of these buttons, so we want a list of trigger buttons as the map hash keys.
2018-08-08Make map `kind` an enum; Fix `modes` typeTeddy Wing
The `kind` has a specific set of things that it can be. It didn't need to be a `String`. Fix `DKMapGroup.modes` to ensure that values are map hashes. Remove `trigger` from `Map` because it didn't make sense to include it in the `HashMap` value if it's the hash key.
2018-08-08Add some types to use for storing the parsed resultTeddy Wing
Imagining how the data should be stored after parsing the map file.
2018-08-08Initialise new project with CargoTeddy Wing
$ cargo init --lib $ rustc --version rustc 1.28.0 (9634041f0 2018-07-30)