aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/language
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/frontend/src/language')
-rw-r--r--subprojects/frontend/src/language/folding.ts9
-rw-r--r--subprojects/frontend/src/language/indentation.ts19
-rw-r--r--subprojects/frontend/src/language/problem.grammar2
-rw-r--r--subprojects/frontend/src/language/problemLanguageSupport.ts11
-rw-r--r--subprojects/frontend/src/language/props.ts2
5 files changed, 23 insertions, 20 deletions
diff --git a/subprojects/frontend/src/language/folding.ts b/subprojects/frontend/src/language/folding.ts
index 2560c183..9d1c04a3 100644
--- a/subprojects/frontend/src/language/folding.ts
+++ b/subprojects/frontend/src/language/folding.ts
@@ -1,7 +1,7 @@
1import { EditorState } from '@codemirror/state'; 1import type { EditorState } from '@codemirror/state';
2import type { SyntaxNode } from '@lezer/common'; 2import type { SyntaxNode } from '@lezer/common';
3 3
4export type FoldRange = { from: number, to: number }; 4export type FoldRange = { from: number; to: number };
5 5
6/** 6/**
7 * Folds a block comment between its delimiters. 7 * Folds a block comment between its delimiters.
@@ -47,7 +47,10 @@ export function foldBlockComment(node: SyntaxNode): FoldRange {
47 * @param state the editor state 47 * @param state the editor state
48 * @returns the folding range or `null` is there is nothing to fold 48 * @returns the folding range or `null` is there is nothing to fold
49 */ 49 */
50export function foldDeclaration(node: SyntaxNode, state: EditorState): FoldRange | null { 50export function foldDeclaration(
51 node: SyntaxNode,
52 state: EditorState,
53): FoldRange | null {
51 const { firstChild: open, lastChild: close } = node; 54 const { firstChild: open, lastChild: close } = node;
52 if (open === null || close === null) { 55 if (open === null || close === null) {
53 return null; 56 return null;
diff --git a/subprojects/frontend/src/language/indentation.ts b/subprojects/frontend/src/language/indentation.ts
index 1c38637f..0bd2423c 100644
--- a/subprojects/frontend/src/language/indentation.ts
+++ b/subprojects/frontend/src/language/indentation.ts
@@ -1,4 +1,4 @@
1import { TreeIndentContext } from '@codemirror/language'; 1import type { TreeIndentContext } from '@codemirror/language';
2 2
3/** 3/**
4 * Finds the `from` of first non-skipped token, if any, 4 * Finds the `from` of first non-skipped token, if any,
@@ -11,18 +11,16 @@ import { TreeIndentContext } from '@codemirror/language';
11 * @returns the alignment or `null` if there is no token after the opening keyword 11 * @returns the alignment or `null` if there is no token after the opening keyword
12 */ 12 */
13function findAlignmentAfterOpening(context: TreeIndentContext): number | null { 13function findAlignmentAfterOpening(context: TreeIndentContext): number | null {
14 const { 14 const { node: tree, simulatedBreak } = context;
15 node: tree,
16 simulatedBreak,
17 } = context;
18 const openingToken = tree.childAfter(tree.from); 15 const openingToken = tree.childAfter(tree.from);
19 if (openingToken === null) { 16 if (openingToken === null) {
20 return null; 17 return null;
21 } 18 }
22 const openingLine = context.state.doc.lineAt(openingToken.from); 19 const openingLine = context.state.doc.lineAt(openingToken.from);
23 const lineEnd = simulatedBreak == null || simulatedBreak <= openingLine.from 20 const lineEnd =
24 ? openingLine.to 21 simulatedBreak == null || simulatedBreak <= openingLine.from
25 : Math.min(openingLine.to, simulatedBreak); 22 ? openingLine.to
23 : Math.min(openingLine.to, simulatedBreak);
26 const cursor = openingToken.cursor(); 24 const cursor = openingToken.cursor();
27 while (cursor.next() && cursor.from < lineEnd) { 25 while (cursor.next() && cursor.from < lineEnd) {
28 if (!cursor.type.isSkipped) { 26 if (!cursor.type.isSkipped) {
@@ -58,7 +56,10 @@ function findAlignmentAfterOpening(context: TreeIndentContext): number | null {
58 * @param units the number of units to indent 56 * @param units the number of units to indent
59 * @returns the desired indentation level 57 * @returns the desired indentation level
60 */ 58 */
61function indentDeclarationStrategy(context: TreeIndentContext, units: number): number { 59function indentDeclarationStrategy(
60 context: TreeIndentContext,
61 units: number,
62): number {
62 const alignment = findAlignmentAfterOpening(context); 63 const alignment = findAlignmentAfterOpening(context);
63 if (alignment !== null) { 64 if (alignment !== null) {
64 return context.column(alignment); 65 return context.column(alignment);
diff --git a/subprojects/frontend/src/language/problem.grammar b/subprojects/frontend/src/language/problem.grammar
index ac0b0ea3..313df05d 100644
--- a/subprojects/frontend/src/language/problem.grammar
+++ b/subprojects/frontend/src/language/problem.grammar
@@ -1,6 +1,6 @@
1@detectDelim 1@detectDelim
2 2
3@external prop implicitCompletion from '../../../../src/language/props.ts' 3@external prop implicitCompletion from './props'
4 4
5@top Problem { statement* } 5@top Problem { statement* }
6 6
diff --git a/subprojects/frontend/src/language/problemLanguageSupport.ts b/subprojects/frontend/src/language/problemLanguageSupport.ts
index 65fb50dc..246135d8 100644
--- a/subprojects/frontend/src/language/problemLanguageSupport.ts
+++ b/subprojects/frontend/src/language/problemLanguageSupport.ts
@@ -7,9 +7,7 @@ import {
7 LRLanguage, 7 LRLanguage,
8} from '@codemirror/language'; 8} from '@codemirror/language';
9import { styleTags, tags as t } from '@lezer/highlight'; 9import { styleTags, tags as t } from '@lezer/highlight';
10import { LRParser } from '@lezer/lr';
11 10
12import { parser } from '../../build/generated/sources/lezer/problem';
13import { 11import {
14 foldBlockComment, 12 foldBlockComment,
15 foldConjunction, 13 foldConjunction,
@@ -21,8 +19,9 @@ import {
21 indentDeclaration, 19 indentDeclaration,
22 indentPredicateOrRule, 20 indentPredicateOrRule,
23} from './indentation'; 21} from './indentation';
22import { parser } from './problem.grammar';
24 23
25const parserWithMetadata = (parser as LRParser).configure({ 24const parserWithMetadata = parser.configure({
26 props: [ 25 props: [
27 styleTags({ 26 styleTags({
28 LineComment: t.lineComment, 27 LineComment: t.lineComment,
@@ -86,8 +85,6 @@ const problemLanguage = LRLanguage.define({
86 }, 85 },
87}); 86});
88 87
89export function problemLanguageSupport(): LanguageSupport { 88export default function problemLanguageSupport(): LanguageSupport {
90 return new LanguageSupport(problemLanguage, [ 89 return new LanguageSupport(problemLanguage, [indentUnit.of(' ')]);
91 indentUnit.of(' '),
92 ]);
93} 90}
diff --git a/subprojects/frontend/src/language/props.ts b/subprojects/frontend/src/language/props.ts
index 8e488bf5..65392e75 100644
--- a/subprojects/frontend/src/language/props.ts
+++ b/subprojects/frontend/src/language/props.ts
@@ -1,3 +1,5 @@
1/* eslint-disable import/prefer-default-export -- Lezer needs non-default exports */
2
1import { NodeProp } from '@lezer/common'; 3import { NodeProp } from '@lezer/common';
2 4
3export const implicitCompletion = new NodeProp({ 5export const implicitCompletion = new NodeProp({