1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-02-03 13:01:47 +02:00

fix(ocaml): support multistring (#1035)

This commit is contained in:
Gusted 2025-01-07 05:49:25 +01:00 committed by GitHub
parent e79c813a78
commit d82957931f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 77 additions and 0 deletions

View File

@ -41,6 +41,14 @@
<rule pattern="\b(as|assert|begin|class|constraint|do|done|downto|else|end|exception|external|false|for|fun|function|functor|if|in|include|inherit|initializer|lazy|let|match|method|module|mutable|new|object|of|open|private|raise|rec|sig|struct|then|to|true|try|type|value|val|virtual|when|while|with)\b">
<token type="Keyword"/>
</rule>
<rule pattern="({([a-z_]*)\|)([\s\S]+?)(?=\|\2})(\|\2})">
<bygroups>
<token type="LiteralStringAffix"/>
<token type="Ignore"/>
<token type="LiteralString"/>
<token type="LiteralStringAffix"/>
</bygroups>
</rule>
<rule pattern="(~|\}|\|]|\||\{&lt;|\{|`|_|]|\[\||\[&gt;|\[&lt;|\[|\?\?|\?|&gt;\}|&gt;]|&gt;|=|&lt;-|&lt;|;;|;|:&gt;|:=|::|:|\.\.|\.|-&gt;|-\.|-|,|\+|\*|\)|\(|&amp;&amp;|&amp;|#|!=)">
<token type="Operator"/>
</rule>

27
lexers/testdata/ocaml.actual vendored Normal file
View File

@ -0,0 +1,27 @@
let create_user =
(unit ->. unit)
@@ {eos|
CREATE TABLE IF NOT EXISTS user (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL CHECK (LENGTH(name) <= 256),
password_hash TEXT NOT NULL,
created_unix INTEGER NOT NULL DEFAULT (unixepoch()),
UNIQUE (name COLLATE NOCASE)
) STRICT
|eos}
let create_group =
(unit ->. unit)
@@ {|
CREATE TABLE IF NOT EXISTS `group` (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL CHECK (LENGTH(name) <= 256),
description TEXT CHECK (description IS NULL OR LENGTH(description) <= 1024),
user_id INTEGER NOT NULL, -- Controls the group
created_unix INTEGER NOT NULL DEFAULT (unixepoch()),
FOREIGN KEY (user_id) REFERENCES user(id),
UNIQUE (name COLLATE NOCASE)
) STRICT
|}

42
lexers/testdata/ocaml.expected vendored Normal file
View File

@ -0,0 +1,42 @@
[
{"type":"Keyword","value":"let"},
{"type":"Text","value":" "},
{"type":"Name","value":"create_user"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":"\n "},
{"type":"Operator","value":"("},
{"type":"KeywordType","value":"unit"},
{"type":"Text","value":" "},
{"type":"Operator","value":"-\u003e."},
{"type":"Text","value":" "},
{"type":"KeywordType","value":"unit"},
{"type":"Operator","value":")"},
{"type":"Text","value":"\n "},
{"type":"Operator","value":"@@"},
{"type":"Text","value":" "},
{"type":"LiteralStringAffix","value":"{eos|"},
{"type":"LiteralString","value":"\n CREATE TABLE IF NOT EXISTS user (\n id INTEGER PRIMARY KEY,\n name TEXT NOT NULL CHECK (LENGTH(name) \u003c= 256),\n password_hash TEXT NOT NULL,\n created_unix INTEGER NOT NULL DEFAULT (unixepoch()),\n\n UNIQUE (name COLLATE NOCASE)\n ) STRICT\n "},
{"type":"LiteralStringAffix","value":"|eos}"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"let"},
{"type":"Text","value":" "},
{"type":"Name","value":"create_group"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":"\n "},
{"type":"Operator","value":"("},
{"type":"KeywordType","value":"unit"},
{"type":"Text","value":" "},
{"type":"Operator","value":"-\u003e."},
{"type":"Text","value":" "},
{"type":"KeywordType","value":"unit"},
{"type":"Operator","value":")"},
{"type":"Text","value":"\n "},
{"type":"Operator","value":"@@"},
{"type":"Text","value":" "},
{"type":"LiteralStringAffix","value":"{|"},
{"type":"LiteralString","value":"\n CREATE TABLE IF NOT EXISTS `group` (\n id INTEGER PRIMARY KEY,\n name TEXT NOT NULL CHECK (LENGTH(name) \u003c= 256),\n description TEXT CHECK (description IS NULL OR LENGTH(description) \u003c= 1024),\n user_id INTEGER NOT NULL, -- Controls the group\n created_unix INTEGER NOT NULL DEFAULT (unixepoch()),\n\n FOREIGN KEY (user_id) REFERENCES user(id),\n UNIQUE (name COLLATE NOCASE)\n ) STRICT\n "},
{"type":"LiteralStringAffix","value":"|}"},
{"type":"Text","value":"\n"}
]