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

Configurable language parsing #23

Draft
wants to merge 3 commits into
base: main
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
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@ import { lintExpression } from "@bpmn-io/feel-lint"
lintExpression('foo = bar');
```

### Codemirror plugin
You may pass custom language configuration to the editor:

The `cmFeelLinter` function returns a codemirror linting source that you can use as a extension
in you codemirror instance.
```javascript
lintExpression('> 10, "yes", mike\'s name', {
dialect: 'unaryTests',
context: {
"mike's name": "Mike the might"
}
});
```

### CodeMirror plugin

The `cmFeelLinter` function returns a [`LintSource`](https://codemirror.net/docs/ref/#lint.LintSource) that you can use to extend your [CodeMirror](https://codemirror.net/) instance.

```javascript
import { cmFeelLinter } from "@bpmn-io/feel-lint"
Expand Down
17 changes: 14 additions & 3 deletions lib/text/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import { parser } from 'lezer-feel';
import { parser, trackVariables } from 'lezer-feel';
import lintAll from '../shared/index.js';

/**
* Create an array of syntax errors for the given expression.
*
* @param {String} expression
* @param { {
* dialect?: 'expression' | 'unaryTests',
* context?: Record<string, any>
* } } [lintOptions]
*
* @returns {LintMessage[]} array of syntax errors
*/
export function lintExpression(expression) {
export function lintExpression(expression, {
dialect = 'expression',
context = {}
} = {}) {

const syntaxTree = parser.parse(expression);
const syntaxTree = parser.configure({
top: dialect === 'unaryTests' ? 'UnaryTests' : 'Expression',
contextTracker: trackVariables(context)
}).parse(expression);

const lintMessages = lintAll(syntaxTree);

Expand Down
Loading
Loading