Skip to content
Merged
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
12 changes: 12 additions & 0 deletions crates/biome_tailwind_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use biome_parser::lexer::{Lexer, LexerCheckpoint, LexerWithCheckpoint, ReLexer,
use biome_rowan::{SyntaxKind, TextLen};
use biome_tailwind_syntax::T;
use biome_tailwind_syntax::TailwindSyntaxKind::*;
use biome_tailwind_syntax::metadata::BASENAMES_WITH_DASHES;
use biome_tailwind_syntax::{TailwindSyntaxKind, TextSize};

pub(crate) struct TailwindLexer<'src> {
Expand Down Expand Up @@ -104,6 +105,17 @@ impl<'src> TailwindLexer<'src> {
fn consume_base(&mut self) -> TailwindSyntaxKind {
self.assert_current_char_boundary();

// Find the longest matching base name
let source_from_position = &self.source[self.position..];
let base_name = BASENAMES_WITH_DASHES
.iter()
.rfind(|&name| source_from_position.starts_with(name));

if let Some(base_name) = base_name {
self.advance(base_name.len());
return TW_BASE;
}

while let Some(byte) = self.current_byte() {
let char = self.current_char_unchecked();
if char.is_whitespace() || byte == b'-' || byte == b'!' || byte == b':' {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bg-radial-[at_50%_75%] from-sky-200 via-blue-400 to-indigo-900 to-90%
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
---
source: crates/biome_tailwind_parser/tests/spec_test.rs
expression: snapshot
---
## Input

```text
bg-radial-[at_50%_75%] from-sky-200 via-blue-400 to-indigo-900 to-90%

```


## AST

```
TwRoot {
bom_token: missing (optional),
candidates: TwCandidateList [
TwFullCandidate {
variants: TwVariantList [],
candidate: TwFunctionalCandidate {
base_token: TW_BASE@0..9 "bg-radial" [] [],
minus_token: DASH@9..10 "-" [] [],
value: TwArbitraryValue {
l_brack_token: L_BRACKET@10..11 "[" [] [],
value_token: TW_VALUE@11..21 "at_50%_75%" [] [],
r_brack_token: R_BRACKET@21..22 "]" [] [],
},
modifier: missing (optional),
},
excl_token: missing (optional),
},
WHITESPACE@22..23 " " [] [],
TwFullCandidate {
variants: TwVariantList [],
candidate: TwFunctionalCandidate {
base_token: TW_BASE@23..27 "from" [] [],
minus_token: DASH@27..28 "-" [] [],
value: TwNamedValue {
value_token: TW_VALUE@28..35 "sky-200" [] [],
},
modifier: missing (optional),
},
excl_token: missing (optional),
},
WHITESPACE@35..36 " " [] [],
TwFullCandidate {
variants: TwVariantList [],
candidate: TwFunctionalCandidate {
base_token: TW_BASE@36..39 "via" [] [],
minus_token: DASH@39..40 "-" [] [],
value: TwNamedValue {
value_token: TW_VALUE@40..48 "blue-400" [] [],
},
modifier: missing (optional),
},
excl_token: missing (optional),
},
WHITESPACE@48..49 " " [] [],
TwFullCandidate {
variants: TwVariantList [],
candidate: TwFunctionalCandidate {
base_token: TW_BASE@49..51 "to" [] [],
minus_token: DASH@51..52 "-" [] [],
value: TwNamedValue {
value_token: TW_VALUE@52..62 "indigo-900" [] [],
},
modifier: missing (optional),
},
excl_token: missing (optional),
},
WHITESPACE@62..63 " " [] [],
TwFullCandidate {
variants: TwVariantList [],
candidate: TwFunctionalCandidate {
base_token: TW_BASE@63..65 "to" [] [],
minus_token: DASH@65..66 "-" [] [],
value: TwNamedValue {
value_token: TW_VALUE@66..70 "90%" [] [Newline("\n")],
},
modifier: missing (optional),
},
excl_token: missing (optional),
},
],
eof_token: EOF@70..70 "" [] [],
}
```

## CST

```
0: TW_ROOT@0..70
0: (empty)
1: TW_CANDIDATE_LIST@0..70
0: TW_FULL_CANDIDATE@0..22
0: TW_VARIANT_LIST@0..0
1: TW_FUNCTIONAL_CANDIDATE@0..22
0: TW_BASE@0..9 "bg-radial" [] []
1: DASH@9..10 "-" [] []
2: TW_ARBITRARY_VALUE@10..22
0: L_BRACKET@10..11 "[" [] []
1: TW_VALUE@11..21 "at_50%_75%" [] []
2: R_BRACKET@21..22 "]" [] []
3: (empty)
2: (empty)
1: WHITESPACE@22..23 " " [] []
2: TW_FULL_CANDIDATE@23..35
0: TW_VARIANT_LIST@23..23
1: TW_FUNCTIONAL_CANDIDATE@23..35
0: TW_BASE@23..27 "from" [] []
1: DASH@27..28 "-" [] []
2: TW_NAMED_VALUE@28..35
0: TW_VALUE@28..35 "sky-200" [] []
3: (empty)
2: (empty)
3: WHITESPACE@35..36 " " [] []
4: TW_FULL_CANDIDATE@36..48
0: TW_VARIANT_LIST@36..36
1: TW_FUNCTIONAL_CANDIDATE@36..48
0: TW_BASE@36..39 "via" [] []
1: DASH@39..40 "-" [] []
2: TW_NAMED_VALUE@40..48
0: TW_VALUE@40..48 "blue-400" [] []
3: (empty)
2: (empty)
5: WHITESPACE@48..49 " " [] []
6: TW_FULL_CANDIDATE@49..62
0: TW_VARIANT_LIST@49..49
1: TW_FUNCTIONAL_CANDIDATE@49..62
0: TW_BASE@49..51 "to" [] []
1: DASH@51..52 "-" [] []
2: TW_NAMED_VALUE@52..62
0: TW_VALUE@52..62 "indigo-900" [] []
3: (empty)
2: (empty)
7: WHITESPACE@62..63 " " [] []
8: TW_FULL_CANDIDATE@63..70
0: TW_VARIANT_LIST@63..63
1: TW_FUNCTIONAL_CANDIDATE@63..70
0: TW_BASE@63..65 "to" [] []
1: DASH@65..66 "-" [] []
2: TW_NAMED_VALUE@66..70
0: TW_VALUE@66..70 "90%" [] [Newline("\n")]
3: (empty)
2: (empty)
2: EOF@70..70 "" [] []

```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
drop-shadow-red-500
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
source: crates/biome_tailwind_parser/tests/spec_test.rs
expression: snapshot
---
## Input

```text
drop-shadow-red-500

```


## AST

```
TwRoot {
bom_token: missing (optional),
candidates: TwCandidateList [
TwFullCandidate {
variants: TwVariantList [],
candidate: TwFunctionalCandidate {
base_token: TW_BASE@0..11 "drop-shadow" [] [],
minus_token: DASH@11..12 "-" [] [],
value: TwNamedValue {
value_token: TW_VALUE@12..20 "red-500" [] [Newline("\n")],
},
modifier: missing (optional),
},
excl_token: missing (optional),
},
],
eof_token: EOF@20..20 "" [] [],
}
```

## CST

```
0: TW_ROOT@0..20
0: (empty)
1: TW_CANDIDATE_LIST@0..20
0: TW_FULL_CANDIDATE@0..20
0: TW_VARIANT_LIST@0..0
1: TW_FUNCTIONAL_CANDIDATE@0..20
0: TW_BASE@0..11 "drop-shadow" [] []
1: DASH@11..12 "-" [] []
2: TW_NAMED_VALUE@12..20
0: TW_VALUE@12..20 "red-500" [] [Newline("\n")]
3: (empty)
2: (empty)
2: EOF@20..20 "" [] []

```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
drop-shadow-[#000000]
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
source: crates/biome_tailwind_parser/tests/spec_test.rs
expression: snapshot
---
## Input

```text
drop-shadow-[#000000]

```


## AST

```
TwRoot {
bom_token: missing (optional),
candidates: TwCandidateList [
TwFullCandidate {
variants: TwVariantList [],
candidate: TwFunctionalCandidate {
base_token: TW_BASE@0..11 "drop-shadow" [] [],
minus_token: DASH@11..12 "-" [] [],
value: TwArbitraryValue {
l_brack_token: L_BRACKET@12..13 "[" [] [],
value_token: TW_VALUE@13..20 "#000000" [] [],
r_brack_token: R_BRACKET@20..22 "]" [] [Newline("\n")],
},
modifier: missing (optional),
},
excl_token: missing (optional),
},
],
eof_token: EOF@22..22 "" [] [],
}
```

## CST

```
0: TW_ROOT@0..22
0: (empty)
1: TW_CANDIDATE_LIST@0..22
0: TW_FULL_CANDIDATE@0..22
0: TW_VARIANT_LIST@0..0
1: TW_FUNCTIONAL_CANDIDATE@0..22
0: TW_BASE@0..11 "drop-shadow" [] []
1: DASH@11..12 "-" [] []
2: TW_ARBITRARY_VALUE@12..22
0: L_BRACKET@12..13 "[" [] []
1: TW_VALUE@13..20 "#000000" [] []
2: R_BRACKET@20..22 "]" [] [Newline("\n")]
3: (empty)
2: (empty)
2: EOF@22..22 "" [] []

```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
border-spacing-y-[2px]
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
source: crates/biome_tailwind_parser/tests/spec_test.rs
expression: snapshot
---
## Input

```text
border-spacing-y-[2px]

```


## AST

```
TwRoot {
bom_token: missing (optional),
candidates: TwCandidateList [
TwFullCandidate {
variants: TwVariantList [],
candidate: TwFunctionalCandidate {
base_token: TW_BASE@0..16 "border-spacing-y" [] [],
minus_token: DASH@16..17 "-" [] [],
value: TwArbitraryValue {
l_brack_token: L_BRACKET@17..18 "[" [] [],
value_token: TW_VALUE@18..21 "2px" [] [],
r_brack_token: R_BRACKET@21..23 "]" [] [Newline("\n")],
},
modifier: missing (optional),
},
excl_token: missing (optional),
},
],
eof_token: EOF@23..23 "" [] [],
}
```

## CST

```
0: TW_ROOT@0..23
0: (empty)
1: TW_CANDIDATE_LIST@0..23
0: TW_FULL_CANDIDATE@0..23
0: TW_VARIANT_LIST@0..0
1: TW_FUNCTIONAL_CANDIDATE@0..23
0: TW_BASE@0..16 "border-spacing-y" [] []
1: DASH@16..17 "-" [] []
2: TW_ARBITRARY_VALUE@17..23
0: L_BRACKET@17..18 "[" [] []
1: TW_VALUE@18..21 "2px" [] []
2: R_BRACKET@21..23 "]" [] [Newline("\n")]
3: (empty)
2: (empty)
2: EOF@23..23 "" [] []

```
Loading