Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure github-linguist compatibility for the syntaxes #1659

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,11 @@
"scopeName": "source.dune-workspace",
"path": "./syntaxes/dune-workspace.json"
},
{
"language": "dune-all",
"scopeName": "source.dune-all",
"path": "./syntaxes/dune-all.json"
},
{
"language": "ocaml.merlin",
"scopeName": "source.ocaml.merlin",
Expand Down
4 changes: 3 additions & 1 deletion syntaxes/atd.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"1": { "name": "keyword.other.atd" },
"2": { "name": "keyword.other.atd" }
},
"endCaptures": [{ "name": "keyword.other.atd" }],
"endCaptures": {
"1": { "name": "keyword.other.atd" }
},
"patterns": [{ "include": "$self" }]
}
]
Expand Down
22 changes: 16 additions & 6 deletions syntaxes/cram.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,34 @@
{
"begin": "\\[\\^?",
"end": "\\]",
"beginCaptures": [{ "name": "keyword.other.regex" }],
"endCaptures": [{ "name": "keyword.other.regex" }],
"beginCaptures": {
"1": { "name": "keyword.other.regex" }
},
"endCaptures": {
"1": { "name": "keyword.other.regex" }
},
"contentName": "source.regex",
"patterns": [{ "name": "keyword.other.regex", "match": "-" }]
},
{
"begin": "\\((\\?[:=!])?",
"end": "\\)",
"beginCaptures": [{ "name": "keyword.other.regex" }],
"endCaptures": [{ "name": "keyword.other.regex" }],
"beginCaptures": {
"1": { "name": "keyword.other.regex" }
},
"endCaptures": {
"1": { "name": "keyword.other.regex" }
},
"contentName": "source.regex",
"patterns": [{ "include": "#regex" }]
},
{
"begin": "{",
"end": "}",
"beginCaptures": [{ "name": "keyword.other.regex" }],
"endCaptures": [{ "name": "keyword.other.regex" }],
"beginCaptures": {
"1": { "name": "keyword.other.regex" }
},
"endCaptures": { "1": { "name": "keyword.other.regex" } },
"contentName": "source.regex",
"patterns": [
{
Expand Down
11 changes: 11 additions & 0 deletions syntaxes/dune-all.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "dune-all",
"scopeName": "source.dune-all",
"fileTypes": ["dune", "dune-project", "dune-workspace"],
"patterns": [
{ "include": "source.dune#general" },
{ "include": "source.dune#stanzas" },
{ "include": "source.dune-project#stanzas" },
{ "include": "source.dune-workspace#stanzas" }
]
}
24 changes: 12 additions & 12 deletions syntaxes/dune.json
Original file line number Diff line number Diff line change
Expand Up @@ -2788,16 +2788,16 @@
"comment": "variable",
"begin": "%\\{",
"end": "\\}",
"beginCaptures": [
{
"beginCaptures": {
"1": {
"name": "keyword.operator.dune"
}
],
"endCaptures": [
{
},
"endCaptures": {
"1": {
"name": "keyword.operator.dune"
}
],
},
"patterns": [
{
"include": "#variables"
Expand Down Expand Up @@ -2876,16 +2876,16 @@
"comment": "escaped variable",
"begin": "(\\%\\{)",
"end": "(\\})",
"beginCaptures": [
{
"beginCaptures": {
"1": {
"name": "constant.character.escape.dune"
}
],
"endCaptures": [
{
},
"endCaptures": {
"1": {
"name": "constant.character.escape.dune"
}
],
},
"patterns": [
{
"include": "#variables"
Expand Down
34 changes: 17 additions & 17 deletions syntaxes/menhir.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
{
"comment": "sequence of rules",
"begin": "%%",
"beginCaptures": [{ "name": "keyword.other.menhir" }],
"beginCaptures": { "1": { "name": "keyword.other.menhir" } },
"end": "%%",
"endCaptures": [{ "name": "keyword.other.menhir" }],
"endCaptures": { "1": { "name": "keyword.other.menhir" } },
"patterns": [{ "include": "#comments" }, { "include": "#rules" }]
},
{ "include": "source.ocaml" }
Expand Down Expand Up @@ -44,15 +44,15 @@
{
"comment": "ocaml header",
"begin": "%{",
"beginCaptures": [{ "name": "keyword.other.menhir" }],
"beginCaptures": { "1": { "name": "keyword.other.menhir" } },
"end": "%}",
"endCaptures": [{ "name": "keyword.other.menhir" }],
"endCaptures": { "1": { "name": "keyword.other.menhir" } },
"patterns": [{ "include": "source.ocaml" }]
},
{
"comment": "token declaration",
"begin": "%token\\b",
"beginCaptures": [{ "name": "keyword.other.menhir" }],
"beginCaptures": { "1": { "name": "keyword.other.menhir" } },
"end": "(?=%)",
"patterns": [
{ "include": "#type-annotation" },
Expand All @@ -65,7 +65,7 @@
{
"comment": "associativity declaration",
"begin": "%(?:nonassoc|left|right)\\b",
"beginCaptures": [{ "name": "keyword.other.menhir" }],
"beginCaptures": { "1": { "name": "keyword.other.menhir" } },
"end": "(?=%)",
"patterns": [
{ "include": "#token-name" },
Expand All @@ -78,7 +78,7 @@
{
"comment": "type/start/on_error_reduce declaration",
"begin": "%(?:type|start|on_error_reduce)\\b",
"beginCaptures": [{ "name": "keyword.other.menhir" }],
"beginCaptures": { "1": { "name": "keyword.other.menhir" } },
"end": "(?=%)",
"patterns": [
{ "include": "#type-annotation" },
Expand All @@ -96,7 +96,7 @@
{
"comment": "attribute declaration",
"begin": "%(?:attribute\\b|(?=\\[))",
"beginCaptures": [{ "name": "keyword.other.menhir" }],
"beginCaptures": { "1": { "name": "keyword.other.menhir" } },
"end": "(?=%)",
"patterns": [
{ "include": "source.ocaml#attributes" },
Expand All @@ -113,8 +113,8 @@
"comment": "ocaml type annotation for token",
"begin": "<",
"end": ">",
"beginCaptures": [{ "name": "keyword.other.menhir" }],
"endCaptures": [{ "name": "keyword.other.menhir" }],
"beginCaptures": { "1": { "name": "keyword.other.menhir" } },
"endCaptures": { "1": { "name": "keyword.other.menhir" } },
"patterns": [{ "include": "source.ocaml" }]
}
}
Expand Down Expand Up @@ -167,7 +167,7 @@
{
"comment": "production",
"begin": "[:|]",
"beginCaptures": [{ "name": "keyword.other.menhir" }],
"beginCaptures": { "1": { "name": "keyword.other.menhir" } },
"end": "(?=[{<|]|let\\b|[[:lower:]_][[:word:]]*[[:space:]]*(?:\\([^)]+\\)[[:space:]]*)?:|%(?!prec\\b))",
"patterns": [
{ "include": "#comments" },
Expand Down Expand Up @@ -214,7 +214,7 @@
{
"comment": "production",
"begin": "[:|]",
"beginCaptures": [{ "name": "keyword.other.menhir" }],
"beginCaptures": { "1": { "name": "keyword.other.menhir" } },
"end": "(?=[{<|]|let\\b|[[:lower:]_][[:word:]]*[[:space:]]*(?:\\([^)]+\\)[[:space:]]*)?:|%(?!prec\\b))",
"patterns": [
{ "include": "#comments" },
Expand All @@ -238,9 +238,9 @@
"comment": "ocaml semantic action",
"contentName": "source.embedded-action.menhir",
"begin": "{",
"beginCaptures": [{ "name": "keyword.other.menhir" }],
"beginCaptures": { "1": { "name": "keyword.other.menhir" } },
"end": "}",
"endCaptures": [{ "name": "keyword.other.menhir" }],
"endCaptures": { "1": { "name": "keyword.other.menhir" } },
"patterns": [{ "include": "source.ocaml" }]
},
"new-actions": {
Expand All @@ -249,9 +249,9 @@
{
"comment": "point-free ocaml semantic action",
"begin": "<",
"beginCaptures": [{ "name": "keyword.other.menhir" }],
"beginCaptures": { "1": { "name": "keyword.other.menhir" } },
"end": ">",
"endCaptures": [{ "name": "keyword.other.menhir" }],
"endCaptures": { "1": { "name": "keyword.other.menhir" } },
"patterns": [{ "include": "source.ocaml" }]
}
]
Expand Down Expand Up @@ -279,7 +279,7 @@
},
{
"comment": "destructured semantic value capture",
"begin": "(?<![[:word:]][[:space:]]*)\\(",
"begin": "(?<!\\w)\\(",
Copy link
Author

@huwaireb huwaireb Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is a correct fix.

It resolves

- Invalid regex in grammar: `source.ocaml.menhir` (in `syntaxes/menhir.json`) 
contains a malformed regex (regex "`(?<![[:word:]][[:space:]]*)\(`": 
lookbehind assertion is not fixed length (at offset 26))

caused by [[:space:]]*.

Copy link
Collaborator

@mnxn mnxn Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, the regex would not match either a(b, c) = x or a (b, c) = x. But now the second string matches.
I don't know what the ideal solution is here, but at the very least, both of the strings above should not match.

Also, the regex should stick with [[:word:]] instead of \\w.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like it accepts this (?<![[:word:]])(?<![[:space:]])\\(, can we do this instead? Rubular parses it fine, i can't seem to get it to make the vsix to try it out.

"end": "\\)[[:space:]]*(=)",
"endCaptures": {
"1": { "name": "keyword.other.menhir" }
Expand Down
12 changes: 6 additions & 6 deletions syntaxes/ocaml.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@
"comment": "Cinaps comment",
"begin": "\\(\\*\\$",
"end": "\\*\\)",
"beginCaptures": [{ "name": "comment.cinaps.ocaml" }],
"endCaptures": [{ "name": "comment.cinaps.ocaml" }],
"beginCaptures": { "1": { "name": "comment.cinaps.ocaml" } },
"endCaptures": { "1": { "name": "comment.cinaps.ocaml" } },
"patterns": [{ "include": "$self" }]
},
{
Expand Down Expand Up @@ -333,15 +333,15 @@
{
"begin": "\\b(sig)\\b",
"end": "\\b(end)\\b",
"beginCaptures": [{ "name": "keyword.other.ocaml" }],
"endCaptures": [{ "name": "keyword.other.ocaml" }],
"beginCaptures": { "1": { "name": "keyword.other.ocaml" } },
"endCaptures": { "1": { "name": "keyword.other.ocaml" } },
"patterns": [{ "include": "source.ocaml.interface" }]
},
{
"begin": "\\b(struct)\\b",
"end": "\\b(end)\\b",
"beginCaptures": [{ "name": "keyword.other.ocaml" }],
"endCaptures": [{ "name": "keyword.other.ocaml" }],
"beginCaptures": { "1": { "name": "keyword.other.ocaml" } },
"endCaptures": { "1": { "name": "keyword.other.ocaml" } },
"patterns": [{ "include": "$self" }]
}
]
Expand Down
12 changes: 6 additions & 6 deletions syntaxes/ocamlbuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
{
"begin": "<",
"end": ">",
"beginCaptures": [{ "name": "keyword.operator.ocamlbuild" }],
"endCaptures": [{ "name": "keyword.operator.ocamlbuild" }],
"beginCaptures": { "1": { "name": "keyword.operator.ocamlbuild" } },
"endCaptures": { "1": { "name": "keyword.operator.ocamlbuild" } },
"name": "string.quoted.double.ocamlbuild",
"patterns": [{ "include": "#patterns" }]
},
Expand Down Expand Up @@ -65,8 +65,8 @@
{
"begin": "{",
"end": "}",
"beginCaptures": [{ "name": "keyword.operator.ocamlbuild" }],
"endCaptures": [{ "name": "keyword.operator.ocamlbuild" }],
"beginCaptures": { "1": { "name": "keyword.operator.ocamlbuild" } },
"endCaptures": { "1": { "name": "keyword.operator.ocamlbuild" } },
"patterns": [
{ "name": "keyword.operator.ocamlbuild", "match": "," },
{ "include": "#patterns" }
Expand All @@ -75,8 +75,8 @@
{
"begin": "\\[\\^?",
"end": "\\]",
"beginCaptures": [{ "name": "keyword.operator.ocamlbuild" }],
"endCaptures": [{ "name": "keyword.operator.ocamlbuild" }]
"beginCaptures": { "1": { "name": "keyword.operator.ocamlbuild" } },
"endCaptures": { "1": { "name": "keyword.operator.ocamlbuild" } }
}
]
},
Expand Down
8 changes: 6 additions & 2 deletions syntaxes/ocamllex.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@
{
"comment": "embedded ocaml source",
"begin": "{",
"beginCaptures": [{ "name": "keyword.other.ocamllex" }],
"beginCaptures": {
"1": { "name": "keyword.other.ocamllex" }
},
"end": "}",
"endCaptures": [{ "name": "keyword.other.ocamllex" }],
"endCaptures": {
"1": { "name": "keyword.other.ocamllex" }
},
"patterns": [{ "include": "source.ocaml" }]
}
]
Expand Down
Loading