aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dotup/cfg.rs28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/dotup/cfg.rs b/src/dotup/cfg.rs
index efa67e2..7caee4e 100644
--- a/src/dotup/cfg.rs
+++ b/src/dotup/cfg.rs
@@ -3,10 +3,11 @@ use std::fmt::Write;
3use nom::{ 3use nom::{
4 branch::alt, 4 branch::alt,
5 bytes::complete::{tag, take_while}, 5 bytes::complete::{tag, take_while},
6 character::complete::{alphanumeric1, multispace0, multispace1, space1}, 6 character::complete::{multispace0, multispace1, space1},
7 combinator::map, 7 combinator::map,
8 multi::separated_list0, 8 multi::separated_list0,
9 sequence::{delimited, preceded}, 9 sequence::{delimited, preceded},
10 InputTakeAtPosition,
10}; 11};
11 12
12type Span<'s> = nom_locate::LocatedSpan<&'s str>; 13type Span<'s> = nom_locate::LocatedSpan<&'s str>;
@@ -215,7 +216,7 @@ fn linesep(i: Span) -> IResult<Span, Span> {
215} 216}
216 217
217fn keyvalue(i: Span) -> IResult<Span, KeyValue> { 218fn keyvalue(i: Span) -> IResult<Span, KeyValue> {
218 let (i, key) = alphanumeric1(i)?; 219 let (i, key) = ident1(i)?;
219 let (i, _) = tag("=")(i)?; 220 let (i, _) = tag("=")(i)?;
220 let (i, val) = delimited(tag("\""), take_while(is_value_char), tag("\""))(i)?; 221 let (i, val) = delimited(tag("\""), take_while(is_value_char), tag("\""))(i)?;
221 Ok(( 222 Ok((
@@ -250,7 +251,7 @@ fn comment(i: Span) -> IResult<Span, Comment> {
250 251
251fn action(i: Span) -> IResult<Span, Action> { 252fn action(i: Span) -> IResult<Span, Action> {
252 let location = location_from_span(i); 253 let location = location_from_span(i);
253 let (i, kind) = alphanumeric1(i)?; 254 let (i, kind) = ident1(i)?;
254 let (i, keyvalues) = preceded(space1, keyvalues)(i)?; 255 let (i, keyvalues) = preceded(space1, keyvalues)(i)?;
255 Ok(( 256 Ok((
256 i, 257 i,
@@ -275,7 +276,7 @@ fn group(i: Span) -> IResult<Span, Group> {
275 276
276 let (i, _) = tag("group")(i)?; 277 let (i, _) = tag("group")(i)?;
277 let (i, _) = multispace1(i)?; 278 let (i, _) = multispace1(i)?;
278 let (i, name) = alphanumeric1(i)?; 279 let (i, name) = ident1(i)?;
279 let (i, _) = multispace0(i)?; 280 let (i, _) = multispace0(i)?;
280 let (i, _) = tag("{")(i)?; 281 let (i, _) = tag("{")(i)?;
281 let (i, _) = multispace0(i)?; 282 let (i, _) = multispace0(i)?;
@@ -316,6 +317,10 @@ fn location_from_span(span: Span) -> Location {
316 Location::new(span.location_line(), span.get_utf8_column() as u32) 317 Location::new(span.location_line(), span.get_utf8_column() as u32)
317} 318}
318 319
320fn ident1(i: Span) -> IResult<Span, Span> {
321 i.split_at_position_complete(|c: char| !(c.is_alphanumeric() || c == '_' || c == '-'))
322}
323
319#[cfg(test)] 324#[cfg(test)]
320mod tests { 325mod tests {
321 use super::*; 326 use super::*;
@@ -329,6 +334,21 @@ mod tests {
329 } 334 }
330 335
331 #[test] 336 #[test]
337 fn parse_keyvalue_dash() {
338 // key with dash
339 let input = Span::new(r#"key-value="value""#);
340 let (rem, kv) = keyvalue(input).unwrap();
341 assert!(rem.is_empty());
342 assert_eq!(kv, KeyValue::new("key-value", "value"),);
343
344 // value with dash
345 let input = Span::new(r#"key="value-1""#);
346 let (rem, kv) = keyvalue(input).unwrap();
347 assert!(rem.is_empty());
348 assert_eq!(kv, KeyValue::new("key", "value-1"),);
349 }
350
351 #[test]
332 fn parse_keyvalues() { 352 fn parse_keyvalues() {
333 let kvs = vec![ 353 let kvs = vec![
334 KeyValue::new("key1", "value1"), 354 KeyValue::new("key1", "value1"),