Skip to content

Commit

Permalink
fix: loading csharp, markdown-math, and search-result syntax failed
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Jan 30, 2024
1 parent 31c7eb3 commit d68f98f
Show file tree
Hide file tree
Showing 16 changed files with 5,115 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,42 @@ public OnigRegExp(final String pattern) {
* @throws TMException if parsing fails
*/
public OnigRegExp(final String pattern, final boolean ignoreCase) {
this.pattern = pattern;
hasGAnchor = pattern.contains("\\G");
final byte[] patternBytes = pattern.getBytes(StandardCharsets.UTF_8);
this.pattern = rewritePatternIfRequired(pattern);
hasGAnchor = this.pattern.contains("\\G");
final byte[] patternBytes = this.pattern.getBytes(StandardCharsets.UTF_8);
try {
int options = Option.CAPTURE_GROUP;
if (ignoreCase)
options |= Option.IGNORECASE;
regex = new Regex(patternBytes, 0, patternBytes.length, options, UTF8Encoding.INSTANCE, Syntax.DEFAULT,
LOGGER.isLoggable(Level.WARNING) ? LOGGER_WARN_CALLBACK : WarnCallback.NONE);
} catch (final SyntaxException ex) {
throw new TMException("Parsing regex pattern \"" + pattern + "\" failed with " + ex, ex);
throw new TMException("Parsing regex pattern \"" + this.pattern + "\" failed with " + ex, ex);
}
}

/**
* Rewrites the given pattern to workaround limitations of the joni library which for example does not support
* negative variable-length lookbehinds
*
* @see <a href="https://github.com/eclipse/tm4e/issues/677">github.com/eclipse/tm4e/issue/677</a>
*/
private String rewritePatternIfRequired(final String pattern) {

// e.g. used in csharp.tmLanguage.json
final var lookbehind1 = "(?<!\\.\\s*)";
if (pattern.startsWith(lookbehind1)) {
return "(?<!\\.)\\s*" + pattern.substring(lookbehind1.length());
}

// e.g. used in markdown.math.inline.tmLanguage.json
final var lookbehind2 = "(?<=^\\s*)";
if (pattern.startsWith(lookbehind2)) {
return "(?<=^)\\s*" + pattern.substring(lookbehind2.length());
}
return pattern;
}

/**
* @return null if not found
*/
Expand Down
1 change: 1 addition & 0 deletions org.eclipse.tm4e.language_pack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ for the [Eclipse IDE](https://eclipseide.org).
| TypeScript | file-extensions="cts, mts, ts" | [1.85.2@microsoft/vscode](https://github.com/microsoft/vscode/tree/8b3775030ed1a69b13e4f4c628c612102e30a681/extensions/typescript-basics) [[upstream]](https://github.com/microsoft/TypeScript-TmLanguage/commit/8c7482b94b548eab56da64dbfb30b82589b3f747)
| TypeScript JSX | file-extensions="tsx" | [1.85.2@microsoft/vscode](https://github.com/microsoft/vscode/tree/8b3775030ed1a69b13e4f4c628c612102e30a681/extensions/typescript-basics) [[upstream]](https://github.com/microsoft/TypeScript-TmLanguage/commit/8c7482b94b548eab56da64dbfb30b82589b3f747)
| Visual Basic | file-extensions="bas, brs, vb, vba, vbs" | [1.85.2@microsoft/vscode](https://github.com/microsoft/vscode/tree/8b3775030ed1a69b13e4f4c628c612102e30a681/extensions/vb) [[upstream]](https://github.com/textmate/asp.vb.net.tmbundle/commit/72d44550b3286d0382d7be0624140cf97857ff69)
| VS Code Search Result <img src="syntaxes/search-result/icon.png" width=16/> | file-extensions="code-search" | [1.85.2@microsoft/vscode](https://github.com/microsoft/vscode/tree/8b3775030ed1a69b13e4f4c628c612102e30a681/extensions/search-result)
| XML | file-extensions="ascx, atom, axaml, axml, bpmn, cpt, csl, csproj, csproj.user, dita, ditamap, dtd, dtml, ent, fsproj, fxml, iml, isml, jmx, launch, menu, mod, mxml, nuspec, opml, owl, proj, props, pt, publishsettings, pubxml, pubxml.user, rbxlx, rbxmx, rdf, rng, rss, shproj, storyboard, svg, targets, tld, tmx, vbproj, vbproj.user, vcxproj, vcxproj.filters, wsdl, wxi, wxl, wxs, xaml, xbl, xib, xlf, xliff, xml, xoml, xpdl, xsd, xul" | [1.85.2@microsoft/vscode](https://github.com/microsoft/vscode/tree/8b3775030ed1a69b13e4f4c628c612102e30a681/extensions/xml) [[upstream]](https://github.com/atom/language-xml/commit/7bc75dfe779ad5b35d9bf4013d9181864358cb49)
| XSL | file-extensions="xsl, xslt" | [1.85.2@microsoft/vscode](https://github.com/microsoft/vscode/tree/8b3775030ed1a69b13e4f4c628c612102e30a681/extensions/xml) [[upstream]](https://github.com/atom/language-xml/commit/507de2ee7daca60cf02e9e21fbeb92bbae73e280)
| YAML | file-extensions="cff, eyaml, eyml, yaml, yaml-tmlanguage, yaml-tmpreferences, yaml-tmtheme, yml" | [1.85.2@microsoft/vscode](https://github.com/microsoft/vscode/tree/8b3775030ed1a69b13e4f4c628c612102e30a681/extensions/yaml) [[upstream]](https://github.com/textmate/yaml.tmbundle/commit/e54ceae3b719506dba7e481a77cea4a8b576ae46)
Expand Down
5 changes: 5 additions & 0 deletions org.eclipse.tm4e.language_pack/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ <h2>About This Content</h2>
<td>file-extensions="bas, brs, vb, vba, vbs"</td>
<td><a href="https://github.com/microsoft/vscode/tree/8b3775030ed1a69b13e4f4c628c612102e30a681/extensions/vb">1.85.2@microsoft/vscode</a> <a href="https://github.com/textmate/asp.vb.net.tmbundle/commit/72d44550b3286d0382d7be0624140cf97857ff69">[upstream]</a>
</tr>
<tr>
<td>VS Code Search Result <img src="syntaxes/search-result/icon.png" width=16/></td>
<td>file-extensions="code-search"</td>
<td><a href="https://github.com/microsoft/vscode/tree/8b3775030ed1a69b13e4f4c628c612102e30a681/extensions/search-result">1.85.2@microsoft/vscode</a>
</tr>
<tr>
<td>XML</td>
<td>file-extensions="ascx, atom, axaml, axml, bpmn, cpt, csl, csproj, csproj.user, dita, ditamap, dtd, dtml, ent, fsproj, fxml, iml, isml, jmx, launch, menu, mod, mxml, nuspec, opml, owl, proj, props, pt, publishsettings, pubxml, pubxml.user, rbxlx, rbxmx, rdf, rng, rss, shproj, storyboard, svg, targets, tld, tmx, vbproj, vbproj.user, vcxproj, vcxproj.filters, wsdl, wxi, wxl, wxs, xaml, xbl, xib, xlf, xliff, xml, xoml, xpdl, xsd, xul"</td>
Expand Down
48 changes: 48 additions & 0 deletions org.eclipse.tm4e.language_pack/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,34 @@
<snippet name="Markdown Example" path="syntaxes/markdown/markdown.example.md" scopeName="text.html.markdown" />
</extension>

<!-- ======================================== -->
<!-- markdown-math/markdown-math: Markdown Math -->
<!-- ======================================== -->
<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type id="org.eclipse.tm4e.language_pack.markdown-math" name="Markdown Math" base-type="org.eclipse.tm4e.language_pack.basetype" priority="low"
/>
</extension>
<extension point="org.eclipse.tm4e.registry.grammars">
<grammar scopeName="text.html.markdown.math" path="syntaxes/markdown-math/markdown-math.tmLanguage.json" />
<scopeNameContentTypeBinding scopeName="text.html.markdown.math" contentTypeId="org.eclipse.tm4e.language_pack.markdown-math" />
</extension>

<extension point="org.eclipse.ui.genericeditor.icons">
<icon contentType="org.eclipse.tm4e.language_pack.markdown-math" icon="syntaxes/markdown-math/icon.png"/>
</extension>

<extension point="org.eclipse.tm4e.ui.snippets">
<snippet name="Markdown Math Example" path="syntaxes/markdown-math/markdown-math.example.md" scopeName="text.html.markdown.math" />
</extension>

<!-- ======================================== -->
<!-- markdown-math: Inline Grammars -->
<!-- ======================================== -->
<extension point="org.eclipse.tm4e.registry.grammars">
<grammar scopeName="markdown.math.block" path="syntaxes/markdown-math/markdown.math.block.tmLanguage.json" />
<grammar scopeName="markdown.math.inline" path="syntaxes/markdown-math/markdown.math.inline.tmLanguage.json" />
</extension>

<!-- ======================================== -->
<!-- objective-c/objective-c: Objective-C -->
<!-- ======================================== -->
Expand Down Expand Up @@ -1114,6 +1142,26 @@
<grammar scopeName="source.sassdoc" path="syntaxes/scss/source.sassdoc.tmLanguage.json" />
</extension>

<!-- ======================================== -->
<!-- search-result/search-result: VS Code Search Result -->
<!-- ======================================== -->
<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type id="org.eclipse.tm4e.language_pack.search-result" name="VS Code Search Result" base-type="org.eclipse.tm4e.language_pack.basetype" priority="low"
file-extensions="code-search" />
</extension>
<extension point="org.eclipse.tm4e.registry.grammars">
<grammar scopeName="text.searchResult" path="syntaxes/search-result/search-result.tmLanguage.json" />
<scopeNameContentTypeBinding scopeName="text.searchResult" contentTypeId="org.eclipse.tm4e.language_pack.search-result" />
</extension>

<extension point="org.eclipse.ui.genericeditor.icons">
<icon contentType="org.eclipse.tm4e.language_pack.search-result" icon="syntaxes/search-result/icon.png"/>
</extension>

<extension point="org.eclipse.tm4e.ui.snippets">
<snippet name="VS Code Search Result Example" path="syntaxes/search-result/search-result.example.code-search" scopeName="text.searchResult" />
</extension>

<!-- ======================================== -->
<!-- shaderlab/shaderlab: ShaderLab -->
<!-- ======================================== -->
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# MathMarkdown Example

**Inline Equations:**

You can include inline equations by enclosing them in single dollar signs ($). For example, the equation for the area of a circle is $A = \pi r^2$.

**Display Equations:**

To display equations on their own line, you can use double dollar signs ($$). For example, the quadratic formula is:

$$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$$

**Greek Letters:**

MathMarkdown supports Greek letters using their LaTeX names. For example, you can write alpha ($\alpha$), beta ($\beta$), and gamma ($\gamma$) using the LaTeX notation.

**Fractions and Exponents:**

You can create fractions using the `\frac` command. For example, $\frac{1}{2}$ represents one-half.

Exponents can be written using the caret (^) symbol. For example, $2^3$ represents two raised to the power of three.

**Summation and Integration:**

MathMarkdown also supports summation and integration symbols. For example, the sum of the first $n$ natural numbers can be written as:

$$\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$$

The definite integral of a function $f(x)$ from $a$ to $b$ can be written as:

$$\int_{a}^{b} f(x) dx$$

**Matrices:**

You can create matrices using the `matrix` environment. For example, the following matrix represents a 2x2 identity matrix:

$$
\begin{matrix}
1 & 0 \\
0 & 1 \\
\end{matrix}
$$
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"information_for_contributors": [
"This file includes some grammar rules copied from https://github.com/James-Yu/LaTeX-Workshop/blob/master/syntax/TeX.tmLanguage.json"
],
"name": "Markdown Math",
"scopeName": "text.html.markdown.math",
"patterns": [
{
"include": "#math"
}
],
"repository": {
"math": {
"patterns": [
{
"name": "comment.line.math.tex",
"match": "((?<!\\\\)%)(.+)$",
"captures": {
"1": {
"name": "punctuation.definition.comment.math.tex"
}
}
},
{
"name": "line.separator.math.tex",
"match": "(\\\\\\\\)$",
"captures": {
"1": {
"name": "punctuation.line.separator.math.tex"
}
}
},
{
"name": "meta.function.math.tex",
"begin": "((\\\\)([a-zA-Z_]+))\\s*(\\{)",
"beginCaptures": {
"1": {
"name": "storage.type.function.math.tex"
},
"2": {
"name": "punctuation.definition.function.math.tex"
},
"3": {
"name": "entity.name.function.math.tex"
},
"4": {
"name": "punctuation.definition.arguments.begin.math.tex"
}
},
"end": "\\}",
"endCaptures": {
"0": {
"name": "punctuation.definition.arguments.end.math.tex"
}
},
"patterns": [
{
"include": "$self"
}
]
},
{
"captures": {
"1": {
"name": "punctuation.definition.constant.math.tex"
}
},
"match": "(\\\\)([a-zA-Z_]+)\\b",
"name": "constant.character.math.tex"
},
{
"captures": {
"1": {
"name": "punctuation.definition.constant.math.tex"
}
},
"match": "(\\\\)(?!begin\\*\\{|verb)([A-Za-z]+)",
"name": "constant.other.general.math.tex"
},
{
"match": "(?<!\\\\)\\{",
"name": "punctuation.math.begin.bracket.curly"
},
{
"match": "(?<!\\\\)\\}",
"name": "punctuation.math.end.bracket.curly"
},
{
"match": "\\(",
"name": "punctuation.math.begin.bracket.round"
},
{
"match": "\\)",
"name": "punctuation.math.end.bracket.round"
},
{
"match": "(([0-9]*[\\.][0-9]+)|[0-9]+)",
"name": "constant.numeric.math.tex"
},
{
"match": "[\\+\\*/_\\^-]",
"name": "punctuation.math.operator.latex"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"fileTypes": [],
"injectionSelector": "L:text.html.markdown - (comment, string, meta.paragraph.markdown, markup.math.block.markdown, markup.fenced_code.block.markdown, markup.raw.block.markdown)",
"patterns": [
{
"include": "#double_dollar_math_block"
},
{
"include": "#single_dollar_math_block"
}
],
"repository": {
"double_dollar_math_block": {
"name": "markup.math.block.markdown",
"contentName": "meta.embedded.math.markdown",
"begin": "(?<=^\\s*)(\\${2})(?![^$]*\\${2})",
"beginCaptures": {
"1": {
"name": "punctuation.definition.math.begin.markdown"
}
},
"end": "(.*)(\\${2})",
"endCaptures": {
"1": {
"name": "meta.embedded.math.markdown",
"patterns": [
{
"include": "text.html.markdown.math#math"
}
]
},
"2": {
"name": "punctuation.definition.math.end.markdown"
}
},
"patterns": [
{
"begin": "(^|\\G)",
"while": "(^|\\G)(?!.*(\\${2}))",
"patterns": [
{
"include": "text.html.markdown.math#math"
}
]
}
]
},
"single_dollar_math_block": {
"name": "markup.math.block.markdown",
"contentName": "meta.embedded.math.markdown",
"begin": "(?<=^\\s*)(\\$)(?![^$]*\\$|\\d)",
"beginCaptures": {
"1": {
"name": "punctuation.definition.math.begin.markdown"
}
},
"end": "(.*)(\\${1})",
"endCaptures": {
"1": {
"name": "meta.embedded.math.markdown",
"patterns": [
{
"include": "text.html.markdown.math#math"
}
]
},
"2": {
"name": "punctuation.definition.math.end.markdown"
}
},
"patterns": [
{
"begin": "(^|\\G)",
"while": "(^|\\G)(?!.*(\\${1}))",
"patterns": [
{
"include": "text.html.markdown.math#math"
}
]
}
]
}
},
"scopeName": "markdown.math.block"
}
Loading

0 comments on commit d68f98f

Please sign in to comment.