-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
318 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use hdx_ast::css::values::{CounterStyle, PredefinedCounterStyle, Symbols}; | ||
|
||
use crate::{atom, diagnostics, Atomizable, Kind, Parse, Parser, Result, Spanned}; | ||
|
||
impl<'a> Parse<'a> for CounterStyle<'a> { | ||
fn parse(parser: &mut Parser<'a>) -> Result<Spanned<Self>> { | ||
let span = parser.cur().span; | ||
match parser.cur().kind { | ||
Kind::Ident => { | ||
let ident = parser.expect_ident()?; | ||
if let Some(node) = PredefinedCounterStyle::from_atom(ident.clone()) { | ||
Ok(Self::Predefined(node).spanned(span)) | ||
} else { | ||
Ok(Self::Named(ident).spanned(span)) | ||
} | ||
} | ||
Kind::Function => { | ||
let ident = parser.expect_ident()?; | ||
if ident == atom!("symbols") { | ||
let node = Symbols::parse(parser)?; | ||
Ok(Self::Symbols(node).spanned(span.up_to(&parser.cur().span))) | ||
} else { | ||
Err(diagnostics::ExpectedFunction(atom!("symbols"), ident, parser.cur().span))? | ||
} | ||
} | ||
k => Err(diagnostics::Unexpected(k, parser.cur().span))?, | ||
} | ||
} | ||
} | ||
|
||
impl<'a> Parse<'a> for Symbols<'a> { | ||
fn parse(parser: &mut Parser<'a>) -> Result<Spanned<Self>> { | ||
Err(diagnostics::Unimplemented(parser.cur().span))? | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
use hdx_ast::css::values::{ | ||
CounterStyle, Expr, Image, ListStyleImageValue, ListStylePositionValue, ListStyleShorthand, | ||
ListStyleTypeValue, Shorthand, | ||
}; | ||
|
||
use crate::{atom, diagnostics, Kind, Parse, Parser, Result, Spanned}; | ||
|
||
impl<'a> Parse<'a> for ListStyleShorthand<'a> { | ||
fn parse(parser: &mut Parser<'a>) -> Result<Spanned<Self>> { | ||
let span = parser.cur().span; | ||
let mut position = Shorthand::Implicit; | ||
let mut image = Shorthand::Implicit; | ||
let mut marker = Shorthand::Implicit; | ||
loop { | ||
match parser.cur().kind { | ||
Kind::Semicolon | Kind::Comma | Kind::Eof => { | ||
break; | ||
} | ||
Kind::Ident => { | ||
let ident = parser.cur_atom().unwrap(); | ||
if position.is_implicit() && matches!(ident, atom!("inside") | atom!("outside")) | ||
{ | ||
let node = Expr::<ListStylePositionValue>::parse(parser)?; | ||
position = Shorthand::Explicit(parser.boxup(node)); | ||
} else if image.is_implicit() && matches!(ident, atom!("none")) { | ||
let node = Expr::<ListStyleImageValue>::parse(parser)?; | ||
image = Shorthand::Explicit(parser.boxup(node)); | ||
} else if marker.is_implicit() { | ||
let node = Expr::<ListStyleTypeValue>::parse(parser)?; | ||
marker = Shorthand::Explicit(parser.boxup(node)); | ||
} else { | ||
Err(diagnostics::UnexpectedIdent(ident.clone(), parser.cur().span))? | ||
} | ||
} | ||
k => { | ||
let checkpoint = parser.checkpoint(); | ||
if image.is_implicit() { | ||
let node = Expr::<ListStyleImageValue>::parse(parser); | ||
match node { | ||
Ok(node) => { | ||
image = Shorthand::Explicit(parser.boxup(node)); | ||
continue; | ||
} | ||
Err(_) => parser.rewind(checkpoint), | ||
} | ||
} | ||
let checkpoint = parser.checkpoint(); | ||
if marker.is_implicit() { | ||
let node = Expr::<ListStyleTypeValue>::parse(parser); | ||
match node { | ||
Ok(node) => { | ||
marker = Shorthand::Explicit(parser.boxup(node)); | ||
continue; | ||
} | ||
Err(_) => parser.rewind(checkpoint), | ||
} | ||
} | ||
Err(diagnostics::Unexpected(k, parser.cur().span))? | ||
} | ||
} | ||
if position.is_explicit() && image.is_explicit() && marker.is_explicit() { | ||
break; | ||
} | ||
} | ||
Ok(Self { position, image, marker }.spanned(span.up_to(&parser.cur().span))) | ||
} | ||
} | ||
|
||
impl<'a> Parse<'a> for ListStyleTypeValue<'a> { | ||
fn parse(parser: &mut Parser<'a>) -> Result<Spanned<Self>> { | ||
let span = parser.cur().span; | ||
match parser.cur().kind { | ||
Kind::Ident => { | ||
let ident = parser.cur_atom().unwrap(); | ||
if ident == atom!("none") { | ||
parser.advance(); | ||
Ok(Self::None.spanned(span)) | ||
} else { | ||
let node = CounterStyle::parse(parser)?; | ||
Ok(Self::CounterStyle(node).spanned(span.up_to(&parser.cur().span))) | ||
} | ||
} | ||
Kind::String => Ok(Self::String(parser.expect_string()?).spanned(span)), | ||
_ => { | ||
let node = CounterStyle::parse(parser)?; | ||
Ok(Self::CounterStyle(node).spanned(span.up_to(&parser.cur().span))) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<'a> Parse<'a> for ListStyleImageValue<'a> { | ||
fn parse(parser: &mut Parser<'a>) -> Result<Spanned<Self>> { | ||
let span = parser.cur().span; | ||
match parser.cur().kind { | ||
Kind::Ident => { | ||
let ident = parser.cur_atom().unwrap(); | ||
if ident == atom!("none") { | ||
parser.advance(); | ||
Ok(Self::None.spanned(span)) | ||
} else { | ||
let node = Image::parse(parser)?; | ||
Ok(Self::Image(node).spanned(span.up_to(&parser.cur().span))) | ||
} | ||
} | ||
_ => { | ||
let node = Image::parse(parser)?; | ||
Ok(Self::Image(node).spanned(span.up_to(&parser.cur().span))) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.