Skip to content

Commit

Permalink
Better.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed May 19, 2024
1 parent 243ed78 commit a10d5ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
9 changes: 1 addition & 8 deletions src/liquidsoap.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,9 @@ ContentArgType {
String |
Integer |
Float |
ExpFloat |
Var "=" Var |
Var "=" String |
Var "=" Integer |
Var "=" ExpFloat |
Var "=" Float
}

Expand Down Expand Up @@ -461,7 +459,7 @@ IfEncoder {
}

IfVersion {
kw<"%ifversion"> (cop<"=="> | cop<">="> | cop<"<="> | cop<">"> | cop<"<">) (Integer | ExpFloat | Float | Version) exprs (kw<"%else"> exprs)? kw<"%endif">
kw<"%ifversion"> (cop<"=="> | cop<">="> | cop<"<="> | cop<">"> | cop<"<">) (Integer | Float | Version) exprs (kw<"%else"> exprs)? kw<"%endif">
}

innerListSpread {
Expand Down Expand Up @@ -669,7 +667,6 @@ expr {
Not |
Bool |
Float |
ExpFloat |
Minus |
String |
Var |
Expand Down Expand Up @@ -728,7 +725,6 @@ BlockComment {
@precedence { "%include_extra", encoderName }
@precedence { encoderName, bin2 }
@precedence { Version, Integer }
@precedence { ExpFloat, Integer }
@precedence { TimePredicate, Integer }
@precedence { TimeInterval, TimePredicate }
@precedence { TimeInterval, Integer }
Expand Down Expand Up @@ -781,9 +777,6 @@ BlockComment {
Integer {
$[0-9] $[0-9_]* | "0" $[xX] $[0-9a-fA-F_]+ | "0" $[oO] $[0-7_]+
}
ExpFloat {
$[0-9] $[eE] $[-+]? $[0-9] $[0-9_]*
}
Version {
$[0-9] $[0-9_]* "." $[0-9] $[0-9_]* "." $[0-9] $[0-9_]*
}
Expand Down
22 changes: 22 additions & 0 deletions src/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@ export const varTok = new ExternalTokenizer((input, stack) => {
input.acceptToken(_var);
});

const floatOptExp = (input, stack) => {
let next = input.advance();
if (String.fromCharCode(next) === "-" || String.fromCharCode(next) === "+")
next = input.advance();

if (!/[0-9_]/.test(String.fromCharCode(next))) return;

next = input.advance();
while (/[0-9_]/.test(String.fromCharCode(next))) {
next = input.advance();
}

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

export const floatTok = new ExternalTokenizer((input, stack) => {
let { next } = input;
let hasPrefix = false;
Expand All @@ -146,6 +162,9 @@ export const floatTok = new ExternalTokenizer((input, stack) => {
}
}

if (String.fromCharCode(next) === "e" || String.fromCharCode(next) === "E")
return floatOptExp(input, stack);

if (String.fromCharCode(next) !== ".") {
return;
}
Expand All @@ -164,6 +183,9 @@ export const floatTok = new ExternalTokenizer((input, stack) => {
next = input.advance();
}

if (String.fromCharCode(next) === "e" || String.fromCharCode(next) === "E")
return floatOptExp(input, stack);

let pos = 0;
next = input.peek(pos);

Expand Down

0 comments on commit a10d5ea

Please sign in to comment.