Skip to content

Revise AST syntax detection in AGTree: Replace Common with multi-syntax support and Unknown fallback #178

@scripthunter7

Description

@scripthunter7

Currently AGTree assigns a single syntax value to AST nodes, choosing from: Common, AdGuard, UblockOrigin, or AdblockPlus. However, this model is not accurate enough for many real-world scenarios.

Problem 1: Incorrect fallback to Common

When a feature-specific detector is disabled (e.g., uBlock syntax detection is turned off), AGTree assigns Common as the syntax.

Example AGTree detects uBlock syntax for the following rule:

foo.com##:matches-path(/foo) .foo

But if the user disables uBO parsing, AGTree sets the syntax to Common, even though the actual syntax is unknown, because the relevant detection step was skipped.
In such cases, the correct value should be Unknown, not Common.

Problem 2: Mixed or ambiguous syntax is forced into Common

For example:

!#if (adguard && !ext_abp)

This expression is valid in AdGuard and uBlock, but AGTree still categorizes it as Common.
However, “common” is not accurate here — the rule is simply compatible with multiple products, but not all.

Proposed solution

Instead of a single enum-like syntax value, the syntax should:

  1. Be an array or a bitflag representing all compatible syntaxes.
    • Example: ["AdGuard", "UblockOrigin"]
  2. Use Unknown when syntax detection could not run or was intentionally skipped.
  3. Remove Common entirely.
    • Whether something is effectively “common” can be inferred automatically if all supported products appear in the syntax list.

Summary

  • syntax = Unknown → detection incomplete or skipped
  • syntax = ["AdGuard", "UblockOrigin"] → compatible with multiple products
  • “Common” no longer exists, because it becomes derivable (all products listed)

This change would significantly improve the accuracy of AGTree’s syntax metadata and allow downstream tools (like AGLint) to reason about compatibility more precisely.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions