From f5ec40b8fbbe7d4409d94dafcbfcdd41b8a6202b Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Fri, 25 Dec 2020 16:31:48 -0800 Subject: got the path stuff parsing just right --- src/path/parser.lalrpop | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/path/parser.lalrpop (limited to 'src/path/parser.lalrpop') diff --git a/src/path/parser.lalrpop b/src/path/parser.lalrpop new file mode 100644 index 0000000..0b3be9a --- /dev/null +++ b/src/path/parser.lalrpop @@ -0,0 +1,82 @@ +grammar; + +use crate::path::GenericPath; +use crate::path::GenericPathComponent; + +pub PathList: Vec = { + => { + Vec::new() + }, + COLON)*> => { + left.push(right); + left + }, +}; + +pub PathListAllowingEmptyPaths: Vec = { + => vec![GenericPath { + components: Vec::new(), + starts_with_slash: false, + ends_with_slash: false, + }], + PathNoColons => vec![<>], + COLON => { + left.push(GenericPath { + components: Vec::new(), + starts_with_slash: false, + ends_with_slash: false, + }); + left + }, + COLON => { + left.push(right); + left + }, +} + +pub PathNoColons: GenericPath = { + SLASH => GenericPath { + components: Vec::new(), + starts_with_slash: true, + ends_with_slash: true, + }, + => GenericPath { + components: <>, + starts_with_slash: false, + ends_with_slash: false, + }, + SLASH => GenericPath { + components: <>, + starts_with_slash: false, + ends_with_slash: true, + }, + SLASH => GenericPath { + components: <>, + starts_with_slash: true, + ends_with_slash: false, + }, + SLASH SLASH => GenericPath { + components: <>, + starts_with_slash: true, + ends_with_slash: true, + }, +} + +PathNoColons2: Vec = { + => + vec![GenericPathComponent::FileOrDirectoryName(<>.to_string())], + SLASH => { + left.push(GenericPathComponent::FileOrDirectoryName(right.to_string())); + left + } +} + +// Whitespace is not allowed. +match { + r"[^z:/]+" => PATH_COMPONENT_NO_COLONS, + + r"/" => SLASH, + + ":" => COLON, +} + -- cgit 1.4.1