forked from k2d222/twwe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some very basic highlighting for rules++
- Loading branch information
mathis
committed
Sep 14, 2023
1 parent
49877e1
commit be92679
Showing
17 changed files
with
528 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { LRLanguage, LanguageSupport } from "@codemirror/language"; | ||
declare const RppLanguage: LRLanguage; | ||
declare function Rpp(): LanguageSupport; | ||
export { RppLanguage, Rpp }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { LRParser } from '@lezer/lr'; | ||
import { LRLanguage, foldNodeProp, LanguageSupport } from '@codemirror/language'; | ||
import { styleTags, tags } from '@lezer/highlight'; | ||
|
||
// This file was generated by lezer-generator. You probably shouldn't edit it. | ||
const spec_Ident = {__proto__:null,anchor:32, and:34, assert:36, automapper:38, break:40, continue:42, count:44, empty:46, end:48, error:50, false:52, for:54, full:56, function:58, group:60, if:62, index:64, insert:66, invoke:68, last:70, nested:72, newrule:74, newrun:76, nocopy:78, nodefault:80, not:82, notindex:84, null:86, operator:88, or:90, pos:92, preset:94, random:96, return:98, rotate:100, rule:102, to:104, true:106, type:108, warning:110, array:112, bool:114, coord:116, float:118, int:120, object:122, range:124, string:126, N:128, V:130, H:132, R:134, VR:136, VH:138, HR:140, VHR:142}; | ||
const parser = LRParser.deserialize({ | ||
version: 14, | ||
states: "!QQYQPOOOOQO'#Cb'#CbOOQO'#Cd'#CdOOQO'#Ce'#CeOOQO'#Ck'#CkOOQO'#Cg'#CgQYQPOOOOQO-E6e-E6e", | ||
stateData: "%Z~O^OSPOS~ORSOSSOTSOVSOYSO`POaPObPOcPOdPOePOfPOgPOhPOiPOjPOkPOlPOmPOnPOoPOpPOqPOrPOsPOtPOuPOvPOwPOxPOyPOzPO{PO|PO}PO!OPO!PPO!QPO!RPO!SPO!TPO!UPO!VPO!WPO!XPO!YQO!ZQO![QO!]QO!^QO!_QO!`QO!aQO!bRO!cRO!dRO!eRO!fRO!gRO!hRO!iRO~O", | ||
goto: "o`PPPPPPaPaaPePPPkTSOUQUORVUTTOU", | ||
nodeNames: "⚠ LineComment file Preprocessor Literal String Keyword Ident Type Rotation Function", | ||
maxTerm: 71, | ||
skippedNodes: [0,1], | ||
repeatNodeCount: 1, | ||
tokenData: "'g~RdX^!apq!ars#Ust$|{|%h}!O%h!O!P%q!P!Q&[!Q![&P![!]&y!c!}'X#T#o&y#y#z!a$f$g!a#BY#BZ!a$IS$I_!a$I|$JO!a$JT$JU!a$KV$KW!a&FU&FV!a~!fY^~X^!apq!a#y#z!a$f$g!a#BY#BZ!a$IS$I_!a$I|$JO!a$JT$JU!a$KV$KW!a&FU&FV!a~#ZWT~OY#UZr#Urs#ss#O#U#O#P#x#P;'S#U;'S;=`$v<%lO#U~#xOT~~#{RO;'S#U;'S;=`$U;=`O#U~$ZXT~OY#UZr#Urs#ss#O#U#O#P#x#P;'S#U;'S;=`$v;=`<%l#U<%lO#U~$yP;=`<%l#U~%RTR~OY$|Zr$|s;'S$|;'S;=`%b<%lO$|~%eP;=`<%l$|~%kQ!O!P%q!Q![&P~%tP!Q![%w~%|PS~!Q![%w~&UQS~!O!P%w!Q![&P~&_P!P!Q&b~&gSP~OY&bZ;'S&b;'S;=`&s<%lO&b~&vP;=`<%l&b~'ORV~![!]&y!c!}&y#T#o&y~'^RY~![!]'X!c!}'X#T#o'X", | ||
tokenizers: [0], | ||
topRules: {"file":[0,2]}, | ||
specialized: [{term: 7, get: value => spec_Ident[value] || -1}], | ||
tokenPrec: 0 | ||
}); | ||
|
||
function foldRppConfig(node) { | ||
var _a, _b; | ||
const from = (_b = (_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.firstChild) === null || _b === void 0 ? void 0 : _b.to; // end of HeaderTok | ||
const to = node.to - 1; // before newline | ||
if (from) { | ||
return { from, to }; | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
const RppLanguage = LRLanguage.define({ | ||
parser: parser.configure({ | ||
props: [ | ||
foldNodeProp.add({ | ||
Config: foldRppConfig | ||
}), | ||
styleTags({ | ||
LineComment: tags.lineComment, | ||
String: tags.string, | ||
Preprocessor: tags.meta, | ||
Rotation: tags.keyword, | ||
Literal: tags.number, | ||
Keyword: tags.keyword, | ||
Ident: tags.variableName, | ||
Type: tags.typeName, | ||
Function: tags.definition(tags.variableName), // not really but I want colors | ||
}) | ||
] | ||
}), | ||
languageData: { | ||
commentTokens: { line: "#" } | ||
} | ||
}); | ||
function Rpp() { | ||
return new LanguageSupport(RppLanguage); | ||
} | ||
|
||
export { Rpp, RppLanguage }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { linter} from "@codemirror/lint" | ||
|
||
import { | ||
lint as lintAutomapper, | ||
LintLevel, | ||
} from '../../../twmap/automap' | ||
|
||
export const DDNetRulesLinter = linter(view => { | ||
const str = view.state.doc.toString() | ||
const lints = lintAutomapper(str) | ||
|
||
return lints.map(l => { | ||
const line = view.state.doc.line(l.line + 1) | ||
const severity = l.level === LintLevel.Warning ? 'warning' : 'error' | ||
let message = l.reason | ||
if (l.note) message += ' (' + l.note + ')' | ||
|
||
return { | ||
from: line.from + l.range[0], | ||
to: line.from + l.range[1], | ||
severity, | ||
message, | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/node_modules | ||
package-lock.json | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/src | ||
/test | ||
/node_modules | ||
rollup.config.js | ||
tsconfig.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (C) 2021 by Marijn Haverbeke <[email protected]> and others | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# CodeMirror 6 language package template | ||
|
||
This is an example repository containing a minimal [CodeMirror](https://codemirror.net/6/) language support package. The idea is to clone it, rename it, and edit it to create support for a new language. | ||
|
||
Things you'll need to do (see the [language support example](https://codemirror.net/6/examples/lang-package/) for a more detailed tutorial): | ||
|
||
* `git grep EXAMPLE` and replace all instances with your language name. | ||
|
||
* Rewrite the grammar in `src/syntax.grammar` to cover your language. See the [Lezer system guide](https://lezer.codemirror.net/docs/guide/#writing-a-grammar) for information on this file format. | ||
|
||
* Adjust the metadata in `src/index.ts` to work with your new grammar. | ||
|
||
* Adjust the grammar tests in `test/cases.txt`. | ||
|
||
* Build (`npm run prepare`) and test (`npm test`). | ||
|
||
* Rewrite this readme file. | ||
|
||
* Optionally add a license. | ||
|
||
* Publish. Put your package on npm under a name like `codemirror-lang-EXAMPLE`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "codemirror-lang-rpp", | ||
"version": "0.1.0", | ||
"description": "Rules++ language support for CodeMirror", | ||
"scripts": { | ||
"test": "mocha test/test.js", | ||
"prepare": "rollup -c" | ||
}, | ||
"type": "module", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.js", | ||
"exports": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs" | ||
}, | ||
"types": "dist/index.d.ts", | ||
"sideEffects": false, | ||
"dependencies": { | ||
"@codemirror/language": "^6.0.0", | ||
"@lezer/highlight": "^1.0.0", | ||
"@lezer/lr": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@lezer/generator": "^1.0.0", | ||
"mocha": "^9.0.1", | ||
"rollup": "^2.60.2", | ||
"rollup-plugin-dts": "^4.0.1", | ||
"rollup-plugin-ts": "^3.0.2", | ||
"typescript": "^4.3.4" | ||
}, | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import typescript from "rollup-plugin-ts" | ||
import {lezer} from "@lezer/generator/rollup" | ||
|
||
export default { | ||
input: "src/index.ts", | ||
external: id => id != "tslib" && !/^(\.?\/|\w:)/.test(id), | ||
output: [ | ||
{file: "dist/index.cjs", format: "cjs"}, | ||
{dir: "./dist", format: "es"} | ||
], | ||
plugins: [lezer(), typescript()] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { parser } from "./syntax.grammar" | ||
import {LRLanguage, LanguageSupport, foldNodeProp } from "@codemirror/language" | ||
import { SyntaxNode } from "@lezer/common" | ||
import { styleTags, tags as t } from "@lezer/highlight" | ||
|
||
function foldRppConfig(node: SyntaxNode): { | ||
from: number; | ||
to: number; | ||
} | null { | ||
const from = node.firstChild?.firstChild?.to // end of HeaderTok | ||
const to = node.to - 1 // before newline | ||
if (from) { | ||
return { from, to } | ||
} else { | ||
return null | ||
} | ||
} | ||
|
||
export const RppLanguage = LRLanguage.define({ | ||
parser: parser.configure({ | ||
props: [ | ||
foldNodeProp.add({ | ||
Config: foldRppConfig | ||
}), | ||
styleTags({ | ||
LineComment: t.lineComment, | ||
String: t.string, | ||
Preprocessor: t.meta, | ||
Rotation: t.keyword, | ||
Literal: t.number, | ||
Keyword: t.keyword, | ||
Ident: t.variableName, | ||
Type: t.typeName, | ||
Function: t.definition(t.variableName), // not really but I want colors | ||
}) | ||
] | ||
}), | ||
languageData: { | ||
commentTokens: {line: "#"} | ||
} | ||
}) | ||
|
||
export function Rpp() { | ||
return new LanguageSupport(RppLanguage) | ||
} |
Oops, something went wrong.