mirror of https://github.com/gorhill/uBlock.git
Simplify parser's templating code
This commit is contained in:
parent
033aa9cfad
commit
82c73199e4
|
@ -317,30 +317,30 @@ const astTemplates = {
|
||||||
flags: AST_FLAG_NET_PATTERN_LEFT_HNANCHOR |
|
flags: AST_FLAG_NET_PATTERN_LEFT_HNANCHOR |
|
||||||
AST_FLAG_NET_PATTERN_RIGHT_PATHANCHOR,
|
AST_FLAG_NET_PATTERN_RIGHT_PATHANCHOR,
|
||||||
type: NODE_TYPE_LINE_BODY,
|
type: NODE_TYPE_LINE_BODY,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_RAW,
|
type: NODE_TYPE_NET_RAW,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_PATTERN_RAW,
|
type: NODE_TYPE_NET_PATTERN_RAW,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
register: true,
|
register: true,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_PATTERN_LEFT_HNANCHOR,
|
type: NODE_TYPE_NET_PATTERN_LEFT_HNANCHOR,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromBeg: 2,
|
end: 2,
|
||||||
}, {
|
}, {
|
||||||
type: NODE_TYPE_NET_PATTERN,
|
type: NODE_TYPE_NET_PATTERN,
|
||||||
begFromBeg: 2,
|
beg: 2,
|
||||||
endFromEnd: -1,
|
end: -1,
|
||||||
register: true,
|
register: true,
|
||||||
}, {
|
}, {
|
||||||
type: NODE_TYPE_NET_PATTERN_PART_SPECIAL,
|
type: NODE_TYPE_NET_PATTERN_PART_SPECIAL,
|
||||||
begFromEnd: -1,
|
beg: -1,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
}],
|
}],
|
||||||
}],
|
}],
|
||||||
}],
|
}],
|
||||||
|
@ -351,48 +351,48 @@ const astTemplates = {
|
||||||
AST_FLAG_NET_PATTERN_RIGHT_PATHANCHOR |
|
AST_FLAG_NET_PATTERN_RIGHT_PATHANCHOR |
|
||||||
AST_FLAG_HAS_OPTIONS,
|
AST_FLAG_HAS_OPTIONS,
|
||||||
type: NODE_TYPE_LINE_BODY,
|
type: NODE_TYPE_LINE_BODY,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_RAW,
|
type: NODE_TYPE_NET_RAW,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_PATTERN_RAW,
|
type: NODE_TYPE_NET_PATTERN_RAW,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
register: true,
|
register: true,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_PATTERN_LEFT_HNANCHOR,
|
type: NODE_TYPE_NET_PATTERN_LEFT_HNANCHOR,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromBeg: 2,
|
end: 2,
|
||||||
}, {
|
}, {
|
||||||
type: NODE_TYPE_NET_PATTERN,
|
type: NODE_TYPE_NET_PATTERN,
|
||||||
begFromBeg: 2,
|
beg: 2,
|
||||||
endFromEnd: -13,
|
end: -13,
|
||||||
register: true,
|
register: true,
|
||||||
}, {
|
}, {
|
||||||
type: NODE_TYPE_NET_PATTERN_PART_SPECIAL,
|
type: NODE_TYPE_NET_PATTERN_PART_SPECIAL,
|
||||||
begFromEnd: -13,
|
beg: -13,
|
||||||
endFromEnd: -12,
|
end: -12,
|
||||||
}],
|
}],
|
||||||
}, {
|
}, {
|
||||||
type: NODE_TYPE_NET_OPTIONS_ANCHOR,
|
type: NODE_TYPE_NET_OPTIONS_ANCHOR,
|
||||||
begFromEnd: -12,
|
beg: -12,
|
||||||
endFromEnd: -11,
|
end: -11,
|
||||||
}, {
|
}, {
|
||||||
type: NODE_TYPE_NET_OPTIONS,
|
type: NODE_TYPE_NET_OPTIONS,
|
||||||
begFromEnd: -11,
|
beg: -11,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
register: true,
|
register: true,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_OPTION_RAW,
|
type: NODE_TYPE_NET_OPTION_RAW,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_OPTION_NAME_3P,
|
type: NODE_TYPE_NET_OPTION_NAME_3P,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
register: true,
|
register: true,
|
||||||
}],
|
}],
|
||||||
}],
|
}],
|
||||||
|
@ -403,25 +403,25 @@ const astTemplates = {
|
||||||
netHnAnchoredPlainAscii: {
|
netHnAnchoredPlainAscii: {
|
||||||
flags: AST_FLAG_NET_PATTERN_LEFT_HNANCHOR,
|
flags: AST_FLAG_NET_PATTERN_LEFT_HNANCHOR,
|
||||||
type: NODE_TYPE_LINE_BODY,
|
type: NODE_TYPE_LINE_BODY,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_RAW,
|
type: NODE_TYPE_NET_RAW,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_PATTERN_RAW,
|
type: NODE_TYPE_NET_PATTERN_RAW,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
register: true,
|
register: true,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_PATTERN_LEFT_HNANCHOR,
|
type: NODE_TYPE_NET_PATTERN_LEFT_HNANCHOR,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromBeg: 2,
|
end: 2,
|
||||||
}, {
|
}, {
|
||||||
type: NODE_TYPE_NET_PATTERN,
|
type: NODE_TYPE_NET_PATTERN,
|
||||||
begFromBeg: 2,
|
beg: 2,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
register: true,
|
register: true,
|
||||||
}],
|
}],
|
||||||
}],
|
}],
|
||||||
|
@ -431,21 +431,21 @@ const astTemplates = {
|
||||||
// -resource.
|
// -resource.
|
||||||
netPlainAscii: {
|
netPlainAscii: {
|
||||||
type: NODE_TYPE_LINE_BODY,
|
type: NODE_TYPE_LINE_BODY,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_RAW,
|
type: NODE_TYPE_NET_RAW,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_PATTERN_RAW,
|
type: NODE_TYPE_NET_PATTERN_RAW,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
register: true,
|
register: true,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_PATTERN,
|
type: NODE_TYPE_NET_PATTERN,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
register: true,
|
register: true,
|
||||||
}],
|
}],
|
||||||
}],
|
}],
|
||||||
|
@ -454,25 +454,25 @@ const astTemplates = {
|
||||||
// 127.0.0.1 example.com
|
// 127.0.0.1 example.com
|
||||||
netHosts1: {
|
netHosts1: {
|
||||||
type: NODE_TYPE_LINE_BODY,
|
type: NODE_TYPE_LINE_BODY,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_RAW,
|
type: NODE_TYPE_NET_RAW,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_PATTERN_RAW,
|
type: NODE_TYPE_NET_PATTERN_RAW,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
register: true,
|
register: true,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_IGNORE,
|
type: NODE_TYPE_IGNORE,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromBeg: 10,
|
end: 10,
|
||||||
}, {
|
}, {
|
||||||
type: NODE_TYPE_NET_PATTERN,
|
type: NODE_TYPE_NET_PATTERN,
|
||||||
begFromBeg: 10,
|
beg: 10,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
register: true,
|
register: true,
|
||||||
}],
|
}],
|
||||||
}],
|
}],
|
||||||
|
@ -481,25 +481,25 @@ const astTemplates = {
|
||||||
// 0.0.0.0 example.com
|
// 0.0.0.0 example.com
|
||||||
netHosts2: {
|
netHosts2: {
|
||||||
type: NODE_TYPE_LINE_BODY,
|
type: NODE_TYPE_LINE_BODY,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_RAW,
|
type: NODE_TYPE_NET_RAW,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_NET_PATTERN_RAW,
|
type: NODE_TYPE_NET_PATTERN_RAW,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
register: true,
|
register: true,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_IGNORE,
|
type: NODE_TYPE_IGNORE,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromBeg: 8,
|
end: 8,
|
||||||
}, {
|
}, {
|
||||||
type: NODE_TYPE_NET_PATTERN,
|
type: NODE_TYPE_NET_PATTERN,
|
||||||
begFromBeg: 8,
|
beg: 8,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
register: true,
|
register: true,
|
||||||
}],
|
}],
|
||||||
}],
|
}],
|
||||||
|
@ -508,26 +508,26 @@ const astTemplates = {
|
||||||
// ##.ads-container
|
// ##.ads-container
|
||||||
extPlainGenericSelector: {
|
extPlainGenericSelector: {
|
||||||
type: NODE_TYPE_LINE_BODY,
|
type: NODE_TYPE_LINE_BODY,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_EXT_RAW,
|
type: NODE_TYPE_EXT_RAW,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_EXT_OPTIONS_ANCHOR,
|
type: NODE_TYPE_EXT_OPTIONS_ANCHOR,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromBeg: 2,
|
end: 2,
|
||||||
register: true,
|
register: true,
|
||||||
}, {
|
}, {
|
||||||
type: NODE_TYPE_EXT_PATTERN_RAW,
|
type: NODE_TYPE_EXT_PATTERN_RAW,
|
||||||
begFromBeg: 2,
|
beg: 2,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
register: true,
|
register: true,
|
||||||
children: [{
|
children: [{
|
||||||
type: NODE_TYPE_EXT_PATTERN_COSMETIC,
|
type: NODE_TYPE_EXT_PATTERN_COSMETIC,
|
||||||
begFromBeg: 0,
|
beg: 0,
|
||||||
endFromEnd: 0,
|
end: 0,
|
||||||
}],
|
}],
|
||||||
}],
|
}],
|
||||||
}],
|
}],
|
||||||
|
@ -866,12 +866,8 @@ export class AstFilterParser {
|
||||||
astFromTemplate(parent, template) {
|
astFromTemplate(parent, template) {
|
||||||
const parentBeg = this.nodes[parent+NODE_BEG_INDEX];
|
const parentBeg = this.nodes[parent+NODE_BEG_INDEX];
|
||||||
const parentEnd = this.nodes[parent+NODE_END_INDEX];
|
const parentEnd = this.nodes[parent+NODE_END_INDEX];
|
||||||
const beg = template.begFromBeg !== undefined
|
const beg = template.beg + (template.beg >= 0 ? parentBeg : parentEnd);
|
||||||
? parentBeg + template.begFromBeg
|
const end = template.end + (template.end <= 0 ? parentEnd : parentBeg);
|
||||||
: parentEnd + template.begFromEnd;
|
|
||||||
const end = template.endFromEnd !== undefined
|
|
||||||
? parentEnd + template.endFromEnd
|
|
||||||
: parentBeg + template.endFromBeg;
|
|
||||||
const node = this.allocTypedNode(template.type, beg, end);
|
const node = this.allocTypedNode(template.type, beg, end);
|
||||||
if ( template.register ) {
|
if ( template.register ) {
|
||||||
this.addNodeToRegister(template.type, node);
|
this.addNodeToRegister(template.type, node);
|
||||||
|
|
Loading…
Reference in New Issue