Skip to content
Closed
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
3 changes: 3 additions & 0 deletions crates/lsh/definitions/cpp.lsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
#[path = "**/*.cpp"]
#[path = "**/*.cc"]
#[path = "**/*.cxx"]
#[path = "**/*.hh"]
#[path = "**/*.hpp"]
#[path = "**/*.hxx"]
#[path = "**/*.ixx"]
#[path = "**/*.h"]
pub fn cpp() {
until /$/ {
Expand Down
1 change: 1 addition & 0 deletions crates/lsh/definitions/fsharp.lsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#[path = "**/*.fs"]
#[path = "**/*.fsi"]
#[path = "**/*.fsx"]
#[path = "**/*.fsscript"]
pub fn fsharp() {
// Compiler and script directives always occupy the entire line.
if /\s*#(?:if|else|endif|light|line|load|nowarn|time|help|quit|r|I)\>.*/ {
Expand Down
2 changes: 2 additions & 0 deletions crates/lsh/definitions/json.lsh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[display_name = "JSON"]
#[path = "**/*.json"]
#[path = "**/*.jsonc"]
#[path = "**/*.jsonl"]
#[path = "**/*.ndjson"]
pub fn json() {
until /$/ {
yield other;
Expand Down
11 changes: 11 additions & 0 deletions crates/lsh/definitions/markdown.lsh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[display_name = "Markdown"]
#[path = "**/*.md"]
#[path = "**/*.markdown"]
pub fn markdown() {
// Any lines that start with a tab or 4+ spaces are code blocks.
if /(?:\t| ).*/ {
Expand Down Expand Up @@ -90,6 +91,16 @@ pub fn markdown() {
if /.*/ {}
}
}
} else if /(?i:sql)/ {
loop {
await input;
if /\s*```/ {
return;
} else {
sql();
if /.*/ {}
}
}
} else if /(?i:pwsh|powershell)/ {
loop {
await input;
Expand Down
81 changes: 81 additions & 0 deletions crates/lsh/definitions/sql.lsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#[display_name = "SQL"]
#[path = "**/*.sql"]
pub fn sql() {
until /$/ {
yield other;

if /--.*/ {
yield comment;
} else if /\/\*/ {
loop {
yield comment;
await input;
if /\*\// {
yield comment;
break;
}
}
} else if /'/ {
// Single-quoted string. '' is an escaped quote.
until /$/ {
yield string;
if /''/ {
// Escaped quote, stay in string.
} else if /'/ {
yield string;
break;
}
await input;
}
} else if /"/ {
// Quoted identifier. "" is an escaped quote.
until /$/ {
yield string;
if /""/ {
// Escaped quote, stay in string.
} else if /"/ {
yield string;
break;
}
await input;
}
} else if /`/ {
// MySQL quoted identifier. `` is an escaped quote.
until /$/ {
yield string;
if /``/ {
// Escaped quote, stay in string.
} else if /`/ {
yield string;
break;
}
await input;
}
} else if /\[[^\]]*\]/ {
// T-SQL bracketed identifier: [column name].
yield string;
} else if /(?i:case|when|then|else|end|if|loop|while|for|repeat|leave|return|begin|cursor|handler|trigger|break|continue|do)\>/ {
yield keyword.control;
} else if /(?i:select|from|where|join|inner|outer|left|right|full|cross|on|using|group|by|order|having|limit|offset|fetch|union|intersect|except|all|distinct|as|into|values|set|insert|update|delete|merge|create|alter|drop|table|view|index|sequence|schema|database|primary|foreign|key|references|constraint|unique|check|default|not|and|or|between|in|like|ilike|is|exists|any|some|escape|over|partition|rows|range|unbounded|preceding|following|current|row|with|recursive|grant|revoke|commit|rollback|transaction|explain|analyze|vacuum)\>/ {
yield keyword.other;
} else if /(?i:true|false|null|unknown)\>/ {
yield constant.language;
} else if /(?i:count|sum|avg|min|max|coalesce|nullif|cast|extract|substring|trim|upper|lower|length|concat|now|current_date|current_time|current_timestamp)\>/ {
yield method;
} else if /(?i:smallint|integer|int|bigint|decimal|numeric|real|double|precision|float|serial|bigserial|money|char|varchar|text|bytea|timestamp|date|time|interval|boolean|bool|uuid|json|jsonb|xml|array)\>/ {
yield storage.type;
} else if /(?i:-?(?:0x[\da-fA-F_]+|0b[01_]+|0o[0-7_]+|[\d_]+\.?[\d_]*|\.[\d_]+)(?:e[+-]?[\d_]+)?)/ {
if /\w+/ {
// Invalid numeric literal
} else {
yield constant.numeric;
}
} else if /(\w+)\s*\(/ {
yield $1 as method;
} else if /\w+/ {
// Gobble word chars to align the next iteration on a word boundary.
}

yield other;
}
}
2 changes: 1 addition & 1 deletion crates/lsh/definitions/xml.lsh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#[path = "**/*.vcxproj.filters"]
#[path = "**/*.vcxproj"]
#[path = "**/*.xaml"]
#[path = "**/*.xml"]
#[path = "**/*.xhtml"]
#[path = "**/*.xml"]
pub fn xml() {
until /$/ {
Expand Down
82 changes: 81 additions & 1 deletion crates/lsh/definitions/yaml.lsh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,77 @@ pub fn yaml() {

if /---/ {
yield other;
} else if /!![\w-]+/ {
// Explicit tag, e.g. !!str, !!int (see YAML 1.2.2 §6.9.1).
yield storage.type;
if /\s+/ {
yield other;
}
if /'/ {
until /$/ {
yield string;
if /''/ {
} else if /'/ {
yield string;
break;
}
await input;
}
} else if /"/ {
until /$/ {
yield string;
if /\\./ {
} else if /"/ {
yield string;
break;
}
await input;
}
} else if /true|false|yes|no|null|~/ {
if /\s*[^\s#]+[^#]*/ {
yield string;
} else {
yield constant.language;
}
} else if /(?i:[+-]?\.(?:inf|nan))\>/ {
if /\s*[^\s#]+[^#]*/ {
yield string;
} else {
yield constant.numeric;
}
} else if /-?(?:0x[\da-fA-F_]+|0o[0-7_]+|0b[01_]+|\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/ {
if /\s*[^\s#]+[^#]*/ {
yield string;
} else {
yield constant.numeric;
}
} else if /[^\s#]+[^#]*/ {
yield string;
}
} else if /'/ {
// Single-quoted string. '' is an escaped quote (see YAML 1.2.2 §7.3.2).
// Handled explicitly so that '#' inside quotes isn't mistaken for a comment.
until /$/ {
yield string;
if /''/ {
// Escaped quote, stay in string.
} else if /'/ {
yield string;
break;
}
await input;
}
} else if /"/ {
// Double-quoted string with backslash escapes.
until /$/ {
yield string;
if /\\./ {
} else if /"/ {
yield string;
break;
}
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,7 +125,16 @@ pub fn yaml() {
} else {
yield constant.language;
}
} else if /-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/ {
} else if /(?i:[+-]?\.(?:inf|nan))\>/ {
// Special values: .inf, -.inf, +.inf, .nan (see YAML 1.2.2 §2.4, Example 2.20).
// Same as with keywords above: trailing content means it's actually a string.
if /\s*[^\s#]+[^#]*/ {
yield string;
} else {
yield constant.numeric;
}
} else if /-?(?:0x[\da-fA-F_]+|0o[0-7_]+|0b[01_]+|\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/ {
// Numbers, incl. hex/octal/binary (see YAML 1.2.2 §2.4, Example 2.19).
// Same as with keywords above.
if /\s*[^\s#]+[^#]*/ {
yield string;
Expand Down