Accept _ and - in identifiers
This commit is contained in:
parent
a14070b054
commit
e3aae97767
@ -112,7 +112,7 @@ impl<W: Write> PrettyPrinter<W> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test_scss {
|
||||||
use super::StyleSheet;
|
use super::StyleSheet;
|
||||||
macro_rules! test {
|
macro_rules! test {
|
||||||
($func:ident, $input:literal) => {
|
($func:ident, $input:literal) => {
|
||||||
@ -145,6 +145,7 @@ mod test {
|
|||||||
|
|
||||||
test!(empty, "");
|
test!(empty, "");
|
||||||
test!(basic_nesting, "a {\n b {\n }\n}\n");
|
test!(basic_nesting, "a {\n b {\n }\n}\n");
|
||||||
|
test!(mul_nesting, "a, b {\n a, b {\n }\n}\n");
|
||||||
test!(ident_with_num, "el1 {\n}\n");
|
test!(ident_with_num, "el1 {\n}\n");
|
||||||
|
|
||||||
test!(selector_element, "a {\n}\n");
|
test!(selector_element, "a {\n}\n");
|
||||||
|
10
src/lexer.rs
10
src/lexer.rs
@ -102,7 +102,7 @@ impl<'a> Lexer<'a> {
|
|||||||
fn lex_at_rule(&mut self) -> TokenKind {
|
fn lex_at_rule(&mut self) -> TokenKind {
|
||||||
let mut string = String::with_capacity(99);
|
let mut string = String::with_capacity(99);
|
||||||
while let Some(c) = self.buf.peek() {
|
while let Some(c) = self.buf.peek() {
|
||||||
if !c.is_alphabetic() && c != &'-' {
|
if !c.is_alphabetic() && c != &'-' && c != &'_' {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let tok = self
|
let tok = self
|
||||||
@ -163,7 +163,7 @@ impl<'a> Lexer<'a> {
|
|||||||
fn lex_attr(&mut self) -> TokenKind {
|
fn lex_attr(&mut self) -> TokenKind {
|
||||||
let mut attr = String::with_capacity(99);
|
let mut attr = String::with_capacity(99);
|
||||||
while let Some(c) = self.buf.peek() {
|
while let Some(c) = self.buf.peek() {
|
||||||
if !c.is_alphabetic() && c != &'-' {
|
if !c.is_alphabetic() && c != &'-' && c != &'_' {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let tok = self
|
let tok = self
|
||||||
@ -229,7 +229,7 @@ impl<'a> Lexer<'a> {
|
|||||||
let mut case_sensitive = true;
|
let mut case_sensitive = true;
|
||||||
|
|
||||||
while let Some(c) = self.buf.peek() {
|
while let Some(c) = self.buf.peek() {
|
||||||
if !c.is_alphabetic() && c != &'-' {
|
if !c.is_alphabetic() && c != &'-' && c != &'_' {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ impl<'a> Lexer<'a> {
|
|||||||
self.pos.next_char();
|
self.pos.next_char();
|
||||||
let mut name = String::with_capacity(99);
|
let mut name = String::with_capacity(99);
|
||||||
while let Some(c) = self.buf.peek() {
|
while let Some(c) = self.buf.peek() {
|
||||||
if !c.is_alphabetic() && c != &'-' {
|
if !c.is_alphabetic() && c != &'-' && c != &'_' {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let tok = self
|
let tok = self
|
||||||
@ -305,7 +305,7 @@ impl<'a> Lexer<'a> {
|
|||||||
let mut string = String::with_capacity(99);
|
let mut string = String::with_capacity(99);
|
||||||
while let Some(c) = self.buf.peek() {
|
while let Some(c) = self.buf.peek() {
|
||||||
// we know that the first char is alphabetic from peeking
|
// we know that the first char is alphabetic from peeking
|
||||||
if !c.is_alphanumeric() && c != &'-' {
|
if !c.is_alphanumeric() && c != &'-' && c != &'_' {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let tok = self
|
let tok = self
|
||||||
|
Loading…
x
Reference in New Issue
Block a user