Skip to content

Commit d829579

Browse files
authored
fix(ocaml): support multistring (#1035)
1 parent e79c813 commit d829579

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

lexers/embedded/ocaml.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
<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">
4242
<token type="Keyword"/>
4343
</rule>
44+
<rule pattern="({([a-z_]*)\|)([\s\S]+?)(?=\|\2})(\|\2})">
45+
<bygroups>
46+
<token type="LiteralStringAffix"/>
47+
<token type="Ignore"/>
48+
<token type="LiteralString"/>
49+
<token type="LiteralStringAffix"/>
50+
</bygroups>
51+
</rule>
4452
<rule pattern="(~|\}|\|]|\||\{&lt;|\{|`|_|]|\[\||\[&gt;|\[&lt;|\[|\?\?|\?|&gt;\}|&gt;]|&gt;|=|&lt;-|&lt;|;;|;|:&gt;|:=|::|:|\.\.|\.|-&gt;|-\.|-|,|\+|\*|\)|\(|&amp;&amp;|&amp;|#|!=)">
4553
<token type="Operator"/>
4654
</rule>

lexers/testdata/ocaml.actual

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
let create_user =
2+
(unit ->. unit)
3+
@@ {eos|
4+
CREATE TABLE IF NOT EXISTS user (
5+
id INTEGER PRIMARY KEY,
6+
name TEXT NOT NULL CHECK (LENGTH(name) <= 256),
7+
password_hash TEXT NOT NULL,
8+
created_unix INTEGER NOT NULL DEFAULT (unixepoch()),
9+
10+
UNIQUE (name COLLATE NOCASE)
11+
) STRICT
12+
|eos}
13+
14+
let create_group =
15+
(unit ->. unit)
16+
@@ {|
17+
CREATE TABLE IF NOT EXISTS `group` (
18+
id INTEGER PRIMARY KEY,
19+
name TEXT NOT NULL CHECK (LENGTH(name) <= 256),
20+
description TEXT CHECK (description IS NULL OR LENGTH(description) <= 1024),
21+
user_id INTEGER NOT NULL, -- Controls the group
22+
created_unix INTEGER NOT NULL DEFAULT (unixepoch()),
23+
24+
FOREIGN KEY (user_id) REFERENCES user(id),
25+
UNIQUE (name COLLATE NOCASE)
26+
) STRICT
27+
|}

lexers/testdata/ocaml.expected

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{"type":"Keyword","value":"let"},
3+
{"type":"Text","value":" "},
4+
{"type":"Name","value":"create_user"},
5+
{"type":"Text","value":" "},
6+
{"type":"Operator","value":"="},
7+
{"type":"Text","value":"\n "},
8+
{"type":"Operator","value":"("},
9+
{"type":"KeywordType","value":"unit"},
10+
{"type":"Text","value":" "},
11+
{"type":"Operator","value":"-\u003e."},
12+
{"type":"Text","value":" "},
13+
{"type":"KeywordType","value":"unit"},
14+
{"type":"Operator","value":")"},
15+
{"type":"Text","value":"\n "},
16+
{"type":"Operator","value":"@@"},
17+
{"type":"Text","value":" "},
18+
{"type":"LiteralStringAffix","value":"{eos|"},
19+
{"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 "},
20+
{"type":"LiteralStringAffix","value":"|eos}"},
21+
{"type":"Text","value":"\n\n"},
22+
{"type":"Keyword","value":"let"},
23+
{"type":"Text","value":" "},
24+
{"type":"Name","value":"create_group"},
25+
{"type":"Text","value":" "},
26+
{"type":"Operator","value":"="},
27+
{"type":"Text","value":"\n "},
28+
{"type":"Operator","value":"("},
29+
{"type":"KeywordType","value":"unit"},
30+
{"type":"Text","value":" "},
31+
{"type":"Operator","value":"-\u003e."},
32+
{"type":"Text","value":" "},
33+
{"type":"KeywordType","value":"unit"},
34+
{"type":"Operator","value":")"},
35+
{"type":"Text","value":"\n "},
36+
{"type":"Operator","value":"@@"},
37+
{"type":"Text","value":" "},
38+
{"type":"LiteralStringAffix","value":"{|"},
39+
{"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 "},
40+
{"type":"LiteralStringAffix","value":"|}"},
41+
{"type":"Text","value":"\n"}
42+
]

0 commit comments

Comments
 (0)