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

Add support for * prefix in declaration names #388

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion src/rules_and_declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ where
type Item = Result<I, (ParseError<'i, E>, &'i str)>;

fn next(&mut self) -> Option<Self::Item> {
let mut parsing_lagacy_star_hack = false;
loop {
self.input.skip_whitespace();
let start = self.input.state();
Expand All @@ -266,7 +267,7 @@ where
// keep parsing as a qualified rule if the token is not an ident, so we implement
// that in a slightly more straight-forward way
Token::Ident(ref name) if self.parser.parse_declarations() => {
let name = name.clone();
let mut name = name.clone();
let parse_qualified = self.parser.parse_qualified();
let result = {
let error_behavior = if parse_qualified {
Expand All @@ -281,6 +282,10 @@ where
error_behavior,
|input| {
input.expect_colon()?;
if parsing_lagacy_star_hack {
name = format!("*{name}").into();
parsing_lagacy_star_hack = false;
}
parser.parse_value(name, input)
},
)
Expand All @@ -302,6 +307,10 @@ where
return Some(result.map_err(|e| (e, self.input.slice_from(start.position()))));
}
token => {
if *token == Token::Delim('*') {
parsing_lagacy_star_hack = true;
continue;
}
let result = if self.parser.parse_qualified() {
self.input.reset(&start);
let delimiters = if self.parser.parse_declarations() {
Expand Down
4 changes: 4 additions & 0 deletions src/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ where
hex_escape(digit, dest)?;
value = &value[1..];
}
if b'*' == value.as_bytes()[0] {
Copy link
Member

Choose a reason for hiding this comment

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

This is not correct, this is not an identifier.

dest.write_str("*")?;
value = &value[1..];
}
serialize_name(value, dest)
}
}
Expand Down