diff --git a/assets/highlighting-tests/go.go b/assets/highlighting-tests/go.go new file mode 100644 index 00000000000..517715dc6d8 --- /dev/null +++ b/assets/highlighting-tests/go.go @@ -0,0 +1,130 @@ +// Line comment +/* + * Multi-line + * comment + */ + +package main + +import ( + "fmt" + "time" +) + +// Numbers +const ( + Dec = 42 + Neg = -7 + Hex = 0xCAFE_BABE + Oct = 0o755 + Old = 0755 + Bin = 0b1010 + Sep = 1_000_000 + Flt = 3.14 + Half = .5 + Exp = 1e10 + Sci = 1.5e-3 + Imag = 2.5i +) + +// Constants and iota +const ( + A = iota + B +) + +var ( + yes = true + no = false + none = nil +) + +// Predeclared types +var ( + b bool + by byte + r rune + s string + i int + i8 int8 + i64 int64 + u uint + u32 uint32 + up uintptr + f64 float64 + c128 complex128 + e error + a any +) + +// Strings and runes +var ( + char = 'a' + escaped = '\n' + quote = '\'' + str = "double quotes with escapes: \" \n \t \\" + raw = `raw string +spans lines and may contain "quotes"` +) + +type Speaker interface { + Speak() string +} + +type Animal struct { + Name string `json:"name"` +} + +func (a Animal) Speak() string { + return fmt.Sprintf("%s speaks", a.Name) +} + +func compare[T comparable](a, b T) bool { + return a == b +} + +func main() { + if yes { + fmt.Println("enabled") + } else { + fmt.Println("disabled") + } + + for i := 0; i < 10; i++ { + switch { + case i == 5: + continue + case i == 8: + goto done + default: + fallthrough + } + } + + switch now := time.Now().Weekday(); now { + case time.Saturday, time.Sunday: + fmt.Println("weekend") + } + + values := []int{1, 2, 3} + m := map[string]int{"one": 1} + for _, value := range values { + fmt.Println(value, m) + } + + ch := make(chan int, 1) + go func() { + defer close(ch) + ch <- 42 + }() + + select { + case msg := <-ch: + fmt.Println(msg) + default: + fmt.Println("no message") + } + +done: + var _ Speaker = Animal{Name: "dog"} +} diff --git a/assets/highlighting-tests/markdown.md b/assets/highlighting-tests/markdown.md index 8044e5a9895..555b182f961 100644 --- a/assets/highlighting-tests/markdown.md +++ b/assets/highlighting-tests/markdown.md @@ -80,16 +80,6 @@ export function greet(name) { } ``` -```lua -local function greet(name) - return "hello " .. name -end -``` - -```luau -export type Greeting = (name: string) -> string -``` - ```python def greet(name: str) -> str: return f"hello {name}" diff --git a/crates/lsh/definitions/go.lsh b/crates/lsh/definitions/go.lsh new file mode 100644 index 00000000000..8b1d82c5279 --- /dev/null +++ b/crates/lsh/definitions/go.lsh @@ -0,0 +1,53 @@ +#[display_name = "Go"] +#[path = "**/*.go"] +pub fn go() { + until /$/ { + yield other; + + if /\/\/.*/ { + yield comment; + } else if /\/\*/ { + loop { + yield comment; + await input; + if /\*\// { + yield comment; + break; + } + } + } else if /`/ { + loop { + yield string; + if /`/ { + yield string; + break; + } + await input; + } + } else if /'/ { + single_quote_string(); + } else if /"/ { + double_quote_string(); + } else if /(?:break|case|continue|default|defer|else|fallthrough|for|goto|go|if|range|return|select|switch)\>/ { + yield keyword.control; + } else if /(?:chan|const|func|import|interface|map|package|struct|type|var)\>/ { + yield keyword.other; + } else if /(?:true|false|iota|nil)\>/ { + yield constant.language; + } else if /(?:any|bool|byte|comparable|complex128|complex64|error|float32|float64|int8|int16|int32|int64|int|rune|string|uint8|uint16|uint32|uint64|uintptr|uint)\>/ { + yield storage.type; + } else if /(?i:-?(?:0x[\da-f_]+|0b[01_]+|0o[0-7_]+|\d[\d_]*\.?[\d_]*|\.[\d_]+)(?:[ep][+-]?[\d_]+)?i?)/ { + 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; + } +} diff --git a/crates/lsh/definitions/markdown.lsh b/crates/lsh/definitions/markdown.lsh index 75d5c1a6cbd..2abaa580c00 100644 --- a/crates/lsh/definitions/markdown.lsh +++ b/crates/lsh/definitions/markdown.lsh @@ -60,17 +60,7 @@ pub fn markdown() { if /.*/ {} } } - } else if /(?i:lua|luau)/ { - loop { - await input; - if /\s*```/ { - return; - } else { - lua(); - if /.*/ {} - } - } - } else if /(?i:py)/ { + } else if /(?i:py|python)/ { loop { await input; if /\s*```/ {