Merge branch 'master' into sieve-gui

# Conflicts:
#	dev/Sieve/Parser.js
This commit is contained in:
the-djmaze 2024-09-23 11:26:36 +02:00
commit 05bc9a60b1
6 changed files with 30 additions and 10 deletions

View file

@ -45,8 +45,16 @@ export class GrammarString /*extends String*/
/**
* abstract
*/
export class GrammarComment extends GrammarString
export /*abstract*/ class GrammarComment extends GrammarString
{
/*
constructor()
{
if (this.constructor == GrammarComment) {
throw Error("Abstract class can't be instantiated.");
}
}
*/
}
/**

View file

@ -18,6 +18,7 @@ import {
import {
GrammarBracketComment,
GrammarCommand,
GrammarComment,
GrammarHashComment,
GrammarMultiLine,
GrammarNumber,
@ -28,7 +29,7 @@ import {
} from 'Sieve/Grammar';
import { availableCommands } from 'Sieve/Commands';
import { ConditionalCommand, RequireCommand } from 'Sieve/Commands/Controls';
import { ConditionalCommand, IfCommand, RequireCommand } from 'Sieve/Commands/Controls';
import { NotTest } from 'Sieve/Commands/Tests';
const
@ -156,7 +157,17 @@ export const parseScript = (script, name = 'script.sieve') => {
let new_command;
if (Commands[value]) {
if ('elsif' === value || 'else' === value) {
// (prev_command instanceof ConditionalCommand) || error('Not after IF condition');
let valid = false, cmd = (command ? command?.commands : tree), i = cmd?.length;
while (i) {
cmd[--i];
if (cmd[i] instanceof IfCommand) {
valid = true;
break;
} else if (typeof cmd[i] !== 'string' && !(cmd[i] instanceof GrammarComment)) {
break;
}
}
valid || error('Not after IF/ELSIF condition');
}
if ('allof' === value || 'anyof' === value) {
// (command instanceof ConditionalCommand || command instanceof NotTest) || error('Test-list not in conditional');
@ -266,7 +277,6 @@ export const parseScript = (script, name = 'script.sieve') => {
break;
case T_BLOCK_END:
(command instanceof ConditionalCommand) || error(TokenError[type]);
// prev_command = command;
command = levels.up();
break;