Skip to content

Commit 4ed28e0

Browse files
committed
Simplify expressions
1 parent 831740b commit 4ed28e0

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

crates/lsh/definitions/toml.lsh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ pub fn toml() {
1010
}
1111

1212
// Table headers: [table], [a.b.c] and [[array.of.tables]].
13-
if /\[\[[^\]]*\]\]/ {
14-
yield meta.header;
15-
} else if /\[[^\]]*\]/ {
16-
yield meta.header;
13+
if /\[\[([^\]]*)\]\]/ {
14+
yield $1 as meta.header;
15+
} else if /\[([^\]]*)\]/ {
16+
yield $1 as meta.header;
1717
}
1818

1919
yield other;
@@ -50,15 +50,14 @@ pub fn toml() {
5050
yield $1 as variable;
5151
}
5252
// Bare or dotted key: key = ..., a.b.c = ... (also matches inside inline tables).
53-
else if /([A-Za-z0-9_.-]+)[ \t]*=/ {
53+
else if /([\w.-]+)[ \t]*=/ {
5454
yield $1 as variable;
5555
} else if /"/ {
5656
double_quote_string();
5757
} else if /'/ {
5858
// Literal string: no escape sequences, so a trailing backslash
5959
// (e.g. a Windows path like 'C:\dir\') still ends the string.
6060
until /$/ {
61-
yield string;
6261
if /'/ {
6362
yield string;
6463
break;
@@ -68,13 +67,13 @@ pub fn toml() {
6867
yield constant.language;
6968
} else if /\+?-?(?:inf|nan)\>/ {
7069
yield constant.language;
71-
} else if /\d{4}-\d{2}-\d{2}(?:[Tt ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})?)?/ {
70+
} else if /(?i:\d{4}-\d{2}-\d{2}(?:[Tt ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:z|[+-]\d{2}:\d{2})?)?)/ {
7271
// Offset date-time, local date-time and local date.
7372
yield constant.numeric;
7473
} else if /\d{2}:\d{2}:\d{2}(?:\.\d+)?/ {
7574
// Local time.
7675
yield constant.numeric;
77-
} else if /\+?-?(?:0x[0-9a-fA-F][0-9a-fA-F_]*|0o[0-7][0-7_]*|0b[01][01_]*|\d[\d_]*(?:\.\d[\d_]*)?(?:[eE][+-]?\d[\d_]*)?)/ {
76+
} else if /(?i:\+?-?(?:0x[\da-fA-F_]+|0b[01_]+|0o[0-7_]+|[\d_]+\.?[\d_]*|\.[\d_]+)(?:e[+-]?[\d_]+)?)/ {
7877
if /\w+/ {
7978
// Not a number after all.
8079
} else {

0 commit comments

Comments
 (0)