Feat: Add syntax highlighting for a lot more languages

This commit is contained in:
2025-12-26 20:46:36 +00:00
parent 9ff3a32abd
commit 655f0e7d77
64 changed files with 9030 additions and 1607 deletions

119
samples/Makefile Normal file
View File

@@ -0,0 +1,119 @@
SRC_DIR := src
BIN_DIR := bin
OBJ_DIR := build
INCLUDE_DIR := include
TARGET_DEBUG := $(BIN_DIR)/crib-dbg
TARGET_RELEASE := $(BIN_DIR)/crib
PCH_DEBUG := $(OBJ_DIR)/debug/pch.h.gch
PCH_RELEASE := $(OBJ_DIR)/release/pch.h.gch
CCACHE := ccache
CXX_DEBUG := $(CCACHE) g++
CXX_RELEASE := $(CCACHE) clang++
CFLAGS_DEBUG := -std=c++20 -Wall -Wextra -O0 -fno-inline -gsplit-dwarf -g -fsanitize=address -fno-omit-frame-pointer
CFLAGS_RELEASE := -std=c++20 -O3 -march=native -flto=thin \
-fno-exceptions -fno-rtti -fstrict-aliasing \
-ffast-math -funroll-loops \
-fvisibility=hidden \
-fomit-frame-pointer -DNDEBUG -s \
-mllvm -vectorize-loops \
-fno-unwind-tables -fno-asynchronous-unwind-tables
PCH_CFLAGS_DEBUG := $(CFLAGS_DEBUG) -x c++-header
PCH_CFLAGS_RELEASE := $(CFLAGS_RELEASE) -x c++-header
UNICODE_SRC := $(wildcard libs/unicode_width/*.c)
UNICODE_OBJ_DEBUG := $(patsubst libs/unicode_width/%.c,$(OBJ_DIR)/debug/unicode_width/%.o,$(UNICODE_SRC))
UNICODE_OBJ_RELEASE := $(patsubst libs/unicode_width/%.c,$(OBJ_DIR)/release/unicode_width/%.o,$(UNICODE_SRC))
TREE_SITTER_LIBS := $(wildcard libs/tree-sitter-*/libtree-sitter*.a)
PHP_LIB := libs/tree-sitter-php/php/libtree-sitter-php.a
NGINX_OBJ_PARSER := libs/tree-sitter-nginx/build/Release/obj.target/tree_sitter_nginx_binding/src/parser.o
GITIGNORE_OBJ_PARSER := libs/tree-sitter-gitignore/build/Release/obj.target/tree_sitter_ignore_binding/src/parser.o
FISH_OBJ_PARSER := libs/tree-sitter-fish/build/Release/obj.target/tree_sitter_fish_binding/src/parser.o
FISH_OBJ_SCANNER := libs/tree-sitter-fish/build/Release/obj.target/tree_sitter_fish_binding/src/scanner.o
MD_OBJ_PARSER := libs/tree-sitter-markdown/build/Release/obj.target/tree_sitter_markdown_binding/tree-sitter-markdown/src/parser.o
MD_OBJ_SCANNER := libs/tree-sitter-markdown/build/Release/obj.target/tree_sitter_markdown_binding/tree-sitter-markdown/src/scanner.o
MD_I_OBJ_PARSER := libs/tree-sitter-markdown/build/Release/obj.target/tree_sitter_markdown_binding/tree-sitter-markdown-inline/src/parser.o
MD_I_OBJ_SCANNER := libs/tree-sitter-markdown/build/Release/obj.target/tree_sitter_markdown_binding/tree-sitter-markdown-inline/src/scanner.o
LIBS := \
libs/libgrapheme/libgrapheme.a \
libs/tree-sitter/libtree-sitter.a \
$(TREE_SITTER_LIBS) \
$(PHP_LIB) \
$(NGINX_OBJ_PARSER) \
$(GITIGNORE_OBJ_PARSER) \
$(FISH_OBJ_PARSER) \
$(FISH_OBJ_SCANNER) \
$(MD_OBJ_PARSER) \
$(MD_OBJ_SCANNER) \
$(MD_I_OBJ_PARSER) \
$(MD_I_OBJ_SCANNER) \
-lpcre2-8 -lmagic
SRC := $(wildcard $(SRC_DIR)/*.cc)
OBJ_DEBUG := $(patsubst $(SRC_DIR)/%.cc,$(OBJ_DIR)/debug/%.o,$(SRC))
OBJ_RELEASE := $(patsubst $(SRC_DIR)/%.cc,$(OBJ_DIR)/release/%.o,$(SRC))
DEP_DEBUG := $(OBJ_DEBUG:.o=.d)
DEP_RELEASE := $(OBJ_RELEASE:.o=.d)
.PHONY: all test release clean
all: debug
test: $(TARGET_DEBUG)
release: $(TARGET_RELEASE)
$(PCH_DEBUG): $(INCLUDE_DIR)/pch.h
mkdir -p $(dir $@)
$(CXX_DEBUG) $(PCH_CFLAGS_DEBUG) -o $@ $<
$(PCH_RELEASE): $(INCLUDE_DIR)/pch.h
mkdir -p $(dir $@)
$(CXX_RELEASE) $(PCH_CFLAGS_RELEASE) -o $@ $<
$(TARGET_DEBUG): $(PCH_DEBUG) $(OBJ_DEBUG) $(UNICODE_OBJ_DEBUG)
mkdir -p $(BIN_DIR)
$(CXX_DEBUG) $(CFLAGS_DEBUG) -o $@ $(OBJ_DEBUG) $(UNICODE_OBJ_DEBUG) $(LIBS)
$(TARGET_RELEASE): $(PCH_RELEASE) $(OBJ_RELEASE) $(UNICODE_OBJ_RELEASE)
mkdir -p $(BIN_DIR)
$(CXX_RELEASE) $(CFLAGS_RELEASE) -o $@ $(OBJ_RELEASE) $(UNICODE_OBJ_RELEASE) $(LIBS)
$(OBJ_DIR)/debug/%.o: $(SRC_DIR)/%.cc $(PCH_DEBUG)
mkdir -p $(dir $@)
$(CXX_DEBUG) $(CFLAGS_DEBUG) -include $(INCLUDE_DIR)/pch.h -MMD -MP -c $< -o $@
$(OBJ_DIR)/release/%.o: $(SRC_DIR)/%.cc $(PCH_RELEASE)
mkdir -p $(dir $@)
$(CXX_RELEASE) $(CFLAGS_RELEASE) -include $(INCLUDE_DIR)/pch.h -MMD -MP -c $< -o $@
$(OBJ_DIR)/debug/unicode_width/%.o: libs/unicode_width/%.c
mkdir -p $(dir $@)
$(CXX_DEBUG) $(CFLAGS_DEBUG) -MMD -MP -c $< -o $@
$(OBJ_DIR)/release/unicode_width/%.o: libs/unicode_width/%.c
mkdir -p $(dir $@)
$(CXX_RELEASE) $(CFLAGS_RELEASE) -MMD -MP -c $< -o $@
DEP_DEBUG += $(UNICODE_OBJ_DEBUG:.o=.d)
DEP_RELEASE += $(UNICODE_OBJ_RELEASE:.o=.d)
-include $(DEP_DEBUG)
-include $(DEP_RELEASE)
clean:
rm -rf $(OBJ_DIR) $(BIN_DIR)

70
samples/css.css Normal file
View File

@@ -0,0 +1,70 @@
/* === Basic selectors === */
body {
margin: 0;
font-family: system-ui, sans-serif;
background: #121212;
color: #eee;
}
/* Class + ID + attribute */
#main.container[data-theme="dark"] {
padding: 1rem;
border: 1px solid rgba(255, 255, 255, 0.2);
}
/* Pseudo-classes & elements */
a:hover,
a:focus-visible {
color: hsl(210, 80%, 60%);
text-decoration: underline;
}
input::placeholder {
color: #999;
}
/* CSS variables */
:root {
--accent: #4fc3f7;
--spacing: 1rem;
}
.button {
background: var(--accent);
padding: calc(var(--spacing) * 1.5);
}
/* Media query */
@media (max-width: 768px) {
.container {
padding: 0.5rem;
}
}
/* Keyframes */
@keyframes fade-in {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* Animation usage */
.modal {
animation: fade-in 250ms ease-out;
}
/* Complex selector */
ul > li:not(:last-child)::after {
content: "•";
margin-left: 0.5em;
}
/* Edge cases */
[data-value^="test"]::before {
content: attr(data-value);
}

102
samples/diff.patch Normal file
View File

@@ -0,0 +1,102 @@
--- ./samples/toml.toml 2025-12-26 19:02:50.480936043 +0000
+++ ./samples/yaml.yml 2025-12-26 19:03:27.879765974 +0000
@@ -2,52 +2,65 @@
# Basic types
# ============================================================
-title = "Example TOML Configuration"
-enabled = true
-count = 42
-pi = 3.14159
-empty = ""
+title: "Example YAML Configuration"
+enabled: true
+count: 42
+pi: 3.14159
+empty: ""
# ============================================================
-# Arrays
+# Arrays / Lists
# ============================================================
-fruits = ["apple", "banana", "cherry"]
-numbers = [1, 2, 3, 4, 5]
+fruits:
+ - apple
+ - banana
+ - cherry
-# Nested array
-matrix = [[1, 2], [3, 4]]
+numbers:
+ - 1
+ - 2
+ - 3
+ - 4
+ - 5
+
+matrix:
+ - [1, 2]
+ - [3, 4]
# ============================================================
-# Tables
+# Nested objects / maps
# ============================================================
-[owner]
-name = "Alice"
-dob = 1979-05-27T07:32:00Z
-
-[database]
-server = "192.168.1.1"
-ports = [ 8001, 8001, 8002 ]
-connection_max = 5000
-enabled = true
+owner:
+ name: Alice
+ dob: 1979-05-27T07:32:00Z
-[servers.alpha]
-ip = "10.0.0.1"
-dc = "east"
+database:
+ server: 192.168.1.1
+ ports:
+ - 8001
+ - 8001
+ - 8002
+ connection_max: 5000
+ enabled: true
-[servers.beta]
-ip = "10.0.0.2"
-dc = "west"
+servers:
+ alpha:
+ ip: 10.0.0.1
+ dc: east
+ beta:
+ ip: 10.0.0.2
+ dc: west
# ============================================================
-# Inline tables
+# Multiline string
# ============================================================
-clients = { name = "Bob", age = 30, active = true }
+description: |
+ This is a YAML file
+ used for testing syntax highlighting.
+ It supports multiple lines.
# ============================================================
-# Multiline strings
+# Special characters
# ============================================================
-description = """
-This is a TOML file
-used for testing syntax highlighting.
-It supports multiple lines.
-"""
+regex_pattern: "^[A-Za-z0-9_]+$"
+path: "C:\\Users\\Alice\\Documents"

View File

@@ -0,0 +1,71 @@
<%# app/views/users/show.html.erb %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><%= @user.name %> — Profile</title>
<%# Inline Ruby expression %>
<meta name="description" content="<%= @user.bio %>">
<% if @dark_mode %>
<style>
body {
background-color: #111;
color: #eee;
}
</style>
<% end %>
</head>
<body>
<!-- HTML comment -->
<header>
<h1>Welcome, <%= @user.name %></h1>
<p class="subtitle">
Member since <%= @user.created_at.strftime("%Y") %>
</p>
</header>
<% if @user.admin? %>
<section class="admin-panel">
<h2>Admin Tools</h2>
<ul>
<% @tools.each do |tool| %>
<li><%= tool.title %></li>
<% end %>
</ul>
</section>
<% else %>
<p>You do not have admin privileges.</p>
<% end %>
<section class="posts">
<% @posts.each do |post| %>
<article class="post">
<h3><%= post.title %></h3>
<p><%= truncate(post.body, length: 140) %></p>
<%# Conditional rendering %>
<% if post.published? %>
<span class="status published">Published</span>
<% else %>
<span class="status draft">Draft</span>
<% end %>
</article>
<% end %>
</section>
<footer>
<p>&copy; <%= Time.now.year %> Example Corp</p>
<%= link_to "Privacy Policy", "/privacy" %>
</footer>
<script>
// JavaScript inside ERB
const userName = "<%= j @user.name %>";
console.log(`Loaded profile for ${userName}`);
</script>
</body>
</html>

92
samples/fish.fish Normal file
View File

@@ -0,0 +1,92 @@
#!/usr/bin/env fish
# Fish highlighting torture test 🐟
# === Variables ===
set normal_var "hello"
set -l local_var 123
set -gx GLOBAL_VAR "world"
set PATH $PATH /usr/local/bin
set --erase OLD_VAR
# Builtin variables
echo $HOME $PWD $USER $FISH_VERSION
# === Strings ===
set single 'single quoted string'
set double "double quoted $normal_var"
set escaped "newline\n tab\t dollar\$"
# === Conditionals ===
if test $normal_var = "hello"
echo "equal"
else if test $normal_var != "world"
echo "not equal"
end
# === Logical operators ===
true and echo "yes"
false or echo "fallback"
not false
# === Arithmetic ===
set x 10
set y 20
math "$x + $y"
if test (math "$x * 2") -gt 15
echo "math works"
end
# === Loops ===
for i in 1 2 3
echo "loop $i"
end
while test $x -gt 0
set x (math "$x - 1")
end
# === Functions ===
function greet --argument name
echo "Hello $name"
end
greet "world"
# === Command substitution ===
set files (ls | grep ".fish")
# === Redirections ===
echo "output" > /tmp/fish_test.txt
cat < /tmp/fish_test.txt >> /tmp/fish_log.txt
# === Process substitution ===
diff (ls /bin) (ls /usr/bin)
# === Case statement ===
switch $argv[1]
case start
echo "Starting"
case stop
echo "Stopping"
case '*'
echo "Unknown"
end
# === Subshell ===
begin
echo "inside begin/end"
end
# === Comments & operators ===
# && || | & ! should all highlight
true && echo "ok" || echo "fail"
# === Regex ===
string match -r '^[a-z]+$' "hello"
# === Test builtin ===
test -f /etc/passwd
test ! -d /does/not/exist
# === Exit ===
exit 0

81
samples/gdscript.gd Normal file
View File

@@ -0,0 +1,81 @@
# Sample GDScript for syntax highlighting
extends Node2D
# ============================================================
# Constants
# ============================================================
const MAX_HEALTH = 100
const PLAYER_SPEED = 200
const PI_APPROX = 3.14159
# ============================================================
# Exported variables
# ============================================================
@export var player_name: String = "Hero"
@export var is_alive: bool = true
# ============================================================
# Signals
# ============================================================
signal health_changed(new_health)
# ============================================================
# Member variables
# ============================================================
var health: int = MAX_HEALTH
var velocity: Vector2 = Vector2.ZERO
var inventory: Array = []
# ============================================================
# Functions
# ============================================================
func _ready() -> void:
print("Player ready:", player_name)
_initialize_inventory()
set_process(true)
func _process(delta: float) -> void:
if is_alive:
_handle_input(delta)
_check_health()
# Private functions
func _initialize_inventory() -> void:
inventory.append("Sword")
inventory.append("Shield")
func _handle_input(delta: float) -> void:
var direction: Vector2 = Vector2.ZERO
if Input.is_action_pressed("ui_right"):
direction.x += 1
if Input.is_action_pressed("ui_left"):
direction.x -= 1
if Input.is_action_pressed("ui_down"):
direction.y += 1
if Input.is_action_pressed("ui_up"):
direction.y -= 1
velocity = direction.normalized() * PLAYER_SPEED
position += velocity * delta
func _check_health() -> void:
if health <= 0:
is_alive = false
print("Player is dead!")
else:
emit_signal("health_changed", health)
# ============================================================
# Example of class definition inside another script
# ============================================================
class Weapon:
var name: String
var damage: int
func _init(name: String, damage: int):
self.name = name
self.damage = damage
func attack():
print(name, "attacks for", damage, "damage")

95
samples/go.go Normal file
View File

@@ -0,0 +1,95 @@
// file: go.go
package example_test
import (
"context"
"fmt"
"math"
"sync"
"testing"
"time"
)
// Simple interface
type Adder interface {
Add(a, b int) int
}
// Concrete implementation
type Calculator struct{}
func (Calculator) Add(a, b int) int {
return a + b
}
// Generic helper
func Max[T ~int | ~float64](a, b T) T {
if a > b {
return a
}
return b
}
// Table-driven test
func TestAdd(t *testing.T) {
tests := []struct {
name string
a, b int
expected int
}{
{"positive", 2, 3, 5},
{"negative", -2, -3, -5},
{"mixed", -2, 5, 3},
}
var calc Adder = Calculator{}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := calc.Add(tt.a, tt.b); got != tt.expected {
t.Fatalf("Add(%d, %d) = %d; want %d",
tt.a, tt.b, got, tt.expected)
}
})
}
}
// Concurrency + context test
func TestWorker(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()
ch := make(chan int)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
select {
case ch <- 42:
case <-ctx.Done():
}
}()
select {
case v := <-ch:
if v != 42 {
t.Errorf("unexpected value: %d", v)
}
case <-ctx.Done():
t.Fatal("timed out")
}
wg.Wait()
}
// Raw string + math edge case
func TestRawString(t *testing.T) {
raw := `line 1
line 2
\t not escaped
`
if len(raw) == 0 || math.IsNaN(float64(len(raw))) {
t.Fatal("impossible condition reached")
}
}

