Skip to content

Commit

Permalink
Update to support savonet/liquidsoap#3498
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Oct 31, 2023
1 parent 6831896 commit 29ff9e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const LiquidsoapLanguage = LRLanguage.define({
"LabeledArgument/...": t.labelName,
Integer: t.integer,
Float: t.float,
Minus: t.integer,
Regexp: t.regexp,
EscapedChar: t.escape,
Op: t.operatorKeyword,
Expand Down
19 changes: 6 additions & 13 deletions src/liquidsoap.grammar
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@context noUminus from "./tokens.js"

@precedence {
uminus,
blockComment @right
include @left
stringInterpolation @right
Expand Down Expand Up @@ -37,14 +38,6 @@ cop<term> { ControlOperator { Op { term } } }
aop<term> { ArithmeticOperator { Op { term } } }
defined<term> { Defined { term } }

Integer {
uminus? integer
}

Float {
uminus? float
}

Var {
var
}
Expand Down Expand Up @@ -649,7 +642,7 @@ op {
Infix { expr op expr }

Minus {
uminus "(" expr ")"
!uminus uminus expr
}

expr {
Expand Down Expand Up @@ -704,7 +697,7 @@ BlockComment {
}

@external tokens varTok from "./tokens" { var, varLpar, varLbra }
@external tokens floatTok from "./tokens" { float }
@external tokens floatTok from "./tokens" { Float }
@external tokens uminusTok from "./tokens" { uminus }

@tokens {
Expand All @@ -719,8 +712,8 @@ BlockComment {
@precedence { "%include", encoderName }
@precedence { "%include_extra", encoderName }
@precedence { encoderName, bin2 }
@precedence { Version, integer }
@precedence { TimePredicate, integer }
@precedence { Version, Integer }
@precedence { TimePredicate, Integer }
@precedence { regexpContentToken, RegexpEnd }
@precedence { "\"", doubleQuoteStringContentToken }
@precedence { "#{", doubleQuoteStringContentToken }
Expand Down Expand Up @@ -767,7 +760,7 @@ BlockComment {
bin3 {
"/" | "*." | "/." | "*" | "mod"
}
integer {
Integer {
$[0-9] $[0-9_]* | "0" $[xX] $[0-9a-fA-F_]+ | "0" $[oO] $[0-7_]+
}
Version {
Expand Down
15 changes: 9 additions & 6 deletions src/tokens.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExternalTokenizer, ContextTracker } from "@lezer/lr";
import { _var, varLpar, varLbra, uminus, float } from "./parser.terms.js";
import { _var, varLpar, varLbra, uminus, Float } from "./parser.terms.js";

const whiteSpace = /[ \t]/;

Expand Down Expand Up @@ -29,7 +29,7 @@ const keywords = [
"or",
"mod",
"true",
"false"
"false",
];

export const noUminus = new ContextTracker({
Expand Down Expand Up @@ -152,7 +152,7 @@ export const floatTok = new ExternalTokenizer((input, stack) => {

if (hasPrefix && whiteSpace.test(String.fromCharCode(input.peek(1)))) {
stack.context.disabled = true;
input.acceptToken(float);
input.acceptToken(Float);
return;
}

Expand All @@ -175,7 +175,7 @@ export const floatTok = new ExternalTokenizer((input, stack) => {
}

stack.context.disabled = true;
input.acceptToken(float);
input.acceptToken(Float);
return;
});

Expand All @@ -188,8 +188,11 @@ export const uminusTok = new ExternalTokenizer(
prev = input.peek(pos);
}

if (String.fromCharCode(prev) === ")") stack.context.disabled = true;
if (/[,=(]/.test(String.fromCharCode(prev))) stack.context.disabled = false;
if (["}", ")"].includes(String.fromCharCode(prev)))
stack.context.disabled = true;
if (/[0-9]/.test(String.fromCharCode(prev))) stack.context.disabled = true;
if (/[,=(.+-/*]/.test(String.fromCharCode(prev)))
stack.context.disabled = false;
if (keywords.includes(previousKeyword(input, 0)))
stack.context.disabled = false;

Expand Down

0 comments on commit 29ff9e3

Please sign in to comment.