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
43 changes: 43 additions & 0 deletions assets/highlighting-tests/yaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,27 @@ number_int: 42
number_float: 3.1415
number_scientific: 1.23e45
number_negative: -7
number_positive: +7
number_hex: 0xC
number_octal: 0o14
number_binary: 0b1010
number_hex_negative: -0xC
number_hex_separated: 0xCA_FE
number_inf: .inf
number_inf_negative: -.Inf
number_inf_positive: +.INF
number_nan: .NaN
boolean_true: true
boolean_false: false
null_value: null
explicit_null: ~
date: 2024-06-01
timestamp: 2024-06-01T12:34:56Z
confusable_string_number: 1.23e45 1.23e45 # This is a comment
confusable_hex: 0xCafe extra # This is a comment
confusable_inf: .infinite
confusable_nan: .nan suffix
confusable_binary: 0b1010suffix
sequence:
- item1
- item2
Expand All @@ -41,3 +55,32 @@ empty_mapping: { foo: bar }
literal_colon: "value:with:colons"
literal_dash: "-not-a-sequence"
special_chars: "Tab:\t Newline:\n Unicode:\u2713"
single_quoted: "It's YAML # not a comment" # This is a comment
double_quoted: 'An escaped "quote" # not a comment' # This is a comment
empty_single: ""
empty_double: ""
multiline_single: "An escaped quote at end of line: '
# still a string" # This is a comment
multiline_double: 'An escaped quote at end of line: "
# still a string' # This is a comment
tagged_number: !!str 123
tagged_quote: !!int "42" # This is a comment
tagged_boolean: !!bool true
tagged_inf: !!float -.inf
tagged_plain: !!str a plain value # This is a comment
tagged_empty: !!str ""
tagged_single: !!str "An escaped quote at end of line: '
# still a string" # This is a comment
tagged_double: !!str 'An escaped quote at end of line: "
# still a string' # This is a comment
tagged_literal: !!str |
true
# literal text
after_tagged_literal: false
tagged_folded: !!str >
.inf
0xC
after_tagged_folded: 42
tagged_sequence:
- !!str "# not a comment"
- !!int 0o14
32 changes: 30 additions & 2 deletions crates/lsh/definitions/yaml.lsh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ pub fn yaml() {
// Key: (Value follows)
}

yield other;

if /!![\w-]+/ {
yield storage.type;
if /\s+/ {
yield other;
}
}

if /[|>][-+]?.*/ {
// If we see a multiline string inducer, capture content until indentation is back to before.
// Since we'll skip multiple lines, we need to use nested loops here.
Expand Down Expand Up @@ -46,6 +55,26 @@ pub fn yaml() {

if /---/ {
yield other;
} else if /'/ {
loop {
if /''/ {
} else if /'/ {
yield string;
break;
}
yield string;
await input;
}
} else if /"/ {
loop {
if /\\./ {
} else if /"/ {
yield string;
break;
}
yield string;
await input;
}
} else if /true|false|yes|no|null|~/ {
// If it looks like a keyword, check if it's actually a string (e.g. "foo: true false").
// TODO: Ideally this would not consume the last chunk of /\s+/ before a /# comment/.
Expand All @@ -54,8 +83,7 @@ pub fn yaml() {
} else {
yield constant.language;
}
} else if /-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/ {
// Same as with keywords above.
} else if /[+-]?(?i:\.inf|\.nan|(?:0x[\da-f_]+|0o[0-7_]+|0b[01_]+|\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)/ {
if /\s*[^\s#]+[^#]*/ {
yield string;
} else {
Expand Down
Loading