Skip to content

Commit

Permalink
Add spans to class phonemes and trait members (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
fergcb authored Jul 8, 2023
1 parent e97ba8f commit ce7a87c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ pub enum Stmt {
label: Spanned<String>,
encodes: Vec<Spanned<String>>,
annotates: Vec<Spanned<String>>,
phonemes: Vec<PhonemeDef>,
phonemes: Vec<Spanned<PhonemeDef>>,
},
Series {
label: Spanned<String>,
series: Spanned<Series>,
},
Trait {
label: Spanned<String>,
members: Vec<TraitMember>,
members: Vec<Spanned<TraitMember>>,
},
Milestone {
time: Option<Spanned<Time>>,
Expand Down
9 changes: 5 additions & 4 deletions src/parser/class_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub fn parser() -> impl Parser<char, Stmt, Error = Simple<char>> {
.map(|(label, traits)| PhonemeDef { label, traits });

let body = phoneme_definition
.map_with_span(|ph, span| (span, ph))
.separated_by(just(",").padded())
.allow_trailing()
.at_least(1)
Expand Down Expand Up @@ -86,10 +87,10 @@ mod test {
encodes: vec![(17..22, "place".into()), (23..29, "manner".into())],
annotates: vec![],
phonemes: vec![
PhonemeDef { label: (43..44, "p".into()), traits: vec![(47..55, "bilabial".into()), (56..63, "plosive".into())] },
PhonemeDef { label: (75..76, "t".into()), traits: vec![(79..87, "alveolar".into()), (88..95, "plosive".into())] },
PhonemeDef { label: (107..108, "k".into()), traits: vec![(111..116, "velar".into()), (117..124, "plosive".into())] },
PhonemeDef { label: (136..139, "t͡s".into()), traits: vec![(142..150, "alveolar".into()), (151..160, "affricate".into())] },
(43..63, PhonemeDef { label: (43..44, "p".into()), traits: vec![(47..55, "bilabial".into()), (56..63, "plosive".into())] }),
(75..95, PhonemeDef { label: (75..76, "t".into()), traits: vec![(79..87, "alveolar".into()), (88..95, "plosive".into())] }),
(107..124, PhonemeDef { label: (107..108, "k".into()), traits: vec![(111..116, "velar".into()), (117..124, "plosive".into())] }),
(136..160, PhonemeDef { label: (136..139, "t͡s".into()), traits: vec![(142..150, "alveolar".into()), (151..160, "affricate".into())] }),
]
})
)
Expand Down
17 changes: 9 additions & 8 deletions src/parser/trait_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub fn parser() -> impl Parser<char, Stmt, Error = Simple<char>> {
.map(|((default, labels), notation)| TraitMember { default, labels, notation });

let body = member
.map_with_span(|m, span| (span, m))
.separated_by(just(",").padded())
.allow_trailing()
.at_least(1)
Expand Down Expand Up @@ -71,9 +72,9 @@ mod test {
Stmt::Trait {
label: (13..18, "Place".into()),
members: vec![
TraitMember { labels: vec![(29..35, "labial".into())], notation: None, default: false },
TraitMember { labels: vec![(45..53, "alveolar".into())], notation: None, default: false },
TraitMember { labels: vec![(63..68, "velar".into())], notation: None, default: false },
(29..35, TraitMember { labels: vec![(29..35, "labial".into())], notation: None, default: false }),
(45..53, TraitMember { labels: vec![(45..53, "alveolar".into())], notation: None, default: false }),
(63..68, TraitMember { labels: vec![(63..68, "velar".into())], notation: None, default: false }),
],
},
)
Expand All @@ -94,8 +95,8 @@ mod test {
Stmt::Trait {
label: (13..19, "Stress".into()),
members: vec![
TraitMember { labels: vec![(30..37, "primary".into())], notation: Some((40..42, "ˈ_".into())), default: false },
TraitMember { labels: vec![(52..61, "secondary".into())], notation: Some((64..66, "ˌ_".into())), default: false },
(30..42, TraitMember { labels: vec![(30..37, "primary".into())], notation: Some((40..42, "ˈ_".into())), default: false }),
(52..66, TraitMember { labels: vec![(52..61, "secondary".into())], notation: Some((64..66, "ˌ_".into())), default: false }),
],
},
)
Expand All @@ -117,9 +118,9 @@ mod test {
Stmt::Trait {
label: (13..19, "Length".into()),
members: vec![
TraitMember { labels: vec![(38..43, "short".into())], notation: None, default: true },
TraitMember { labels: vec![(53..57, "long".into())], notation: Some((60..62, "_:".into())), default: false },
TraitMember { labels: vec![(72..80, "overlong".into())], notation: Some((83..86, "_::".into())), default: false },
(30..43, TraitMember { labels: vec![(38..43, "short".into())], notation: None, default: true }),
(53..62, TraitMember { labels: vec![(53..57, "long".into())], notation: Some((60..62, "_:".into())), default: false }),
(72..86, TraitMember { labels: vec![(72..80, "overlong".into())], notation: Some((83..86, "_::".into())), default: false }),
],
},
)
Expand Down

0 comments on commit ce7a87c

Please sign in to comment.