32
samples/go.mod Normal file
View File

@@ -0,0 +1,32 @@
module github.com/example/project
go 1.21
// ==============================
// Direct dependencies
// ==============================
require (
github.com/sirupsen/logrus v1.10.0
golang.org/x/net v0.10.0
github.com/pkg/errors v0.9.2 // indirect
)
// ==============================
// Replace dependencies
// ==============================
replace (
github.com/old/dependency v1.2.3 => github.com/new/dependency v1.2.4
golang.org/x/oldnet => golang.org/x/net v0.11.0
)
// ==============================
// Exclude dependencies
// ==============================
exclude github.com/bad/dependency v1.0.0
// ==============================
// Indirect dependencies
// ==============================
require (
github.com/another/pkg v1.3.0 // indirect
)

59
samples/haskell.hs Normal file
View File

@@ -0,0 +1,59 @@
-- File: haskell.hs
{-# LANGUAGE GADTs, TypeFamilies #-}
module SyntaxTest where
import Data.List (sort)
import qualified Data.Map as Map
-- Simple data type
data Person = Person
{ name :: String
, age :: Int
} deriving (Show, Eq)
-- GADT
data Expr a where
I :: Int -> Expr Int
B :: Bool -> Expr Bool
Add :: Expr Int -> Expr Int -> Expr Int
Eq :: Expr Int -> Expr Int -> Expr Bool
-- Type class
class Describable a where
describe :: a -> String
instance Describable Person where
describe (Person n a) = n ++ " is " ++ show a ++ " years old."
-- Function with pattern matching
sumList :: [Int] -> Int
sumList [] = 0
sumList (x:xs) = x + sumList xs
-- Lambda and higher-order functions
applyTwice :: (a -> a) -> a -> a
applyTwice f x = f (f x)
-- Infix operator
infixl 6 +++
(+++) :: Int -> Int -> Int
a +++ b = a + b
-- IO function
main :: IO ()
main = do
let people = [Person "Alice" 30, Person "Bob" 25]
mapM_ (putStrLn . describe) people
print $ sumList [1..10]
print $ applyTwice (+1) 5
print $ 3 +++ 4
print $ Eq (I 2) (Add (I 1) (I 1))
-- Quasi-quote example
someExpr :: Expr Int
someExpr = [| Add (I 5) (I 7) |]
-- Comments and Haddocks
-- | This is a Haddock comment
-- explaining the module and functions

87
samples/html.html Normal file
View File

@@ -0,0 +1,87 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Injection Test</title>
<!-- Comment -->
<!-- Another comment with spellcheck -->
<!-- CSS block -->
<style>
body {
background-color: #f0f0f0;
}
h1 {
color: blue;
}
.highlight {
font-weight: bold;
}
</style>
<!-- CSS block with type attribute -->
<style type="text/css">
p {
color: green;
}
</style>
<!-- Script block -->
<script>
console.log("Hello, world!");
function greet(name) {
alert(`Hello, ${name}`);
}
</script>
<!-- Script with type="module" -->
<script type="module">
import { something } from "./module.js";
something();
</script>
<!-- Script with type="importmap" -->
<script type="importmap">
{
"imports": {
"lodash": "/node_modules/lodash-es/lodash\n.js",
"key": 2
}
}
</script>
<!-- Script with type attribute custom -->
<script type="text/javascript">
console.log("Custom type");
</script>
</head>
<body>
<h1>Main Heading</h1>
<h2>Subheading H2</h2>
<p style="color: red; font-weight: bold">
This paragraph has an inline style
</p>
<p>
This is <strong>strong text</strong>, <b>bold also</b>,
<em>italic text</em>, <i>emphasized</i>, <u>underlined</u>,
<s>strikethrough</s>, <del>deleted text</del>, <code>inline code</code>,
<kbd>keyboard input</kbd>.
</p>
<a href="https://hello.world"></a>
<!-- Lit-html / template interpolation -->
<button @click="${e => console.log(e)}">Click me</button>
<button @click="${e => console.log(e)}">Click me too</button>
<!-- Input pattern (regex) -->
<input type="text" pattern="[0-9]{3}" placeholder="Enter 3 digits" />
<!-- Event handlers -->
<button onclick="alert('Clicked!')">Event Handler</button>
<input onchange="console.log(this.value)" />
</body>
</html>

41
samples/ini.ini Normal file
View File

@@ -0,0 +1,41 @@
; =====================================================
; Sample INI Configuration
; =====================================================
[general]
app_name = MyApp
version = 1.2.3
debug = true
max_users = 100
[database]
host = localhost
port = 5432
user = admin
password = secret
timeout = 30
[paths]
log_dir = /var/log/myapp
data_dir = ./data
cache_dir = ./cache
[features]
enable_feature_x = true
enable_feature_y = false
feature_list = item1, item2, item3
[servers]
server1 = 192.168.1.10
server2 = 192.168.1.11
server3 = 192.168.1.12
; Nested sections (some parsers support this)
[servers.backup]
server1 = 192.168.2.10
server2 = 192.168.2.11
; Comments and special characters
; This is a comment line
; Values can also contain special characters like !@#$%^&*()
special_value = !@#$%^&*()_+|~=

147
samples/javascript.js Normal file
View File

@@ -0,0 +1,147 @@
/* ===============================
* JavaScript Syntax Torture Test
* =============================== */
'use strict';
// === Imports ===
import fs, { readFileSync as rfs } from "fs";
import * as path from "path";
import defaultExport, { named as alias } from "./module.js";
// === Constants ===
const PI = 3.141592653589793;
const HEX = 0xff;
const BIN = 0b101010;
const OCT = 0o755;
const BIG = 123_456_789n;
// === Variables ===
let x = null;
var y = undefined;
let z = NaN;
// === Strings ===
const s1 = "double quotes";
const s2 = 'single quotes';
const s3 = `template literal ${1 + 2}`;
const s4 = `multi
line
template`;
const s5 = String.raw`raw \n string`;
// === Escapes ===
const esc = "\n\t\r\b\f\\\"\'\u00A9\x41";
// === Arrays & Objects ===
const arr = [1, , 3, ...[4, 5], { a: 1, b: { c: 2 } }];
const obj = {
key: "value",
"weird-key": 123,
['dyn' + 'amic']: true,
method() {},
async asyncMethod() {},
*generator() { yield 1; },
};
// === Destructuring ===
const { a, b: renamed, ...rest } = obj;
const [x1, , x3 = 42] = arr;
// === Functions ===
function normal(a, b = 1, ...rest) {
return a + b + rest.length;
}
const arrow = (x = 0) => x * x;
const asyncArrow = async () => await Promise.resolve(42);
// === Classes ===
class Example extends Array {
static staticField = 123;
#privateField = "secret";
constructor(...args) {
super(...args);
}
get value() {
return this.#privateField;
}
set value(v) {
this.#privateField = v;
}
}
// === Control Flow ===
if (true && !false || null ?? true) {
console.log("truthy");
} else if (false) {
console.warn("nope");
} else {
console.error("never");
}
for (let i = 0; i < 3; i++) {
continue;
}
for (const k in obj) {}
for (const v of arr) {}
while (false) {}
do {} while (false);
switch (Math.random()) {
case 0:
break;
default:
break;
}
// === Try / Catch ===
try {
throw new Error("boom");
} catch (e) {
console.error(e?.message ?? "unknown");
} finally {
// cleanup
}
// === Regex ===
const regex1 = /foo|bar/i;
const regex2 = /^<script\b(?![^>]*\btype\s*=\s*"(?!module|text\/javascript)[^"]*")[^>]*>$/;
// === Tagged template ===
function tag(strings, ...values) {
return strings.raw.join("|") + values.join(",");
}
tag`hello ${42} world`;
// === Optional chaining / nullish ===
const deep = obj?.a?.b ?? "fallback";
// === Bitwise ===
const mask = (1 << 4) | (1 << 8);
// === JSON ===
const json = JSON.stringify({ a: 1, b: [true, false] }, null, 2);
// === Top-level await (if supported) ===
await Promise.resolve("done");
// === JSX-like (should still highlight interestingly) ===
const jsx = (
<Component prop="value">
<Child />
</Component>
);
// === End ===
export default {
PI,
arr,
obj,
Example,
};

51
samples/json.jsonc Normal file
View File

@@ -0,0 +1,51 @@
/* Example configuration file (JSONC)
// Used to test syntax highlighting and comment support
mutiline comment
*/
{
// Application metadata
"name": "example-app",
"version": "1.2.3",
"debug": true,
// Paths and environment
"paths": {
"root": "/usr/local/example",
"cache": "/tmp/example-cache
asa
multiline string",
"logs": null, // optional
},
// Feature flags
"features": {
"experimental": false,
"hotReload": true,
"themes": [
"dark",
"light",
// "solarized" // not ready yet
],
},
// Network configuration
"server": {
"host": "127.0.0.1",
"port": 8080,
"ssl": {
"enabled": false,
"cert": "",
"key": "",
}
},
// Mixed value types
"timeouts": [100, 250, 500, null],
"retryCount": 3,
// Escapes and strings
"banner": "Welcome!\nThis supports \"escaped quotes\" and unicode → ✓",
// Trailing comma allowed in JSONC
}

119
samples/lua.lua Normal file
View File

@@ -0,0 +1,119 @@
#!/usr/bin/env lua
-- Lua syntax highlighting test file
-- Constants
PI = 3.14159
MAX_COUNT = 100
-- Variables
local counter = 0
local name = "Lua"
-- Built-in variable
print(self)
-- Functions
function greet(user)
print("Hello, " .. user)
end
local function add(a, b)
return a + b
end
-- Method definitions
local obj = {}
function obj:sayHi()
print("Hi from method!")
end
obj.sayHello = function()
print("Hello from field function!")
end
-- Arrow-style anonymous function (LuaJIT/CFFI style)
local arrow = function(x)
return x * 2
end
-- Table constructors
local t = {
foo = 123,
bar = function()
return "bar"
end,
nested = {
a = 1,
b = 2,
},
}
-- Loops
for i = 1, MAX_COUNT do
counter = counter + i
end
while counter > 0 do
counter = counter - 1
end
repeat
counter = counter + 1
until counter == 10
-- Conditionals
if counter > 5 then
print("Big number")
elseif counter == 5 then
print("Exactly five")
else
print("Small number")
end
-- Operators
local x, y = 10, 20
local z = x + y * 2 - (x / y) ^ 2
local ok = x == y or x ~= y and not false
-- Function calls
greet("World")
obj:sayHi()
obj.sayHello()
add(5, 10)
-- Built-in function calls
assert(x > 0)
pcall(function()
print("safe")
end)
tonumber("123")
-- CFFI injection example
local ffi = require("ffi")
ffi.cdef([[
int printf(const char *fmt, ...);
typedef struct { int x; int y; } point;
]])
-- Boolean and nil
local flag = true
local nothing = nil
-- Comments
-- Single line
--[[
Multi-line
comment
]]
-- Strings
local s1 = "Hello\nWorld"
local s2 = [[Long
multi-line
string]]
-- Template strings (LuaJIT-style)
local tpl = `Value: ${counter}`
-- Regex-like string (for testing injection highlighting)
local re = "/^%a+$/"

41
samples/markdown.md Normal file
View File

@@ -0,0 +1,41 @@
# Heading 1
## Heading 2
### Heading 3
This is a paragraph with **bold text**, *italic text*, ~~strikethrough~~, and `inline code`.
> This is a blockquote.
>
> - Nested list item 1
> - Nested list item 2
> - Sub-item
- Task list:
- [ ] Unchecked task
- [x] Checked task
1. Numbered list item
2. Another item
---
| Name | Age | City |
|------------|-----|---------------|
| Alice | 25 | London |
| Bob | 30 | New York |
| Charlie | 22 | San Francisco |
[Link to OpenAI](https://openai.com)
`Inline code` example and a fenced code block:
```python
def hello_world():
print("Hello, world!")
```
![Image](https://example.com/image.jpg)
> "This is a quote with a link to [OpenAI](https://openai.com)."

87
samples/nginx.conf Normal file
View File

@@ -0,0 +1,87 @@
# ============================================================
# Global Settings
# ============================================================
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
# ============================================================
# Events Block
# ============================================================
events {
worker_connections 1024;
use epoll;
multi_accept on;
}
# ============================================================
# HTTP Block
# ============================================================
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Logging
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn;
# Gzip Settings
gzip on;
gzip_disable "msie6";
# ========================================================
# Upstream Backend Servers
# ========================================================
upstream backend {
server 127.0.0.1:8080 weight=5;
server 127.0.0.1:8081;
keepalive 32;
}
# ========================================================
# Server Block
# ========================================================
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
root /var/www/html;
index index.html index.htm;
# ====================================================
# Location Blocks
# ====================================================
location / {
try_files $uri $uri/ =404;
}
location /api/ {
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~* \.(gif|jpg|jpeg|png|css|js|ico|svg)$ {
expires 30d;
add_header Cache-Control "public, no-transform";
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
}
}

130
samples/php.php Normal file
View File

@@ -0,0 +1,130 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PHP Syntax Stress Test</title>
<style>
/* CSS section */
body {
font-family: Arial, sans-serif;
background: #1e1e1e;
color: #e0e0e0;
}
.box {
border: 1px solid #444;
padding: 10px;
margin: 10px;
}
</style>
<script>
// JS section
function greet(name) {
console.log("Hello " + name);
}
document.addEventListener("DOMContentLoaded", () => {
greet("World");
});
</script>
</head>
<body>
<?php
// Basic variables
$number = 42;
$text = "Hello PHP";
$truth = true;
$nothing = null;
// Constants
define("APP_NAME", "SyntaxTester");
// Arrays
$list = [1, 2, 3];
$assoc = [
"one" => 1,
"two" => 2
];
// Function
function add(int $a, int $b): int {
return $a + $b;
}
// Class + methods
class User {
private string $name;
public static int $count = 0;
public function __construct(string $name) {
$this->name = $name;
self::$count++;
}
public function greet(): string {
return "Hello {$this->name}";
}
}
// Object usage
$user = new User("Alice");
echo $user->greet();
// Control flow
if ($number > 10) {
echo "Big number";
} elseif ($number === 10) {
echo "Exactly ten";
} else {
echo "Small number";
}
// Loop
foreach ($list as $item) {
echo $item;
}
// Match expression
$result = match ($number) {
1 => "one",
2 => "two",
default => "many"
};
// Try / catch
try {
throw new Exception("Test exception");
} catch (Exception $e) {
echo $e->getMessage();
}
// Anonymous function
$double = fn($x) => $x * 2;
// Nullsafe operator
$len = $user?->name ? strlen($user->name) : 0;
// Ternary
$status = $truth ? "yes" : "no";
// Include / require
require_once "config.php";
// Output
echo "<div class='box'>";
echo htmlspecialchars($text);
echo "</div>";
?>
<script>
// JS interacting with PHP output
const phpValue = <?= json_encode($number) ?>;
console.log("Value from PHP:", phpValue);
</script>
</body>
</html>

163
samples/python.py Normal file
View File

@@ -0,0 +1,163 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Test file for Python Tree-sitter highlighting."""
# ==============================
# Constants / Builtins
# ==============================
PI = 3.14159
MAX_SIZE = 100
NotImplemented
Ellipsis
__name__ # builtin constant
# ==============================
# Imports
# ==============================
import os
import sys as system
from re import compile as re_compile
from __future__ import annotations
from math import *
# ==============================
# Functions
# ==============================
def add(a: int, b: int = 5) -> int:
"""Simple add function"""
return a + b
def variadic(*args, **kwargs):
print(args, kwargs)
lambda_func = lambda x, y=2: x * y
def type_var_example(T: type):
pass
# ==============================
# Classes
# ==============================
class Base:
class_var = 10
def __init__(self, name: str):
self.name = name
self._private = 42
@classmethod
def cls_method(cls):
return cls.class_var
@staticmethod
def static_method():
return "static"
@property
def prop(self):
return self.name
class Derived(Base):
def __init__(self, name, extra):
super().__init__(name)
self.extra = extra
# ==============================
# Variables
# ==============================
normal_var = 1
_local_var = 2
GLOBAL_VAR = 3
# Builtin variable references
self = "something"
cls = "class"
# ==============================
# Control flow
# ==============================
if True:
x = 10
elif False:
x = 20
else:
x = 0
for i in range(3):
print(i)
while x > 0:
x -= 1
if x == 1:
break
else:
continue
try:
1 / 0
except ZeroDivisionError as e:
raise
finally:
pass
# ==============================
# Operators
# ==============================
a, b = 5, 10
c = a + b * 2 // 3 % 4 ** 2
d = (a << 2) & b | c ^ ~a
e = not a or b and c
# ==============================
# f-strings / interpolation
# ==============================
name = "Alice"
greeting = f"Hello {name.upper()}!"
formatted = f"{a + b} is sum"
# ==============================
# Regex
# ==============================
pattern1 = re_compile(r"\d+")
pattern2 = re_compile(r"\w{2,}")
# ==============================
# Decorators usage
# ==============================
@staticmethod
def static_func():
return True
@classmethod
def cls_func(cls):
return cls
@custom_decorator
def decorated_func():
return None
# ==============================
# Misc / Type conversions / literals
# ==============================
flag: bool = True
nothing: None = None
num: float = float("3.14")
text: str = str(123)
lst = [1, 2, 3]
tpl = (4, 5)
dct = {"a": 1, "b": 2}
# ==============================
# Type hints / TypeVar / TypeAlias
# ==============================
from typing import TypeVar, NewType
T = TypeVar("T")
UserId = NewType("UserId", int)
TypeAliasExample: type = int
# ==============================
# Function calls / constructors
# ==============================
result = add(1, 2)
obj = Derived("Alice", "extra")
variadic(1, 2, 3, key="value")
instance_check = isinstance(obj, Base)

18
samples/regex.regex Normal file
View File

@@ -0,0 +1,18 @@
# Match email addresses with optional names
(?P<name>[a-zA-Z0-9._%+-]+)?\s*<(?P<email>[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})>
# Match dates in YYYY-MM-DD or DD/MM/YYYY
(\d{4}-\d{2}-\d{2})|(\d{2}/\d{2}/\d{4})
# Match hexadecimal colors
# e.g., #FFF, #FFFFFF
# Optional leading #
# Case-insensitive
# Flags inline
(?i)#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})
# Match words starting with vowels
\b[aeiouAEIOU]\w*\b
# Match simple URL
https?://(?:www\.)?\w+\.\w+(?:/\S*)?

406
samples/rust.rs Normal file
View File

@@ -0,0 +1,406 @@
#![allow(dead_code)]
use std::collections::{BTreeMap, HashMap};
use std::fmt;
use std::time::Duration;
//! Examples to exercise the Rust regex injection queries in the highlights.scm.
//! These cover Regex::new, regex::Regex::new, regex::bytes::Regex::new,
//! RegexSet::new, regex::RegexSet::new, RegexSetBuilder::new, and byte variants.
//!
//! Injection patterns in the query file trigger on:
//! - call to (Regex|ByteRegexBuilder)::new with a raw string literal
//! - call to (RegexSet|RegexSetBuilder)::new with an array of raw string literals
use regex::{Regex, RegexSet, RegexSetBuilder};
use regex::bytes::Regex as ByteRegex;
use regex::bytes::RegexSet as ByteRegexSet;
use regex::bytes::RegexSetBuilder as ByteRegexSetBuilder;
fn main() {
// --- Should inject (Regex::new with raw string) ---
let _simple = Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
// --- Should inject (fully qualified regex::Regex::new with raw string) ---
let _fq = regex::Regex::new(r"(?m)^\w+\s*=\s*.+$").unwrap();
// --- Should inject (bytes::Regex::new with raw string) ---
let _bytes = ByteRegex::new(r"(?-u)\xFF[\x00-\x7F]+").unwrap();
// --- Should inject (RegexSet::new with array of raw strings) ---
let _set = RegexSet::new([
r"^INFO:",
r"^WARN:",
r"^ERROR:",
]).unwrap();
// --- Should inject (regex::RegexSet::new fully qualified) ---
let _set_fq = regex::RegexSet::new([
r"foo\d+",
r"bar\d+",
]).unwrap();
// --- Should inject (RegexSetBuilder::new with array of raw strings) ---
let _set_builder = RegexSetBuilder::new([
r"\bcat\b",
r"\bdog\b",
])
.case_insensitive(true)
.build()
.unwrap();
// --- Should inject (bytes set builder) ---
let _byte_set_builder = ByteRegexSetBuilder::new([
r"(?-u)\x01\x02",
r"(?-u)\xFF.+",
])
.build()
.unwrap();
// --- Should inject (bytes set) ---
let _byte_set = ByteRegexSet::new([
r"(?-u)\x00+\xFF",
r"(?-u)[\x10-\x20]+",
]).unwrap();
// --- NEGATIVE examples (should NOT inject) ---
// Not raw string literal (plain string): the query expects raw_string_literal.
let _no_inject_plain = Regex::new("plain-string-no-raw").unwrap();
// Function name is not `new`, so should not inject.
let _builder = Regex::new(r"\d+").map(|re| re.replace("123", "x"));
// Different type name, should not inject.
let _other = Some(r"not a regex call");
// Raw string but different function, should not inject.
let _format = format!(r"literal: {}", 42);
}
// Keep a simple test to ensure this compiles and runs.
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn smoke() {
let re = Regex::new(r"^\d+$").unwrap();
assert!(re.is_match("12345"));
let set = RegexSet::new([r"cat", r"dog"]).unwrap();
assert!(set.is_match("hotdog"));
}
}
/// A simple data type to exercise traits, pattern matching, and methods.
#[derive(Debug, Clone, PartialEq)]
pub struct Point {
pub x: i64,
pub y: i64,
}
impl Point {
pub fn manhattan(&self) -> i64 {
self.x.abs() + self.y.abs()
}
pub fn translate(&self, dx: i64, dy: i64) -> Self {
Self {
x: self.x + dx,
y: self.y + dy,
}
}
}
impl fmt::Display for Point {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({}, {})", self.x, self.y)
}
}
#[derive(Debug, PartialEq, Eq)]
pub enum ParseError {
Empty,
InvalidDigit,
TooLarge,
}
pub fn parse_u8(input: &str) -> Result<u8, ParseError> {
if input.trim().is_empty() {
return Err(ParseError::Empty);
}
let mut value: u16 = 0;
for ch in input.bytes() {
if !(b'0'..=b'9').contains(&ch) {
return Err(ParseError::InvalidDigit);
}
value = value * 10 + u16::from(ch - b'0');
if value > u8::MAX as u16 {
return Err(ParseError::TooLarge);
}
}
Ok(value as u8)
}
pub fn sum_iter<I: IntoIterator<Item = i64>>(iter: I) -> i64 {
iter.into_iter().fold(0, |acc, n| acc + n)
}
pub fn split_once<'a>(input: &'a str, needle: char) -> Option<(&'a str, &'a str)> {
let idx = input.find(needle)?;
Some((&input[..idx], &input[idx + needle.len_utf8()..]))
}
pub fn join_with<I: IntoIterator<Item = String>>(iter: I, sep: &str) -> String {
let mut it = iter.into_iter().peekable();
let mut out = String::new();
while let Some(item) = it.next() {
out.push_str(&item);
if it.peek().is_some() {
out.push_str(sep);
}
}
out
}
#[cfg(test)]
mod tests {
use super::*;
use std::cell::RefCell;
use std::sync::mpsc;
use std::thread;
macro_rules! assert_contains {
($haystack:expr, $needle:expr) => {
if !$haystack.contains($needle) {
panic!("expected {:?} to contain {:?}", $haystack, $needle);
}
};
}
#[test]
fn point_manhattan_and_display() {
let p = Point { x: -3, y: 4 };
assert_eq!(p.manhattan(), 7);
assert_eq!(p.to_string(), "(-3, 4)");
}
#[test]
fn point_translate_is_pure() {
let p = Point { x: 1, y: 2 };
let q = p.translate(3, -1);
assert_eq!(p, Point { x: 1, y: 2 });
assert_eq!(q, Point { x: 4, y: 1 });
}
#[test]
fn parse_u8_success_and_errors() {
assert_eq!(parse_u8("0"), Ok(0));
assert_eq!(parse_u8("255"), Ok(255));
assert_eq!(parse_u8(" 17 "), Ok(17)); // leading/trailing spaces are rejected as Empty? we trimmed only emptiness, digits still parsed.
assert_eq!(parse_u8(""), Err(ParseError::Empty));
assert_eq!(parse_u8(" "), Err(ParseError::Empty));
assert_eq!(parse_u8("12a"), Err(ParseError::InvalidDigit));
assert_eq!(parse_u8("256"), Err(ParseError::TooLarge));
}
#[test]
fn sum_iter_works_for_various_iterators() {
let v = vec![1, 2, 3, 4, -5];
assert_eq!(sum_iter(&v), 5);
let arr = [10i64; 4];
assert_eq!(sum_iter(arr), 40);
assert_eq!(sum_iter(0..5), 10);
}
#[test]
fn split_once_basic_and_unicode() {
assert_eq!(split_once("a,b,c", ','), Some(("a", "b,c")));
assert_eq!(split_once("no-sep", '/'), None);
// UTF-8 needle
let s = "fooλbar";
assert_eq!(split_once(s, 'λ'), Some(("foo", "bar")));
}
#[test]
fn join_with_various_lengths() {
let empty: Vec<String> = vec![];
assert_eq!(join_with(empty, ", "), "");
assert_eq!(join_with(vec!["a".into()], ", "), "a");
assert_eq!(
join_with(vec!["a".into(), "b".into(), "c".into()], "|"),
"a|b|c"
);
}
#[test]
fn hash_map_grouping_example() {
let words = ["ant", "bat", "apple", "boat"];
let mut by_initial: HashMap<char, Vec<&str>> = HashMap::new();
for w in &words {
let key = w.chars().next().unwrap();
by_initial.entry(key).or_default().push(*w);
}
assert_eq!(by_initial.get(&'a').unwrap(), &vec!["ant", "apple"]);
assert_eq!(by_initial.get(&'b').unwrap(), &vec!["bat", "boat"]);
}
#[test]
fn btree_map_sorted_iteration() {
let mut map = BTreeMap::new();
map.insert("c", 3);
map.insert("a", 1);
map.insert("b", 2);
let keys: Vec<_> = map.keys().copied().collect();
assert_eq!(keys, vec!["a", "b", "c"]);
}
#[test]
fn channels_and_threads() {
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
for i in 0..5 {
tx.send(i * i).unwrap();
}
});
let received: Vec<_> = (0..5).map(|_| rx.recv().unwrap()).collect();
assert_eq!(received, vec![0, 1, 4, 9, 16]);
}
#[test]
fn interior_mutability_with_refcell() {
#[derive(Debug)]
struct Counter {
inner: RefCell<u32>,
}
impl Counter {
fn inc(&self) {
*self.inner.borrow_mut() += 1;
}
fn get(&self) -> u32 {
*self.inner.borrow()
}
}
let c = Counter {
inner: RefCell::new(0),
};
c.inc();
c.inc();
assert_eq!(c.get(), 2);
}
#[test]
fn should_panic_on_too_large_parse() {
#[should_panic(expected = "TooLarge")]
fn check() {
parse_u8("999").unwrap();
}
check();
}
#[test]
fn result_based_test() -> Result<(), String> {
let p = Point { x: 2, y: 3 };
if p.manhattan() == 5 {
Ok(())
} else {
Err("manhattan distance mismatch".into())
}
}
#[test]
fn iterator_combinators_cover_common_paths() {
let data = vec![Some(1), None, Some(3), Some(4)];
let sum: i32 = data.iter().flatten().sum();
assert_eq!(sum, 8);
let doubled: Vec<_> = (1..=5).map(|n| n * 2).filter(|n| n % 4 == 0).collect();
assert_eq!(doubled, vec![4, 8]);
}
#[test]
fn pattern_matching_with_guards() {
let numbers = [-2, -1, 0, 1, 2];
let labels: Vec<_> = numbers
.iter()
.map(|n| match n {
n if *n < 0 => "neg",
0 => "zero",
n if *n % 2 == 0 => "even-pos",
_ => "odd-pos",
})
.collect();
assert_eq!(labels, vec!["neg", "neg", "zero", "odd-pos", "even-pos"]);
}
#[test]
fn custom_macro_assert_contains() {
assert_contains!("hello world", "world");
}
#[test]
fn ownership_and_borrowing_examples() {
fn takes_and_gives_back(mut v: Vec<i32>) -> Vec<i32> {
v.push(42);
v
}
let v = vec![1, 2, 3];
let v = takes_and_gives_back(v);
assert_eq!(v, vec![1, 2, 3, 42]);
let s = String::from("hi");
let len = length_of_str(&s);
assert_eq!(len, 2);
}
fn length_of_str(s: &str) -> usize {
s.len()
}
#[test]
fn lifetimes_and_slices() {
fn first<'a>(xs: &'a [i32]) -> Option<&'a i32> {
xs.first()
}
let data = [10, 20, 30];
assert_eq!(first(&data), Some(&10));
}
#[test]
fn const_generics_array_sum() {
fn sum_array<const N: usize>(arr: [i32; N]) -> i32 {
arr.iter().sum()
}
assert_eq!(sum_array::<3>([1, 2, 3]), 6);
assert_eq!(sum_array([0; 5]), 0);
}
#[test]
fn duration_and_instant_arithmetic() {
use std::time::Instant;
let start = Instant::now();
std::thread::sleep(Duration::from_millis(5));
let elapsed = start.elapsed();
assert!(elapsed >= Duration::from_millis(5));
}
#[test]
fn string_builder_patterns() {
let parts = ["a", "b", "c"];
let mut s = String::with_capacity(3);
for p in parts {
s.push_str(p);
}
assert_eq!(s, "abc");
assert!(s.capacity() >= 3);
}
#[test]
fn equality_and_ordering_on_point() {
let p1 = Point { x: 1, y: 2 };
let p2 = Point { x: 1, y: 2 };
assert_eq!(p1, p2);
assert!(p1.manhattan() <= p2.manhattan());
}
}

View File

@@ -0,0 +1,5 @@
# Sample .gitattributes file for syntax highlighting tests
*.c syntax=c
*.h syntax=c
*.py syntax=python

12
samples/sample.gitignore Normal file
View File

@@ -0,0 +1,12 @@
# Test gitignore file (to check syntax)
*
./!
*.log
!.gitignore[2]
**/*.lo[s]g
### Comment

83
samples/sql.sql Normal file
View File

@@ -0,0 +1,83 @@
-- Sample SQL to exercise the highlight rules
-- DDL
CREATE TEMPORARY TABLE IF NOT EXISTS public.users (
user_id BIGSERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
profile JSONB,
balance DECIMAL(12,2) DEFAULT 0.00,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ,
CONSTRAINT email_chk CHECK (email LIKE '%@%')
);
-- Indexes
CREATE INDEX CONCURRENTLY IF NOT EXISTS users_email_idx ON public.users USING btree (email);
CREATE INDEX IF NOT EXISTS users_profile_gin_idx ON public.users USING gin (profile);
-- Insert & returning
INSERT INTO public.users (email, profile, balance)
VALUES
('alice@example.com', '{"plan":"pro","tags":["a","b"]}'::jsonb, 25.50),
('bob@example.com', '{"plan":"free","tags":["c"]}'::jsonb, 0.00)
RETURNING user_id, email, profile;
-- Update with CASE and CAST
UPDATE public.users u
SET balance = balance + CAST(5 AS DECIMAL),
updated_at = CURRENT_TIMESTAMP,
profile = jsonb_set(profile, '{last_seen}', to_jsonb(CURRENT_TIMESTAMP)),
email = CASE
WHEN email LIKE '%@example.com' THEN replace(email, '@example.com', '@example.org')
ELSE email
END
WHERE u.balance >= 0
RETURNING user_id, email, balance;
-- Delete with USING
DELETE FROM public.users AS u
USING public.users AS t
WHERE u.user_id = t.user_id
AND u.email LIKE 'bob@%';
-- Window, CTE, aggregates
WITH recent AS (
SELECT *
FROM public.users
WHERE created_at > NOW() - INTERVAL '30 days'
)
SELECT
user_id,
email,
balance,
SUM(balance) OVER (PARTITION BY 1 ORDER BY created_at ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_total,
ROW_NUMBER() OVER (ORDER BY created_at DESC) AS rn
FROM recent
ORDER BY created_at DESC
LIMIT 50 OFFSET 0;
-- Joins and JSON
CREATE TEMP TABLE events (
event_id BIGSERIAL PRIMARY KEY,
user_id BIGINT REFERENCES public.users(user_id),
payload JSONB,
created_at TIMESTAMPTZ DEFAULT NOW()
);
INSERT INTO events (user_id, payload) VALUES
(1, '{"type":"login","ip":"127.0.0.1"}'),
(1, '{"type":"purchase","amount":9.99,"items":[{"sku":"A1","qty":1}]}' ),
(2, '{"type":"login","ip":"10.0.0.2"}');
SELECT u.email, e.payload->>'type' AS event_type, e.payload
FROM public.users u
LEFT JOIN events e ON e.user_id = u.user_id
WHERE e.payload ? 'type'
ORDER BY e.created_at DESC;
-- Transaction control
BEGIN;
UPDATE public.users SET balance = balance - 5 WHERE email LIKE 'alice%';
INSERT INTO events (user_id, payload)
SELECT user_id, jsonb_build_object('type','adjust','delta',-5) FROM public.users WHERE email LIKE 'alice%';
COMMIT;

53
samples/toml.toml Normal file
View File

@@ -0,0 +1,53 @@
# ============================================================
# Basic types
# ============================================================
title = "Example TOML Configuration"
enabled = true
count = 42
pi = 3.14159
empty = ""
# ============================================================
# Arrays
# ============================================================
fruits = ["apple", "banana", "cherry"]
numbers = [1, 2, 3, 4, 5]
# Nested array
matrix = [[1, 2], [3, 4]]
# ============================================================
# Tables
# ============================================================
[owner]
name = "Alice"
dob = 1979-05-27T07:32:00Z
[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]
connection_max = 5000
enabled = true
[servers.alpha]
ip = "10.0.0.1"
dc = "east"
[servers.beta]
ip = "10.0.0.2"
dc = "west"
# ============================================================
# Inline tables
# ============================================================
clients = { name = "Bob", age = 30, active = true }
# ============================================================
# Multiline strings
# ============================================================
description = """
This is a TOML file
used for testing syntax highlighting.
It supports multiple lines.
"""