Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Rethink parsing #785

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
75d6992
rethink parsing
Aiving Jul 13, 2024
852d3fd
change parsing api
Aiving Jul 15, 2024
b83476d
Merge branch 'main' into feat/rethink-parsing
Aiving Jul 15, 2024
3abffe9
Merge remote-tracking branch 'refs/remotes/origin/feat/rethink-parsin…
Aiving Jul 15, 2024
bf5cd55
feat: add `try_as_u8` function for `Token`
Aiving Jul 15, 2024
c953a5b
reduced number of modifications for PR files diff
Aiving Jul 15, 2024
f3a86be
Merge branch 'main' into feat/rethink-parsing
Aiving Jul 16, 2024
17bee71
fix rgba color parsing
Aiving Jul 16, 2024
33f151d
Merge branch 'feat/rethink-parsing' of https://github.com/Aiving/frey…
Aiving Jul 16, 2024
ad66c4a
Merge branch 'main' into feat/rethink-parsing
Aiving Jul 16, 2024
fd37282
Update crates/state/src/values/font.rs
Aiving Jul 16, 2024
08818aa
fix unicode character parsing
Aiving Jul 17, 2024
0ee85ba
change text-overflow parsing
Aiving Jul 17, 2024
168d95f
Merge branch 'main' into feat/rethink-parsing
Aiving Jul 17, 2024
017668c
Merge branch 'main' into feat/rethink-parsing
Aiving Aug 4, 2024
fc751ee
fixes
Aiving Aug 4, 2024
3dafc96
more fixes
Aiving Aug 4, 2024
424393d
Merge branch 'main' into feat/rethink-parsing
Aiving Aug 4, 2024
83a0276
Merge branch 'main' into feat/rethink-parsing
marc2332 Aug 18, 2024
1399586
Merge branch 'main' into feat/rethink-parsing
Aiving Sep 29, 2024
b50b78d
yoo
Aiving Sep 29, 2024
b88b19b
fix corner_radius.rs
Aiving Sep 29, 2024
3babf8c
Update style.rs
Aiving Sep 29, 2024
c3a630c
Update border.rs
Aiving Sep 29, 2024
32ec692
Update color.rs
Aiving Sep 29, 2024
a1dd2cb
add parse error messages
Aiving Sep 29, 2024
bee0ee5
fix rgb(a) parsing
Aiving Sep 29, 2024
873306f
fix text shadow parsing
Aiving Sep 29, 2024
6fed2d5
maybe fixed text shadow parsing
Aiving Sep 29, 2024
31aec74
fix hsl color parsing
Aiving Sep 29, 2024
49cf1ca
fix corner radius parsing
Aiving Sep 29, 2024
d6f3396
forgor to fmt
Aiving Sep 29, 2024
315ad4d
fix gradients angle parsing
Aiving Sep 29, 2024
9836be6
Merge branch 'main' into feat/rethink-parsing
Aiving Sep 29, 2024
c32dd2c
Merge branch 'main' into feat/rethink-parsing
Aiving Oct 16, 2024
e7caef3
implement new parse for text height
Aiving Oct 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions crates/state/src/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::sync::{
Arc,
Mutex,
use std::{
num::ParseIntError,
sync::{
Arc,
Mutex,
},
};

use freya_common::{
Expand Down Expand Up @@ -72,7 +75,11 @@ impl ParseAttribute for CursorState {
AttributeName::CursorIndex => {
if let Some(value) = attr.value.as_text() {
if value != "none" {
self.position = Some(value.parse().map_err(|_| ParseError)?);
self.position = Some(
value
.parse()
.map_err(|err: ParseIntError| ParseError(err.to_string()))?,
);
}
}
}
Expand All @@ -88,7 +95,11 @@ impl ParseAttribute for CursorState {
}
AttributeName::CursorId => {
if let Some(value) = attr.value.as_text() {
self.cursor_id = Some(value.parse().map_err(|_| ParseError)?);
self.cursor_id = Some(
value
.parse()
.map_err(|err: ParseIntError| ParseError(err.to_string()))?,
);
}
}
AttributeName::Highlights => {
Expand Down
85 changes: 37 additions & 48 deletions crates/state/src/font_style.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use std::sync::{
Arc,
Mutex,
use std::{
num::{
ParseFloatError,
ParseIntError,
},
sync::{
Arc,
Mutex,
},
};

use freya_common::CompositorDirtyNodes;
Expand All @@ -23,11 +29,13 @@ use torin::torin::Torin;

use crate::{
CustomAttributeValues,
ExtSplit,
Parse,
ParseAttribute,
ParseError,
TextHeight,
TextHeightBehavior,
TextOverflow,
Token,
};

#[derive(Debug, Clone, PartialEq, Component)]
Expand Down Expand Up @@ -123,7 +131,7 @@ impl ParseAttribute for FontStyleState {
fn parse_attribute(
&mut self,
attr: freya_native_core::prelude::OwnedAttributeView<CustomAttributeValues>,
) -> Result<(), crate::ParseError> {
) -> Result<(), ParseError> {
match attr.attribute {
AttributeName::Color => {
if let Some(value) = attr.value.as_text() {
Expand All @@ -136,15 +144,13 @@ impl ParseAttribute for FontStyleState {
}
AttributeName::TextShadow => {
if let Some(value) = attr.value.as_text() {
self.text_shadows = value
.split_excluding_group(',', '(', ')')
.map(|chunk| TextShadow::parse(chunk).unwrap_or_default())
.collect();
self.text_shadows = TextShadow::parse_with_separator(value, &Token::Comma)?;
}
}
AttributeName::FontFamily => {
if let Some(value) = attr.value.as_text() {
let families = value.split(',');

self.font_family = families
.into_iter()
.map(|f| f.trim().to_string())
Expand All @@ -167,84 +173,67 @@ impl ParseAttribute for FontStyleState {
}
AttributeName::TextAlign => {
if let Some(value) = attr.value.as_text() {
if let Ok(text_align) = TextAlign::parse(value) {
self.text_align = text_align;
}
self.text_align = TextAlign::parse(value)?;
}
}
AttributeName::MaxLines => {
if let Some(value) = attr.value.as_text() {
if let Ok(max_lines) = value.parse() {
self.max_lines = Some(max_lines);
}
self.max_lines = Some(
value
.parse()
.map_err(|err: ParseIntError| ParseError(err.to_string()))?,
);
}
}
AttributeName::TextOverflow => {
let value = attr.value.as_text();
if let Some(value) = value {
if let Ok(text_overflow) = TextOverflow::parse(value) {
self.text_overflow = text_overflow;
}
if let Some(value) = attr.value.as_text() {
self.text_overflow = TextOverflow::parse(value)?;
}
}
AttributeName::FontStyle => {
if let Some(value) = attr.value.as_text() {
if let Ok(font_slant) = Slant::parse(value) {
self.font_slant = font_slant;
}
self.font_slant = Slant::parse(value)?;
}
}
AttributeName::FontWeight => {
if let Some(value) = attr.value.as_text() {
if let Ok(font_weight) = Weight::parse(value) {
self.font_weight = font_weight;
}
self.font_weight = Weight::parse(value)?;
}
}
AttributeName::FontWidth => {
if let Some(value) = attr.value.as_text() {
if let Ok(font_width) = Width::parse(value) {
self.font_width = font_width;
}
self.font_width = Width::parse(value)?;
}
}
AttributeName::Decoration => {
if let Some(value) = attr.value.as_text() {
if let Ok(decoration) = TextDecoration::parse(value) {
self.decoration.ty = decoration;
}
self.decoration.ty = TextDecoration::parse(value)?;
}
}
AttributeName::DecorationStyle => {
if let Some(value) = attr.value.as_text() {
if let Ok(style) = TextDecorationStyle::parse(value) {
self.decoration.style = style;
}
self.decoration.style = TextDecorationStyle::parse(value)?;
}
}
AttributeName::DecorationColor => {
if let Some(value) = attr.value.as_text() {
if let Ok(new_decoration_color) = Color::parse(value) {
self.decoration.color = new_decoration_color;
}
self.decoration.color = Color::parse(value)?;
} else {
self.decoration.color = self.color;
}
}
AttributeName::WordSpacing => {
let value = attr.value.as_text();
if let Some(value) = value {
if let Ok(word_spacing) = value.parse() {
self.word_spacing = word_spacing;
}
if let Some(value) = attr.value.as_text() {
self.word_spacing = value
.parse()
.map_err(|err: ParseFloatError| ParseError(err.to_string()))?;
}
}
AttributeName::LetterSpacing => {
let value = attr.value.as_text();
if let Some(value) = value {
if let Ok(letter_spacing) = value.parse() {
self.letter_spacing = letter_spacing;
}
if let Some(value) = attr.value.as_text() {
self.letter_spacing = value
.parse()
.map_err(|err: ParseFloatError| ParseError(err.to_string()))?;
}
}
AttributeName::TextHeight => {
Expand Down
4 changes: 3 additions & 1 deletion crates/state/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ impl ParseAttribute for LayerState {
match attr.attribute {
AttributeName::Layer => {
if let Some(value) = attr.value.as_text() {
let layer = value.parse::<i16>().map_err(|_| ParseError)?;
let layer = value
.parse::<i16>()
.map_err(|err| ParseError(err.to_string()))?;
self.layer -= layer;
self.layer_for_children += layer;
}
Expand Down
54 changes: 42 additions & 12 deletions crates/state/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,32 @@ impl ParseAttribute for LayoutState {
if let Some(value) = attr.value.as_text() {
self.direction = match value {
"horizontal" => DirectionMode::Horizontal,
_ => DirectionMode::Vertical,
"vertical" => DirectionMode::Vertical,
value => {
return Err(ParseError::invalid_ident(
value,
&["horizontal", "vertical"],
))
}
}
}
}
AttributeName::OffsetY => {
if let Some(value) = attr.value.as_text() {
self.offset_y = Length::new(value.parse::<f32>().map_err(|_| ParseError)?);
self.offset_y = Length::new(
value
.parse::<f32>()
.map_err(|err| ParseError(err.to_string()))?,
);
}
}
AttributeName::OffsetX => {
if let Some(value) = attr.value.as_text() {
self.offset_x = Length::new(value.parse::<f32>().map_err(|_| ParseError)?);
self.offset_x = Length::new(
value
.parse::<f32>()
.map_err(|err| ParseError(err.to_string()))?,
);
}
}
AttributeName::MainAlign => {
Expand All @@ -135,26 +149,38 @@ impl ParseAttribute for LayoutState {
}
AttributeName::PositionTop => {
if let Some(value) = attr.value.as_text() {
self.position
.set_top(value.parse::<f32>().map_err(|_| ParseError)?);
self.position.set_top(
value
.parse::<f32>()
.map_err(|err| ParseError(err.to_string()))?,
);
}
}
AttributeName::PositionRight => {
if let Some(value) = attr.value.as_text() {
self.position
.set_right(value.parse::<f32>().map_err(|_| ParseError)?);
self.position.set_right(
value
.parse::<f32>()
.map_err(|err| ParseError(err.to_string()))?,
);
}
}
AttributeName::PositionBottom => {
if let Some(value) = attr.value.as_text() {
self.position
.set_bottom(value.parse::<f32>().map_err(|_| ParseError)?);
self.position.set_bottom(
value
.parse::<f32>()
.map_err(|err| ParseError(err.to_string()))?,
);
}
}
AttributeName::PositionLeft => {
if let Some(value) = attr.value.as_text() {
self.position
.set_left(value.parse::<f32>().map_err(|_| ParseError)?);
self.position.set_left(
value
.parse::<f32>()
.map_err(|err| ParseError(err.to_string()))?,
);
}
}
AttributeName::Content => {
Expand All @@ -171,7 +197,11 @@ impl ParseAttribute for LayoutState {
}
AttributeName::Spacing => {
if let Some(value) = attr.value.as_text() {
self.spacing = Length::new(value.parse::<f32>().map_err(|_| ParseError)?);
self.spacing = Length::new(
value
.parse::<f32>()
.map_err(|err| ParseError(err.to_string()))?,
);
}
}
_ => {}
Expand Down
Loading
Loading