Skip to content

Commit

Permalink
fix(ocaml): support multistring (#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusted authored Jan 7, 2025
1 parent e79c813 commit d829579
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lexers/embedded/ocaml.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
27 changes: 27 additions & 0 deletions lexers/testdata/ocaml.actual
Original file line number Diff line number Diff line change
@@ -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 changes: 42 additions & 0 deletions lexers/testdata/ocaml.expected
Original file line number Diff line number Diff line change
@@ -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"}
]

0 comments on commit d829579

Please sign in to comment.