Skip to content

Commit

Permalink
small metadata rework
Browse files Browse the repository at this point in the history
  • Loading branch information
Zheoni committed Jan 13, 2024
1 parent be5684f commit 40c9dd0
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 64 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# Change Log

## Unreleased - ReleaseDate

### Features
- Special metadata keys are now an extension.
- Improve `Metadata` memory layout and interface.
- Emoji can now also be a shortcode like `:taco:`.

### Breaking
- (De)Serializing `ScaleOutcome` was not camel case, so (de)serialization has changed
from previous versions.
- (De)Serializing format change of `Metadata` special values. Now all special
key values whose parsed values have some different representation are under
the `special` field.
- Removed all fields except `map` from `Metadata`, now they are methods.

## 0.11.1 - 2023-12-28
### Fixed
Expand Down
1 change: 1 addition & 0 deletions playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ <h1>cooklang-rs playground</h1>
"RANGE_VALUES",
"TIMER_REQUIRES_TIME",
"INTERMEDIATE_PREPARATIONS",
"SPECIAL_METADATA",
].forEach((e, i) => {
let bits = 1 << i;
if (i == 11) {
Expand Down
14 changes: 8 additions & 6 deletions src/analysis/event_consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,15 @@ impl<'i, 'c> RecipeCollector<'i, 'c> {
.insert(key_t.to_string(), value_t.to_string());

// check if it's a special key
if !self.extensions.contains(Extensions::SPECIAL_METADATA) {
return;
}
if let Ok(sp_key) = SpecialKey::from_str(&key_t) {
// try to insert it
let res = self.content.metadata.insert_special_key(
sp_key,
value_t.to_string(),
self.converter,
);
let res =
self.content
.metadata
.insert_special(sp_key, value_t.to_string(), self.converter);
if let Err(err) = res {
self.ctx.warn(
warning!(
Expand Down Expand Up @@ -912,7 +914,7 @@ impl<'i, 'c> RecipeCollector<'i, 'c> {
}
parser::QuantityValue::Many(v) => {
const CONFLICT: &str = "Many values conflict";
if let Some(s) = &self.content.metadata.servings {
if let Some(s) = &self.content.metadata.servings() {
let servings_meta_span = self
.locations
.metadata
Expand Down
10 changes: 4 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,8 @@ bitflags! {
const TIMER_REQUIRES_TIME = 1 << 10;
/// This extensions also enables [`Self::COMPONENT_MODIFIERS`].
const INTERMEDIATE_PREPARATIONS = 1 << 11 | Self::COMPONENT_MODIFIERS.bits();

/// Enables [`Self::COMPONENT_MODIFIERS`], [`Self::COMPONENT_NOTE`] and [`Self::COMPONENT_ALIAS`]
const COMPONENT_ALL = Self::COMPONENT_MODIFIERS.bits()
| Self::COMPONENT_ALIAS.bits()
| Self::COMPONENT_NOTE.bits();
/// Enables special metadata key parsing
const SPECIAL_METADATA = 1 << 12;

/// Enables a subset of extensions to maximize compatibility with other
/// cooklang parsers.
Expand All @@ -159,7 +156,8 @@ bitflags! {
| Self::TEMPERATURE.bits()
| Self::TEXT_STEPS.bits()
| Self::RANGE_VALUES.bits()
| Self::INTERMEDIATE_PREPARATIONS.bits();
| Self::INTERMEDIATE_PREPARATIONS.bits()
| Self::SPECIAL_METADATA.bits();
}
}

Expand Down
Loading

0 comments on commit 40c9dd0

Please sign in to comment.