用pegjs重写过滤逻辑

This commit is contained in:
HSunboy
2018-07-05 11:16:30 +08:00
parent 6eb8a18c48
commit 152f186a2e
10 changed files with 1099 additions and 9370 deletions

14
peg/build.js Normal file
View 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
View 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];

View File

@ -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 {