用pegjs重写过滤逻辑
This commit is contained in:
14
peg/build.js
Normal file
14
peg/build.js
Normal file
@ -0,0 +1,14 @@
|
||||
const pegjs=require("pegjs");
|
||||
const path=require("path");
|
||||
const fs=require("fs");
|
||||
|
||||
const files=[{
|
||||
source:path.resolve(process.cwd(),"./peg/comment.pegjs") ,
|
||||
target:path.resolve(process.cwd(),"./core/comment.js") ,
|
||||
},{
|
||||
source:path.resolve(process.cwd(),"./peg/nquery.pegjs") ,
|
||||
target:path.resolve(process.cwd(),"./core/astParser.js") ,
|
||||
}];
|
||||
|
||||
const file=fs.readFileSync(files[0].source,{encoding:"utf8"})
|
||||
pegjs.buildParser(file);
|
72
peg/comment.pegjs
Normal file
72
peg/comment.pegjs
Normal file
@ -0,0 +1,72 @@
|
||||
|
||||
|
||||
start
|
||||
= union_stmt:union_stmt
|
||||
{
|
||||
return union_stmt;
|
||||
}
|
||||
|
||||
|
||||
union_stmt
|
||||
=stmt:
|
||||
(
|
||||
words:(!kw_start word:. {return word})*
|
||||
stmt:(comment:comment {return ''}/quote:quote {return quote})
|
||||
{return words.join("")+stmt}
|
||||
)* other:.*
|
||||
{return stmt.join("")+other.join("")}
|
||||
|
||||
comment
|
||||
=comment:(multiLine/singleLine)
|
||||
{
|
||||
return comment;
|
||||
}
|
||||
|
||||
singleLine
|
||||
= start:KW_SINGLE_LINE_START
|
||||
words:[^\r\n]*
|
||||
{
|
||||
return start+words.join("")
|
||||
}
|
||||
|
||||
|
||||
multiLine
|
||||
=start:KW_MULTI_LINE_START
|
||||
words:(!"*/" word:. {return word })*
|
||||
end:KW_MULTI_LINE_END
|
||||
{return start+words.join("")+end }
|
||||
|
||||
quote
|
||||
=content:(
|
||||
(
|
||||
start:"\""
|
||||
words:[^"]*
|
||||
end:"\""
|
||||
{return start+words.join("")+end;}
|
||||
)
|
||||
/
|
||||
(
|
||||
start:"'"
|
||||
words:[^']*
|
||||
end:"'"
|
||||
{return start+words.join("")+end;}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
kw_start=KW_SINGLE_LINE_START/KW_MULTI_LINE_START/"\""/"'"
|
||||
|
||||
|
||||
KW_SINGLE_LINE_START = "--";
|
||||
KW_SINGLE_LINE_END = [\r\n];
|
||||
KW_MULTI_LINE_START = "/*";
|
||||
KW_MULTI_LINE_END = "*/";
|
||||
|
||||
|
||||
__ = whitespace*
|
||||
|
||||
whitespace
|
||||
= [ \t\r\n];
|
@ -160,7 +160,7 @@ start
|
||||
}
|
||||
}
|
||||
|
||||
init = { params = []; return true; }
|
||||
init = & { params = []; return true; }
|
||||
|
||||
union_stmt
|
||||
= head:select_stmt tail:(__ KW_UNION __ select_stmt)* {
|
||||
@ -424,7 +424,7 @@ expr_list
|
||||
|
||||
expr_list_or_empty
|
||||
= l:expr_list
|
||||
/ {
|
||||
/ & {
|
||||
return {
|
||||
type : 'expr_list',
|
||||
value : []
|
||||
@ -931,7 +931,7 @@ proc_stmt
|
||||
}
|
||||
}
|
||||
|
||||
proc_init = { varList = []; return true; }
|
||||
proc_init = & { varList = []; return true; }
|
||||
|
||||
assign_stmt
|
||||
= va:var_decl __ KW_ASSIGN __ e:proc_expr {
|
||||
|
Reference in New Issue
Block a user