mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 11:37:02 +03:00
Minor improvements
This commit is contained in:
@@ -44,6 +44,9 @@ export enum SkipRuleOperator {
|
|||||||
|
|
||||||
const SKIP_RULE_ATTRIBUTES = Object.values(SkipRuleAttribute);
|
const SKIP_RULE_ATTRIBUTES = Object.values(SkipRuleAttribute);
|
||||||
const SKIP_RULE_OPERATORS = Object.values(SkipRuleOperator);
|
const SKIP_RULE_OPERATORS = Object.values(SkipRuleOperator);
|
||||||
|
const WORD_EXTRA_CHARACTER = /[a-zA-Z0-9.]/;
|
||||||
|
const OPERATOR_EXTRA_CHARACTER = /[<>=!~*&|-]/;
|
||||||
|
const ANY_EXTRA_CHARACTER = /[a-zA-Z0-9<>=!~*&|.-]/;
|
||||||
|
|
||||||
export interface AdvancedSkipCheck {
|
export interface AdvancedSkipCheck {
|
||||||
kind: "check";
|
kind: "check";
|
||||||
@@ -436,7 +439,7 @@ class Lexer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type !== null) {
|
if (type !== null) {
|
||||||
const more = kind == "operator" ? /[<>=!~*&|-]/ : kind == "word" ? /[a-zA-Z0-9.]/ : /[a-zA-Z0-9<>=!~*&|.-]/;
|
const more = kind == "operator" ? OPERATOR_EXTRA_CHARACTER : kind == "word" ? WORD_EXTRA_CHARACTER : ANY_EXTRA_CHARACTER;
|
||||||
|
|
||||||
let c = this.peek();
|
let c = this.peek();
|
||||||
let error = false;
|
let error = false;
|
||||||
@@ -589,7 +592,7 @@ class Lexer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Consume common characters up to a space for a more useful value in the error token
|
// Consume common characters up to a space for a more useful value in the error token
|
||||||
const common = /[a-zA-Z0-9<>=!~*&|.-]/;
|
const common = ANY_EXTRA_CHARACTER;
|
||||||
c = this.peek();
|
c = this.peek();
|
||||||
while (c !== null && common.test(c)) {
|
while (c !== null && common.test(c)) {
|
||||||
this.consume();
|
this.consume();
|
||||||
@@ -749,7 +752,7 @@ class Parser {
|
|||||||
this.erroring = false;
|
this.erroring = false;
|
||||||
const rule = this.parseRule();
|
const rule = this.parseRule();
|
||||||
|
|
||||||
if (!this.erroring) {
|
if (!this.erroring && rule) {
|
||||||
this.rules.push(rule);
|
this.rules.push(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -761,7 +764,7 @@ class Parser {
|
|||||||
return { rules: this.rules, errors: this.errors, };
|
return { rules: this.rules, errors: this.errors, };
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseRule(): AdvancedSkipRule {
|
private parseRule(): AdvancedSkipRule | null {
|
||||||
const rule: AdvancedSkipRule = {
|
const rule: AdvancedSkipRule = {
|
||||||
predicate: null,
|
predicate: null,
|
||||||
skipOption: null,
|
skipOption: null,
|
||||||
@@ -796,11 +799,11 @@ class Parser {
|
|||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
private parsePredicate(): AdvancedSkipPredicate {
|
private parsePredicate(): AdvancedSkipPredicate | null {
|
||||||
return this.parseOr();
|
return this.parseOr();
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseOr(): AdvancedSkipPredicate {
|
private parseOr(): AdvancedSkipPredicate | null {
|
||||||
let left = this.parseAnd();
|
let left = this.parseAnd();
|
||||||
|
|
||||||
while (this.match(["or"])) {
|
while (this.match(["or"])) {
|
||||||
@@ -816,7 +819,7 @@ class Parser {
|
|||||||
return left;
|
return left;
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseAnd(): AdvancedSkipPredicate {
|
private parseAnd(): AdvancedSkipPredicate | null {
|
||||||
let left = this.parsePrimary();
|
let left = this.parsePrimary();
|
||||||
|
|
||||||
while (this.match(["and"])) {
|
while (this.match(["and"])) {
|
||||||
@@ -832,7 +835,7 @@ class Parser {
|
|||||||
return left;
|
return left;
|
||||||
}
|
}
|
||||||
|
|
||||||
private parsePrimary(): AdvancedSkipPredicate {
|
private parsePrimary(): AdvancedSkipPredicate | null {
|
||||||
if (this.match(["("])) {
|
if (this.match(["("])) {
|
||||||
const predicate = this.parsePredicate();
|
const predicate = this.parsePredicate();
|
||||||
this.expect([")"], "expected `)` after condition", true);
|
this.expect([")"], "expected `)` after condition", true);
|
||||||
@@ -842,7 +845,7 @@ class Parser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseCheck(): AdvancedSkipCheck {
|
private parseCheck(): AdvancedSkipCheck | null {
|
||||||
this.expect(SKIP_RULE_ATTRIBUTES, `expected attribute after \`${this.previous.type}\``, true);
|
this.expect(SKIP_RULE_ATTRIBUTES, `expected attribute after \`${this.previous.type}\``, true);
|
||||||
|
|
||||||
if (this.erroring) {
|
if (this.erroring) {
|
||||||
|
|||||||
Reference in New Issue
Block a user