Skip to content

Commit ae8e7eb

Browse files
committed
Remove SQL line comment pattern and add test cases
Deleted the pattern for SQL line comments from the grammar file to adjust syntax highlighting. Added a comprehensive test-sql-syntax.json file with various SQL queries and edge cases for testing. Updated preview.webp, likely to reflect changes in syntax highlighting.
1 parent 17b4a14 commit ae8e7eb

3 files changed

Lines changed: 54 additions & 4 deletions

File tree

preview.webp

22.5 KB
Loading

syntaxes/sql-in-json.tmLanguage.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@
7979
"name": "storage.type.sql",
8080
"match": "/\\*[\\s\\S]*?\\*/"
8181
},
82-
{
83-
"name": "storage.modifier.sql",
84-
"match": "(^|\\s)--.*$"
85-
},
8682
{
8783
"name": "keyword.control",
8884
"match": "(?i)(\\b|^)(SELECT|FROM|WHERE|GROUP\\s+BY|ORDER\\s+BY|HAVING|LIMIT|OFFSET|UNION|UNION\\s+ALL|INTERSECT|EXCEPT|DISTINCT|ALL)\\b"

test-sql-syntax.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"test_queries": {
3+
"basic_select": "SELECT * FROM users WHERE id = 1",
4+
"complex_query": "SELECT u.name, p.title FROM users u INNER JOIN posts p ON u.id = p.user_id WHERE u.active = 1 AND p.published = 'true'",
5+
"with_functions": "SELECT COUNT(*), AVG(price), MAX(created_at), MIN(updated_at) FROM products WHERE category = 'electronics'",
6+
"case_statement": "SELECT CASE WHEN age <= 25 THEN 'young' WHEN age <= 50 THEN 'middle' ELSE 'senior' END as age_group FROM users",
7+
"string_functions": "SELECT UPPER(name), LOWER(email), LENGTH(description), SUBSTR(phone, 1, 3) FROM contacts",
8+
"date_functions": "SELECT CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, DATETIME('now'), DATE('2023-01-01') FROM events",
9+
"with_comments": "SELECT * FROM users -- This is a line comment WHERE id = 1 /* This is a block comment with multiple lines that should be highlighted properly */",
10+
"nested_comments": "SELECT * FROM users /* Outer comment with -- inner line comment */ WHERE id = 1",
11+
"operators": "SELECT * FROM products WHERE price >= 100 AND price <= 500 OR category = 'electronics' AND stock > 0",
12+
"comparison_operators": "SELECT * FROM data WHERE value = 10 AND value <> 20 AND value < 30 AND value > 5 AND value <= 25 AND value >= 15",
13+
"like_patterns": "SELECT * FROM products WHERE name LIKE '%phone%' AND description GLOB '*.jpg' AND code REGEXP '^[A-Z]{2}[0-9]{4}$'",
14+
"in_operators": "SELECT * FROM users WHERE status IN ('active', 'pending', 'verified') AND id NOT IN (1, 2, 3)",
15+
"between_operators": "SELECT * FROM orders WHERE order_date BETWEEN '2023-01-01' AND '2023-12-31' AND amount BETWEEN 100 AND 1000",
16+
"exists_operators": "SELECT * FROM users u WHERE EXISTS (SELECT 1 FROM orders o WHERE o.user_id = u.id) AND NOT EXISTS (SELECT 1 FROM bans b WHERE b.user_id = u.id)",
17+
"null_checks": "SELECT * FROM products WHERE description IS NOT NULL AND category IS NULL AND price IS NOT NULL",
18+
"aggregate_functions": "SELECT category, COUNT(*) as count, SUM(price) as total, AVG(price) as average, MIN(price) as min_price, MAX(price) as max_price FROM products GROUP BY category HAVING COUNT(*) > 5",
19+
"window_functions": "SELECT name, salary, ROW_NUMBER() OVER (ORDER BY salary DESC) as rank, RANK() OVER (ORDER BY salary DESC) as salary_rank FROM employees",
20+
"subqueries": "SELECT * FROM users WHERE id IN (SELECT user_id FROM orders WHERE total > 1000) AND created_at > (SELECT MAX(created_at) FROM users WHERE status = 'inactive')",
21+
"unions": "SELECT name, 'user' as type FROM users UNION ALL SELECT title, 'product' as type FROM products UNION SELECT description, 'category' as type FROM categories",
22+
"joins": "SELECT u.name, p.title, c.name as category FROM users u LEFT JOIN posts p ON u.id = p.user_id RIGHT JOIN categories c ON p.category_id = c.id FULL OUTER JOIN tags t ON p.id = t.post_id",
23+
"with_variables": "SELECT * FROM products WHERE id = <IDM> AND category = '<CATEGORY>' AND status = '<STATUS>'",
24+
"string_literals": "SELECT * FROM products WHERE name = 'iPhone 15' AND description = 'Latest smartphone' AND code = 'IPH15'",
25+
"numeric_literals": "SELECT * FROM products WHERE price = 999.99 AND quantity = 100 AND discount = 0.15 AND rating = 4.5",
26+
"boolean_literals": "SELECT * FROM products WHERE active = true AND featured = false AND available = 1 AND discontinued = 0",
27+
"array_access": "SELECT * FROM products WHERE tags[0] = 'electronics' AND features[1] = 'wireless' AND specs['color'] = 'black'",
28+
"json_functions": "SELECT JSON_EXTRACT(data, '$.name') as name, JSON_OBJECT('id', id, 'name', name) as json_obj FROM products",
29+
"regex_functions": "SELECT * FROM products WHERE name REGEXP '^[A-Z][a-z]+ [0-9]+$' AND description MATCH 'phone|mobile|smart'",
30+
"math_functions": "SELECT ROUND(price, 2) as rounded_price, ABS(discount) as abs_discount, RANDOM() as random_num FROM products",
31+
"text_functions": "SELECT TRIM(name) as trimmed_name, LTRIM(description) as left_trimmed, RTRIM(code) as right_trimmed FROM products",
32+
"type_conversion": "SELECT CAST(price AS TEXT) as price_text, TYPEOF(created_at) as date_type FROM products",
33+
"conditional_functions": "SELECT IFNULL(description, 'No description') as desc, COALESCE(alt_name, name, 'Unknown') as display_name FROM products",
34+
"complex_nested": "SELECT CASE WHEN (CASE WHEN IfNull(ComplementoAplicacao3_1, '') IN ('','-','...','TODOS', '>', '<') THEN 1960 ELSE ComplementoAplicacao3_1 END) <= 25 THEN '20' ELSE '19' END || substr((CASE WHEN IfNull(ComplementoAplicacao3_1, '') IN ('','-','...','TODOS', '>', '<') THEN 1960 ELSE ComplementoAplicacao3_1 END), length((CASE WHEN IfNull(ComplementoAplicacao3_1, '') IN ('','-','...','TODOS', '>', '<') THEN 1960 ELSE ComplementoAplicacao3_1 END))-1)) FROM applications",
35+
"mixed_content": "SELECT u.name, p.title, 'Active' as status FROM users u JOIN posts p ON u.id = p.user_id WHERE u.active = 1 /* User is active */ AND p.published = 'true' -- Post is published",
36+
"special_characters": "SELECT * FROM data WHERE value = 'test@example.com' AND code = 'ABC-123' AND path = '/home/user/file.txt'",
37+
"empty_strings": "SELECT * FROM products WHERE name = '' AND description = '' AND code = ''",
38+
"null_values": "SELECT * FROM products WHERE name IS NULL AND description IS NOT NULL AND price IS NULL",
39+
"escaped_strings": "SELECT * FROM products WHERE description = 'Product with \"quotes\" and \\'apostrophes\\'' AND name = 'Product with \\n newline'",
40+
"unicode_strings": "SELECT * FROM products WHERE name = 'Café' AND description = 'Produit français' AND title = '产品名称'"
41+
},
42+
"edge_cases": {
43+
"empty_query": "",
44+
"single_word": "SELECT",
45+
"just_comment": "-- This is just a comment",
46+
"just_block_comment": "/* This is just a block comment */",
47+
"unclosed_comment": "/* This comment is not closed",
48+
"unclosed_string": "SELECT * FROM users WHERE name = 'unclosed string",
49+
"nested_quotes": "SELECT * FROM users WHERE description = 'User with \"nested quotes\" and \\'apostrophes\\''",
50+
"special_operators": "SELECT * FROM data WHERE value = 10 AND value != 20 AND value <> 30 AND value <= 25 AND value >= 15",
51+
"regex_patterns": "SELECT * FROM products WHERE name REGEXP '^[A-Z][a-z]+ [0-9]+$' AND code MATCH '^[A-Z]{2}[0-9]{4}$'",
52+
"math_expressions": "SELECT (price * 1.1) as price_with_tax, (quantity - reserved) as available, (rating * 100) as percentage FROM products"
53+
}
54+
}

0 commit comments

Comments
 (0)