From 6f35ea5f282b27396033f9532d86731f23ee0ea2 Mon Sep 17 00:00:00 2001 From: Niels Saurer Date: Mon, 7 Aug 2023 22:25:56 +0200 Subject: [PATCH] CI fixes --- experimental/transliterator_parser/README.md | 4 +++- experimental/transliterator_parser/src/compile.rs | 14 +++++--------- experimental/transliterator_parser/src/lib.rs | 11 ++++++++--- experimental/transliterator_parser/src/parse.rs | 12 +++++++++++- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/experimental/transliterator_parser/README.md b/experimental/transliterator_parser/README.md index b8489260e56..cef9a94d048 100644 --- a/experimental/transliterator_parser/README.md +++ b/experimental/transliterator_parser/README.md @@ -4,7 +4,9 @@ This crate provides parsing functionality for [UTS #35 - Transliterators](https://unicode.org/reports/tr35/tr35-general.html#Transforms). -See [`parse`](crate::parse) for more information. +See [`parse`](crate::parse()) for more information. + +[`ICU4X`]: ../icu/index.html ## More Information diff --git a/experimental/transliterator_parser/src/compile.rs b/experimental/transliterator_parser/src/compile.rs index f2a14851d5a..c03a51af420 100644 --- a/experimental/transliterator_parser/src/compile.rs +++ b/experimental/transliterator_parser/src/compile.rs @@ -112,8 +112,7 @@ as described in the zero-copy format, and the maps here are just arrays) */ use crate::parse; -use crate::parse::{ElementKind as EK, ElementLocation as EL, HalfRule, QuantifierKind}; -use parse::ParseError; +use crate::parse::{ElementLocation as EL, HalfRule, QuantifierKind}; use parse::Result; use parse::PEK; use std::collections::{HashMap, HashSet}; @@ -402,8 +401,7 @@ impl<'a, 'p, F: Fn(&str) -> bool> TargetValidator<'a, 'p, F> { fn validate_section(&mut self, section: &[parse::Element], top_level: bool) -> Result<()> { section .iter() - .map(|element| self.validate_element(element, top_level)) - .collect() + .try_for_each(|element| self.validate_element(element, top_level)) } fn validate_element(&mut self, element: &parse::Element, top_level: bool) -> Result<()> { @@ -509,14 +507,13 @@ impl<'a, 'p, F: Fn(&str) -> bool> SourceValidator<'a, 'p, F> { // now neither start nor end anchors may appear anywhere in `order` - sections.iter().map(|s| self.validate_section(s)).collect() + sections.iter().try_for_each(|s| self.validate_section(s)) } fn validate_section(&mut self, section: &[parse::Element]) -> Result<()> { section .iter() - .map(|element| self.validate_element(element)) - .collect() + .try_for_each(|element| self.validate_element(element)) } fn validate_element(&mut self, element: &parse::Element) -> Result<()> { @@ -589,8 +586,7 @@ impl<'a, 'p, F: Fn(&str) -> bool> VariableDefinitionValidator<'a, 'p, F> { fn validate_section(&mut self, section: &[parse::Element]) -> Result<()> { section .iter() - .map(|element| self.validate_element(element)) - .collect() + .try_for_each(|element| self.validate_element(element)) } fn validate_element(&mut self, element: &parse::Element) -> Result<()> { diff --git a/experimental/transliterator_parser/src/lib.rs b/experimental/transliterator_parser/src/lib.rs index 915558de64a..993a95285d1 100644 --- a/experimental/transliterator_parser/src/lib.rs +++ b/experimental/transliterator_parser/src/lib.rs @@ -6,7 +6,9 @@ //! //! This crate provides parsing functionality for [UTS #35 - Transliterators](https://unicode.org/reports/tr35/tr35-general.html#Transforms). //! -//! See [`parse`](crate::parse) for more information. +//! See [`parse`](crate::parse()) for more information. +//! +//! [`ICU4X`]: ../icu/index.html // https://github.com/unicode-org/icu4x/blob/main/docs/process/boilerplate.md#library-annotations #![cfg_attr( @@ -30,6 +32,8 @@ use icu_transliteration::provider::RuleBasedTransliterator; mod compile; mod parse; +pub use parse::ElementKind; +pub use parse::ElementLocation; pub use parse::ParseError; pub use parse::ParseErrorKind; @@ -41,7 +45,7 @@ pub fn parse(source: &str) -> Result, parse::Pa parse_unstable(source, &icu_properties::provider::Baked) } -#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, parse)] +#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, parse())] pub fn parse_unstable

( source: &str, provider: &P, @@ -105,5 +109,6 @@ where + DataProvider, { let parsed = parse::parse_unstable(source, provider)?; - compile::compile(parsed) + // TODO(#3736): pass direction from metadata + compile::compile(parsed, parse::Direction::Both) } diff --git a/experimental/transliterator_parser/src/parse.rs b/experimental/transliterator_parser/src/parse.rs index 3012c3ce5b3..6a08a6e9eff 100644 --- a/experimental/transliterator_parser/src/parse.rs +++ b/experimental/transliterator_parser/src/parse.rs @@ -18,15 +18,25 @@ use icu_unicodeset_parser::{VariableMap, VariableValue}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[non_exhaustive] pub enum ElementKind { + /// A literal string: `abc 'abc'`. Literal, + /// A variable reference: `$var`. VariableReference, + /// A backreference to a segment: `$1`. BackReference, + /// A quantifier of any sort: `c*`, `c+`, `c?`. Quantifier, + /// A segment: `(abc)`. Segment, + /// A UnicodeSet: `[a-z]`. UnicodeSet, + /// A function call: `&[a-z] Remove(...)`. FunctionCall, + /// A cursor: `|`. Cursor, + /// A start anchor: `^`. AnchorStart, + /// An end anchor: `$`. AnchorEnd, } @@ -73,7 +83,7 @@ pub enum ParseErrorKind { // errors originating from compilation step /// A global filter (forward or backward) in an unexpected position. UnexpectedGlobalFilter, - /// An element of `[ElementKind]` appeared in the given [`ElementLocation`], but that is prohibited. + /// An element of [`ElementKind`] appeared in the given [`ElementLocation`], but that is prohibited. UnexpectedElement(ElementKind, ElementLocation), /// The start anchor `^` was not placed at the beginning of a source. AnchorStartNotAtStart,