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
130 changes: 130 additions & 0 deletions assets/highlighting-tests/go.go
Original file line number Diff line number Diff line change
@@ -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"}
}
10 changes: 0 additions & 10 deletions assets/highlighting-tests/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
53 changes: 53 additions & 0 deletions crates/lsh/definitions/go.lsh
Original file line number Diff line number Diff line change
@@ -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;
}
}
12 changes: 1 addition & 11 deletions crates/lsh/definitions/markdown.lsh
Original file line number Diff line number Diff line change
Expand Up @@ -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*```/ {
Expand Down
Loading