From c4332ffb9d1d07483bb7804d66f675452d84918b Mon Sep 17 00:00:00 2001 From: Hare Date: Thu, 9 Jul 2026 00:38:31 +0900 Subject: [PATCH] Restore CodeMirror syntax highlighting --- editors/lezer-decodal/decodal.grammar | 152 +++++++++--------- .../src/lib/codemirror/decodal-parser.js | 14 +- .../lib/codemirror/decodal-parser.terms.js | 108 +++++++++---- .../src/lib/codemirror/decodal.js | 24 +-- 4 files changed, 170 insertions(+), 128 deletions(-) diff --git a/editors/lezer-decodal/decodal.grammar b/editors/lezer-decodal/decodal.grammar index 8914d3b..3e225fe 100644 --- a/editors/lezer-decodal/decodal.grammar +++ b/editors/lezer-decodal/decodal.grammar @@ -1,35 +1,35 @@ @top Source { Statement* } Statement { - FieldDefinition semicolon? | - Expression semicolon? + FieldDefinition Semicolon? | + Expression Semicolon? } Expression { DefaultExpression } DefaultExpression { PatchExpression | - PatchExpression !default default DefaultExpression + PatchExpression !default Default DefaultExpression } PatchExpression { ComposeExpression | - PatchExpression !patch slashSlash ComposeExpression + PatchExpression !patch SlashSlash ComposeExpression } ComposeExpression { LogicalOrExpression | - ComposeExpression !compose amp LogicalOrExpression + ComposeExpression !compose Amp LogicalOrExpression } LogicalOrExpression { LogicalAndExpression | - LogicalOrExpression !or pipePipe LogicalAndExpression + LogicalOrExpression !or PipePipe LogicalAndExpression } LogicalAndExpression { ComparisonExpression | - LogicalAndExpression !and ampAmp ComparisonExpression + LogicalAndExpression !and AmpAmp ComparisonExpression } ComparisonExpression { @@ -39,36 +39,36 @@ ComparisonExpression { ConcatExpression { AdditiveExpression | - ConcatExpression !concat plusPlus AdditiveExpression + ConcatExpression !concat PlusPlus AdditiveExpression } AdditiveExpression { MultiplicativeExpression | - AdditiveExpression !add (plus | minus) MultiplicativeExpression + AdditiveExpression !add (Plus | Minus) MultiplicativeExpression } MultiplicativeExpression { UnaryExpression | - MultiplicativeExpression !multiply (star | slash) UnaryExpression + MultiplicativeExpression !multiply (Star | Slash) UnaryExpression } UnaryExpression { PostfixExpression | - (bang | minus) !unary UnaryExpression + (Bang | Minus) !unary UnaryExpression } PostfixExpression { PrimaryExpression | PostfixExpression !call CallSuffix | - PostfixExpression !path dot identifier + PostfixExpression !path Dot Identifier } -CallSuffix { lParen ArgumentList? rParen } -ArgumentList { Expression (comma Expression)* comma? } +CallSuffix { LParen ArgumentList? RParen } +ArgumentList { Expression (Comma Expression)* Comma? } PrimaryExpression { Literal | - identifier | + Identifier | ComparisonConstraint | Object | Array | @@ -76,31 +76,31 @@ PrimaryExpression { FunctionExpression | MatchExpression | ImportExpression | - lParen Expression rParen + LParen Expression RParen } -Literal { string | integer | float | true | false | regex } -CompareOperator { equalEqual | bangEqual | lt | lte | gt | gte } -ComparisonConstraint { (lt | lte | gt | gte) Expression } +Literal { String | Integer | Float | True | False | Regex } +CompareOperator { EqualEqual | BangEqual | Lt | Lte | Gt | Gte } +ComparisonConstraint { (Lt | Lte | Gt | Gte) Expression } -Object { lBrace (FieldDefinition (semicolon FieldDefinition)* semicolon?)? rBrace } -FieldDefinition { FieldPath equal Expression } -FieldPath { identifier !fieldPath (dot identifier)* } +Object { LBrace (FieldDefinition (Semicolon FieldDefinition)* Semicolon?)? RBrace } +FieldDefinition { FieldPath Equal Expression } +FieldPath { Identifier !fieldPath (Dot Identifier)* } -Array { lBracket (Expression (comma Expression)* comma?)? rBracket } +Array { LBracket (Expression (Comma Expression)* Comma?)? RBracket } -LetExpression { let FieldDefinitionList in Expression } -FieldDefinitionList { (FieldDefinition semicolon)* } +LetExpression { Let FieldDefinitionList In Expression } +FieldDefinitionList { (FieldDefinition Semicolon)* } -FunctionExpression { lParen ParameterList? rParen arrow Expression } -ParameterList { Parameter (comma Parameter)* comma? } -Parameter { identifier colon Expression } +FunctionExpression { LParen ParameterList? RParen Arrow Expression } +ParameterList { Parameter (Comma Parameter)* Comma? } +Parameter { Identifier Colon Expression } -MatchExpression { match Expression lBrace (MatchArm (semicolon MatchArm)* semicolon?)? rBrace } -MatchArm { Pattern colon Expression } -Pattern { underscore | Expression } +MatchExpression { Match Expression LBrace (MatchArm (Semicolon MatchArm)* Semicolon?)? RBrace } +MatchArm { Pattern Colon Expression } +Pattern { Underscore | Expression } -ImportExpression { import string } +ImportExpression { Import String } @precedence { fieldPath @left, @@ -119,54 +119,54 @@ ImportExpression { import string } } @tokens { - let { "let" } - in { "in" } - match { "match" } - import { "import" } - default { "default" } - true { "true" } - false { "false" } + Let { "let" } + In { "in" } + Match { "match" } + Import { "import" } + Default { "default" } + True { "true" } + False { "false" } - identifier { $[A-Za-z_] $[A-Za-z0-9_]* } - integer { $[0-9]+ } - float { $[0-9]+ "." $[0-9]+ } - string { '"' (!["\\\n] | "\\" _)* '"' } - regex { "/" (![/\\\n] | "\\" _)+ "/" } - comment { "#" ![\n]* } + Identifier { $[A-Za-z_] $[A-Za-z0-9_]* } + Integer { $[0-9]+ } + Float { $[0-9]+ "." $[0-9]+ } + String { '"' (!["\\\n] | "\\" _)* '"' } + Regex { "/" (![/\\\n] | "\\" _)+ "/" } + Comment { "#" ![\n]* } - lBrace { "{" } - rBrace { "}" } - lBracket { "[" } - rBracket { "]" } - lParen { "(" } - rParen { ")" } - semicolon { ";" } - comma { "," } - dot { "." } - colon { ":" } - equal { "=" } - equalEqual { "==" } - bang { "!" } - bangEqual { "!=" } - arrow { "=>" } - amp { "&" } - ampAmp { "&&" } - pipePipe { "||" } - plus { "+" } - plusPlus { "++" } - minus { "-" } - star { "*" } - slash { "/" } - slashSlash { "//" } - gt { ">" } - gte { ">=" } - lt { "<" } - lte { "<=" } - underscore { "_" } + LBrace { "{" } + RBrace { "}" } + LBracket { "[" } + RBracket { "]" } + LParen { "(" } + RParen { ")" } + Semicolon { ";" } + Comma { "," } + Dot { "." } + Colon { ":" } + Equal { "=" } + EqualEqual { "==" } + Bang { "!" } + BangEqual { "!=" } + Arrow { "=>" } + Amp { "&" } + AmpAmp { "&&" } + PipePipe { "||" } + Plus { "+" } + PlusPlus { "++" } + Minus { "-" } + Star { "*" } + Slash { "/" } + SlashSlash { "//" } + Gt { ">" } + Gte { ">=" } + Lt { "<" } + Lte { "<=" } + Underscore { "_" } whitespace { @whitespace+ } - @precedence { let, in, match, import, default, true, false, float, integer, underscore, identifier } + @precedence { Let, In, Match, Import, Default, True, False, Float, Integer, Underscore, Identifier } } -@skip { whitespace | comment } +@skip { whitespace | Comment } diff --git a/site/decodal-site/src/lib/codemirror/decodal-parser.js b/site/decodal-site/src/lib/codemirror/decodal-parser.js index f4d9533..be2ffbe 100644 --- a/site/decodal-site/src/lib/codemirror/decodal-parser.js +++ b/site/decodal-site/src/lib/codemirror/decodal-parser.js @@ -2,15 +2,15 @@ import {LRParser} from "@lezer/lr" export const parser = LRParser.deserialize({ version: 14, - states: "7vQYQPOOO#nQPO'#C`OOQO'#Cn'#CnO$wQPO'#CoO&UQPO'#CpO&^QPO'#CqO&eQPO'#CrO&mQPO'#CmO$wQPO'#CwO&wQPO'#CzOOQO'#Cm'#CmOOQO'#Cl'#ClO&|QPO'#CkO$wQPO'#CkOOQO'#Cj'#CjO)fQPO'#CiO.XQPO'#ChO0]QPO'#CgOOQO'#Cf'#CfO2TQPO'#CeO3xQPO'#CdO5jQPO'#CcO7UQPO'#CbOOQO'#Ca'#CaO7`QPO'#C_O7eQPO'#C^OOQO'#DO'#DOQYQPOOO8xQPO'#DPO8}QPO,58zOOQO,59Z,59ZO9VQPO'#C`OOQO,59[,59[O9_QPO,59[OOQO,59],59]O9gQPO,59]O9oQPO'#DSO9tQPO'#CsO9|QPO,59^O:RQPO'#CmO:`QPO'#CuO:hQQO,59`O:mQPO,59`O:rQPO,59XO:wQPO,59cOOQO,59f,59fO:|QPO'#C{OOQO,59W,59WO;TQPO,59WOOQO,59V,59VO$wQPO,59UO$wQPO,59TO$wQPO,59SOOQO'#C}'#C}O$wQPO,59RO$wQPO,59QO$wQPO,59PO$wQPO,59OO$wQPO,58}O$wQPO,58|O$wQPO,58yOOQO,58x,58xOOQO-E6|-E6|OOQO,59k,59kOOQO-E6}-E6}O;YQPO1G.vO;bQPO1G.vOOQO1G.v1G.vO;jQPO1G.wO;qQPO1G.wOOQO1G.w1G.wOOQO,59n,59nOOQO-E7Q-E7QO$wQPO1G.xO$wQPO,59bO;yQPO,59aOZAN>ZOJeQPOAN>ZOOQO-E8O-E8OOOQOG23uG23uP context.column(context.node.from) + context.unit,