lava-oushudb-dt-sql-parser/peg/comment.pegjs

91 lines
1.4 KiB
Plaintext
Raw Normal View History

2018-07-05 11:16:30 +08:00
2018-07-06 16:22:57 +08:00
{
let lines=[];
let isSplit=false;
}
2018-07-05 11:16:30 +08:00
start
= union_stmt:union_stmt
{
2018-07-06 16:22:57 +08:00
return {lines,text:union_stmt};
2018-07-05 11:16:30 +08:00
}
union_stmt
=stmt:
(
words:(!kw_start word:. {return word})*
2018-07-06 16:22:57 +08:00
stmt:(comment:comment {return ''}/quote:quote {return quote}/";" {isSplit=true;return ";"})
{
const text=words.join("")+stmt;
let index=Math.max(lines.length-1,0);
lines[index]=(lines[index]||'')+text;
if(isSplit){
isSplit=false;
lines.push('');
}
return text;
}
2018-07-05 11:16:30 +08:00
)* other:.*
2018-07-06 16:22:57 +08:00
{
const text=stmt.join("")+other.join("")
let index=Math.max(lines.length-1,0);
lines[index]=lines[index]+other.join("");
return text;
}
2018-07-05 11:16:30 +08:00
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;}
)
)
2018-07-06 16:22:57 +08:00
kw_start=KW_SINGLE_LINE_START/KW_MULTI_LINE_START/"\""/"'"/";"
2018-07-05 11:16:30 +08:00
KW_SINGLE_LINE_START = "--";
KW_SINGLE_LINE_END = [\r\n];
KW_MULTI_LINE_START = "/*";
KW_MULTI_LINE_END = "*/";
__ = whitespace*
whitespace
= [ \t\r\n];