Autocomplete, and more CM stuff!

This commit is contained in:
Gregory Schier
2023-02-28 22:54:54 -08:00
parent 1e57890d2e
commit 5040d73a8b
20 changed files with 220 additions and 178 deletions

View File

@@ -1,43 +1,16 @@
import { parser } from './url';
// import { foldNodeProp, foldInside, indentNodeProp } from '@codemirror/language';
import { styleTags, tags as t } from '@lezer/highlight';
import { LanguageSupport, LRLanguage } from '@codemirror/language';
import { completeFromList } from '@codemirror/autocomplete';
const parserWithMetadata = parser.configure({
props: [
styleTags({
Protocol: t.comment,
Port: t.attributeName,
Host: t.variableName,
PathSegment: t.bool,
Slash: t.bool,
Question: t.attributeName,
QueryName: t.attributeName,
QueryValue: t.attributeName,
Amp: t.comment,
Equal: t.comment,
}),
// indentNodeProp.add({
// Application: (context) => context.column(context.node.from) + context.unit,
// }),
// foldNodeProp.add({
// Application: foldInside,
// }),
],
});
import { LanguageSupport, LRLanguage } from '@codemirror/language';
import { parser } from './url';
const urlLanguage = LRLanguage.define({
parser: parserWithMetadata,
languageData: {
// commentTokens: {line: ";"}
},
parser,
languageData: {},
});
const exampleCompletion = urlLanguage.data.of({
autocomplete: completeFromList([
{ label: 'http://', type: 'keyword' },
{ label: 'https://', type: 'keyword' },
{ label: 'http://', type: 'constant' },
{ label: 'https://', type: 'constant' },
]),
});

View File

@@ -0,0 +1,9 @@
import { styleTags, tags as t } from '@lezer/highlight';
export const highlight = styleTags({
Protocol: t.comment,
Port: t.attributeName,
Host: t.variableName,
Path: t.bool,
Query: t.string,
});

View File

@@ -1,29 +1,18 @@
@top url { Protocol Host Port? Path Query }
Protocol {
"http://" | "https://"
}
Path {
(Slash PathSegment)*
}
@top url { Protocol? Host Port? Path? Query? }
Query {
Question (QueryPair)*
}
QueryPair {
Amp? QueryName Equal QueryValue
"?" queryPair ("&" queryPair)*
}
@tokens {
Protocol { $[a-zA-Z]+ "://" }
Path { ("/" $[a-zA-Z0-9\-_.]*)+ }
queryPair { ($[a-zA-Z0-9]+ ("=" $[a-zA-Z0-9]*)?) }
Port { ":" $[0-9]+ }
Host { $[a-zA-Z0-9-_.]+ }
QueryName { $[a-zA-Z0-9-_.]+ }
QueryValue { $[a-zA-Z0-9-_./]+ }
PathSegment { $[a-zA-Z0-9-_.]+ }
Slash { "/" }
Question { "?" }
Equal { "=" }
Amp { "&" }
// Protocol/host overlaps, so give proto explicit precedence
@precedence { Protocol, Host }
}
@external propSource highlight from "./highlight"

View File

@@ -5,12 +5,4 @@ export const
Host = 3,
Port = 4,
Path = 5,
Slash = 6,
PathSegment = 7,
Query = 8,
Question = 9,
QueryPair = 10,
Amp = 11,
QueryName = 12,
Equal = 13,
QueryValue = 14
Query = 6

View File

@@ -1,16 +1,18 @@
// This file was generated by lezer-generator. You probably shouldn't edit it.
import {LRParser} from "@lezer/lr"
import {highlight} from "./highlight"
export const parser = LRParser.deserialize({
version: 14,
states: "#xOQOPOOOOOO'#C^'#C^OYOQOOO_OPOOOjOSO'#CkOoOPO'#CaOwOPOOObOPOOOOOO,59V,59VOOOO-E6i-E6iO|OWO'#CdQOOOOOO!XOPO'#CfO!^OWO'#CfOOOO'#Cl'#ClO!cOWO,59OO!nO`O,59QO!sOPO,59QOOOO-E6j-E6jOOOO1G.l1G.lO!xO`O1G.lOOOO7+$W7+$W",
stateData: "!}~ObPOcPO~ORRO~OSVOUSOXTP~OVWO~OUSOXTX~OXYO~OZ]O[[OaWX~O]`O~O[aO~OZ]O[[OaWa~O^cO~O]dO~O^eO~O",
goto: "}aPPbPPePPiPlPPPPpwRQOTURVRZUT^Y_STRVRXTQ_YRb_",
nodeNames: "⚠ url Protocol Host Port Path Slash PathSegment Query Question QueryPair Amp QueryName Equal QueryValue",
maxTerm: 19,
states: "!jOQOPOOQYOPOOOTOPOOOeOQO'#CbQOOOOOQ`OPOOQ]OPOOOjOPO,58|OrOQO'#CcOwOPO1G.hOOOO,58},58}OOOO-E6a-E6a",
stateData: "!S~OQQORPO~OSUOTTOXRO~OYVO~OZWOWUa~OYYO~OZWOWUi~OQR~",
goto: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