-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): Migrate
codemirror-lang-n8n-expression
into this mono…
…repo (no-changelog) (#9087) Co-authored-by: Iván Ovejero <[email protected]>
- Loading branch information
Showing
19 changed files
with
499 additions
and
43 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
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,14 @@ | ||
const sharedOptions = require('@n8n_io/eslint-config/shared'); | ||
|
||
/** | ||
* @type {import('@types/eslint').ESLint.ConfigData} | ||
*/ | ||
module.exports = { | ||
extends: ['@n8n_io/eslint-config/base'], | ||
|
||
...sharedOptions(__dirname), | ||
|
||
ignorePatterns: [ | ||
'src/expressions/grammar*.ts' | ||
] | ||
}; |
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 @@ | ||
# @n8n/codemirror-lang | ||
|
||
Language support package for CodeMirror 6 in n8n | ||
|
||
[n8n Expression Language support](./src/expressions/README.md) |
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,2 @@ | ||
/** @type {import('jest').Config} */ | ||
module.exports = require('../../../jest.config'); |
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,37 @@ | ||
{ | ||
"name": "@n8n/codemirror-lang", | ||
"version": "0.3.0", | ||
"description": "Language support package for CodeMirror 6 in n8n", | ||
"private": true, | ||
"sideEffects": false, | ||
"main": "dist/index.js", | ||
"module": "src/index.ts", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.js", | ||
"import": "./src/index.ts", | ||
"types": "./dist/index.d.ts" | ||
}, | ||
"./*": "./*" | ||
}, | ||
"scripts": { | ||
"clean": "rimraf dist .turbo", | ||
"typecheck": "tsc --noEmit", | ||
"generate:expressions:grammar": "lezer-generator --typeScript --output src/expressions/grammar.ts src/expressions/expressions.grammar", | ||
"generate": "pnpm generate:expressions:grammar && pnpm format", | ||
"build": "tsc -p tsconfig.build.json", | ||
"test": "jest", | ||
"lint": "eslint . --ext .ts --quiet", | ||
"lintfix": "eslint . --ext .ts --fix", | ||
"format": "prettier --write --ignore-path ../../.prettierignore src test" | ||
}, | ||
"peerDependencies": { | ||
"@codemirror/language": "*", | ||
"@lezer/highlight": "*", | ||
"@lezer/lr": "^1.4.0" | ||
}, | ||
"devDependencies": { | ||
"@lezer/generator": "^1.7.0" | ||
} | ||
} |
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,26 @@ | ||
# n8n Expression language support | ||
|
||
## Usage | ||
|
||
```js | ||
import { parserWithMetaData as n8nParser } from '@n8n/codemirror-lang'; | ||
import { LanguageSupport, LRLanguage } from '@codemirror/language'; | ||
import { parseMixed } from '@lezer/common'; | ||
import { parser as jsParser } from '@lezer/javascript'; | ||
|
||
const n8nPlusJsParser = n8nParser.configure({ | ||
wrap: parseMixed((node) => { | ||
if (node.type.isTop) return null; | ||
|
||
return node.name === 'Resolvable' | ||
? { parser: jsParser, overlay: (node) => node.type.name === 'Resolvable' } | ||
: null; | ||
}), | ||
}); | ||
|
||
const n8nLanguage = LRLanguage.define({ parser: n8nPlusJsParser }); | ||
|
||
export function n8nExpressionLanguageSupport() { | ||
return new LanguageSupport(n8nLanguage); | ||
} | ||
``` |
21 changes: 21 additions & 0 deletions
21
packages/@n8n/codemirror-lang/src/expressions/expressions.grammar
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 @@ | ||
@top Program { entity* } | ||
|
||
entity { Plaintext | Resolvable } | ||
|
||
@tokens { | ||
Plaintext { ![{] Plaintext? | "{" (@eof | ![{] Plaintext?) } | ||
|
||
OpenMarker[closedBy="CloseMarker"] { "{{" } | ||
|
||
CloseMarker[openedBy="OpenMarker"] { "}}" } | ||
|
||
Resolvable { | ||
OpenMarker resolvableChar* CloseMarker | ||
} | ||
|
||
resolvableChar { unicodeChar | "}" ![}] | "\\}}" } | ||
|
||
unicodeChar { $[\u0000-\u007C] | $[\u007E-\u1FFF] | $[\u20A0-\u20CF] | $[\u{1F300}-\u{1F64F}] } | ||
} | ||
|
||
@detectDelim |
4 changes: 4 additions & 0 deletions
4
packages/@n8n/codemirror-lang/src/expressions/grammar.terms.ts
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 @@ | ||
// This file was generated by lezer-generator. You probably shouldn't edit it. | ||
export const Program = 1, | ||
Plaintext = 2, | ||
Resolvable = 3; |
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,18 @@ | ||
// This file was generated by lezer-generator. You probably shouldn't edit it. | ||
import { LRParser } from '@lezer/lr'; | ||
|
||
export const parser = LRParser.deserialize({ | ||
version: 14, | ||
states: "nQQOPOOOOOO'#Cb'#CbOOOO'#C`'#C`QQOPOOOOOO-E6^-E6^", | ||
stateData: 'Y~OQPORPO~O', | ||
goto: 'bVPPPPWP^QRORSRTQOR', | ||
nodeNames: '⚠ Program Plaintext Resolvable', | ||
maxTerm: 6, | ||
skippedNodes: [0], | ||
repeatNodeCount: 1, | ||
tokenData: | ||
"&U~RTO#ob#o#p!h#p;'Sb;'S;=`!]<%lOb~gTQ~O#ob#o#pv#p;'Sb;'S;=`!]<%lOb~yUO#ob#p;'Sb;'S;=`!]<%l~b~Ob~~!c~!`P;=`<%lb~!hOQ~~!kVO#ob#o#p#Q#p;'Sb;'S;=`!]<%l~b~Ob~~!c~#TWO#O#Q#O#P#m#P#q#Q#q#r%Z#r$IS#Q$Lj$Ml#Q;(b;(c%x;(c;(d&O~#pWO#O#Q#O#P#m#P#q#Q#q#r$Y#r$IS#Q$Lj$Ml#Q;(b;(c%x;(c;(d&O~$]TO#q#Q#q#r$l#r;'S#Q;'S;=`%r<%lO#Q~$qWR~O#O#Q#O#P#m#P#q#Q#q#r%Z#r$IS#Q$Lj$Ml#Q;(b;(c%x;(c;(d&O~%^TO#q#Q#q#r%m#r;'S#Q;'S;=`%r<%lO#Q~%rOR~~%uP;=`<%l#Q~%{P;NQ<%l#Q~&RP;=`;JY#Q", | ||
tokenizers: [0], | ||
topRules: { Program: [0, 1] }, | ||
tokenPrec: 0, | ||
}); |
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,28 @@ | ||
import { LRLanguage, LanguageSupport, foldNodeProp, foldInside } from '@codemirror/language'; | ||
import { styleTags, tags as t } from '@lezer/highlight'; | ||
import { parser } from './grammar'; | ||
|
||
export const parserWithMetaData = parser.configure({ | ||
props: [ | ||
foldNodeProp.add({ | ||
Application: foldInside, | ||
}), | ||
styleTags({ | ||
OpenMarker: t.brace, | ||
CloseMarker: t.brace, | ||
Plaintext: t.content, | ||
Resolvable: t.string, | ||
}), | ||
], | ||
}); | ||
|
||
export const n8nLanguage = LRLanguage.define({ | ||
parser: parserWithMetaData, | ||
languageData: { | ||
commentTokens: { line: ';' }, | ||
}, | ||
}); | ||
|
||
export function n8nExpression() { | ||
return new LanguageSupport(n8nLanguage); | ||
} |
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 @@ | ||
export { parserWithMetaData, n8nLanguage } from './expressions'; |
Oops, something went wrong.