Skip to content

Bidi Data Adapter - #1784

Merged
younies merged 21 commits into
unicode-org:mainfrom
younies:bidi_data_helper
Apr 27, 2022
Merged

younies merged 21 commits into
unicode-org:mainfrom
younies:bidi_data_helper

Conversation

@younies

@younies younies commented Apr 7, 2022 •

Copy link
Copy Markdown
Member

Closes: #1784

@younies
younies requested a review from a team as a code owner April 7, 2022 23:13
@younies younies changed the title Bidi Bidi Data Adopter Apr 7, 2022
@younies
younies marked this pull request as draft April 7, 2022 23:14
Comment thread components/properties/src/bc.rs Outdated
use icu_codepointtrie::CodePointTrie;

pub struct BidiClassAdaptor {
code_point_trie: CodePointTrie;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
code_point_trie: CodePointTrie;
code_point_trie: CodePointTrie,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread components/properties/src/bc.rs Outdated
use icu::properties::{maps, BidiClass};
use icu_codepointtrie::CodePointTrie;

pub struct BidiClassAdaptor {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Adapter

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread components/properties/src/bc.rs Outdated
maps::get_bidi_class(&provider)
.expect("The data should be valid");
let data_struct = payload.get();
BidiClassAdaptor{ data_struct.code_point_trie }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BidiClassAdaptor{ data_struct.code_point_trie }
BidiClassAdaptor{ code_point_trie: data_struct.code_point_trie }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I added a reference to the provider. However, I would like to have a way to save a reference to the code_point_trie instead. Shall I pass a code_point_trie?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added it.

Comment thread components/properties/Cargo.toml Outdated
icu_uniset = { version = "0.4.1", path = "../../utils/uniset"}
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }
zerovec = { version = "0.6", path = "../../utils/zerovec", features = ["derive"] }
unicode-bidi = "0.3.7"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: This should be an optional dependency. Enabling this dependency should enable the code that uses it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Comment thread components/properties/src/bc.rs Outdated
@@ -0,0 +1,71 @@
// This file is part of ICU4X. For terms of use, please see the file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please, name this file src/bidi.rs - bc becomes very cryptic for readers.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread components/properties/src/bc.rs Outdated
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::BidiDataSource;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: where is BidiDataSource defined? Why do you need a trait?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it comes from the unicode-bidi crate. The import needs to be fixed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it comes from unicode-bidi and I have fixed the import.

@zbraniecki , we need to implement to plugin the data from ICU4X to unicode-bidi.

@younies
younies marked this pull request as ready for review April 21, 2022 03:46
Comment thread components/properties/src/bidi.rs Outdated
BidiClass::LeftToRightIsolate => DataSourceBidiClass::LRI,
BidiClass::RightToLeftIsolate => DataSourceBidiClass::RLI,
BidiClass::PopDirectionalIsolate => DataSourceBidiClass::PDI,
_ => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what shall we do here? unfortunately, BidiClass is not an enum?

@sffc , @Manishearth

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should return the neutral/undefined/default value.

Running this code is rare, but it can happen if old code runs with new data.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I have returned Other_Neutral

Comment thread components/properties/src/bidi.rs Resolved
Comment thread components/properties/src/lib.rs Outdated
GeneralCategoryGroup, GraphemeClusterBreak, LineBreak, Script, SentenceBreak, WordBreak,
};

pub use bidi::BidiClassAdapter;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Don't hoist this to the top. Leave it exported under the bidi module.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not get this, could you illustrate more?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should clients write

use icu_properties::BidiClassAdapter;

or

use icu_properties::bidi::BidiClassAdapter;

I think we should lean toward putting this into a child namespace rather than the top level, but I can be convinced otherwise.

CC @Manishearth @echeran

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think child module makes sense

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread components/properties/src/bidi.rs Resolved
@younies
younies requested a review from sffc April 21, 2022 13:44
@jira-pull-request-webhook

Copy link
Copy Markdown

Notice: the branch changed across the force-push!

  • Cargo.lock is different
  • components/properties/Cargo.toml is different
  • components/properties/src/lib.rs is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

@sffc sffc changed the title Bidi Data Adopter Bidi Data Adapter Apr 21, 2022
Comment thread components/properties/src/lib.rs Resolved
Comment thread components/properties/Cargo.toml Outdated
default = []
serde = ["dep:serde", "zerovec/serde", "icu_uniset/serde", "icu_codepointtrie/serde"]
datagen = ["serde", "zerovec/serde_serialize", "icu_uniset/serde_serialize", "icu_codepointtrie/serde_serialize"]
unicode-bidi = [ "dep:unicode-bidi" ] No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: name the feature just "bidi"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@younies
younies requested a review from sffc April 25, 2022 13:15
Comment thread components/properties/Cargo.toml Outdated
icu_uniset = { version = "0.4.1", path = "../../utils/uniset"}
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }
zerovec = { version = "0.6", path = "../../utils/zerovec", features = ["derive"] }
unicode-bidi = { git = "https://github.com/servo/unicode-bidi", optional = true , deafault-features = false }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've made servo/unicode-bidi#78 to get this published, since we have a working PR now and are close to landing it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I am waiting to merge it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@younies
younies requested a review from Manishearth April 26, 2022 15:44
@younies younies closed this Apr 26, 2022
@younies younies reopened this Apr 26, 2022
Comment thread components/properties/src/bidi.rs Resolved
Comment thread components/properties/src/bidi.rs Resolved
@younies
younies requested a review from sffc April 26, 2022 18:22
Manishearth
Manishearth previously approved these changes Apr 27, 2022
Comment thread components/properties/src/bidi.rs Resolved
Comment thread components/properties/Cargo.toml Outdated
[dev-dependencies]
icu = { path = "../icu", default-features = false }
icu_testdata = { version = "0.5", path = "../../provider/testdata" }
icu_provider_fs = {version = "0.5.0", path = "../../provider/fs" }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I do not think you are using this dependency, so you should remove it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@younies
younies requested a review from sffc April 27, 2022 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants