mirror of
https://github.com/MontFerret/ferret.git
synced 2025-03-03 15:02:32 +02:00
Fixed parsing escaped new line character (#677)
This commit is contained in:
parent
bd6463fa29
commit
a049f30214
5
e2e/tests/examples/split-new-line.yaml
Normal file
5
e2e/tests/examples/split-new-line.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
timeout: 240
|
||||||
|
query:
|
||||||
|
ref: file://../../../examples/split-new-line.fql
|
||||||
|
assert:
|
||||||
|
text: RETURN T::NOT::EMPTY(@lab.data.query.result)
|
4
examples/split-new-line.fql
Normal file
4
examples/split-new-line.fql
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
LET doc = DOCUMENT('https://github.com/events', {driver: 'cdp'})
|
||||||
|
LET list = ELEMENT(doc, '.footer')[0]
|
||||||
|
LET str = INNER_TEXT(list)
|
||||||
|
RETURN SPLIT(str, "\\n")
|
@ -1121,18 +1121,53 @@ func (v *visitor) visitIntegerLiteral(ctx fql.IIntegerLiteralContext) (core.Expr
|
|||||||
return literals.NewIntLiteral(val), nil
|
return literals.NewIntLiteral(val), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *visitor) visitStringLiteral(c fql.IStringLiteralContext) (core.Expression, error) {
|
func (v *visitor) visitStringLiteral(ctx fql.IStringLiteralContext) (core.Expression, error) {
|
||||||
ctx := c.(*fql.StringLiteralContext)
|
var b strings.Builder
|
||||||
var text string
|
|
||||||
|
|
||||||
strLiteral := ctx.StringLiteral()
|
for _, child := range ctx.GetChildren() {
|
||||||
|
tree := child.(antlr.TerminalNode)
|
||||||
|
sym := tree.GetSymbol()
|
||||||
|
input := sym.GetInputStream()
|
||||||
|
|
||||||
if strLiteral != nil {
|
if input == nil {
|
||||||
text = strLiteral.GetText()
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove extra quotes
|
size := input.Size()
|
||||||
return literals.NewStringLiteral(text[1 : len(text)-1]), nil
|
// skip quotes
|
||||||
|
start := sym.GetStart() + 1
|
||||||
|
stop := sym.GetStop() - 1
|
||||||
|
|
||||||
|
if stop >= size {
|
||||||
|
stop = size - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if start < size && stop < size {
|
||||||
|
for i := start; i <= stop; i++ {
|
||||||
|
c := input.GetText(i, i)
|
||||||
|
|
||||||
|
switch c {
|
||||||
|
case "\\":
|
||||||
|
c2 := input.GetText(i, i+1)
|
||||||
|
|
||||||
|
switch c2 {
|
||||||
|
case "\\n":
|
||||||
|
b.WriteString("\n")
|
||||||
|
case "\\t":
|
||||||
|
b.WriteString("\t")
|
||||||
|
default:
|
||||||
|
b.WriteString(c2)
|
||||||
|
}
|
||||||
|
|
||||||
|
i++
|
||||||
|
default:
|
||||||
|
b.WriteString(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return literals.NewStringLiteral(b.String()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *visitor) visitBooleanLiteral(ctx fql.IBooleanLiteralContext) (core.Expression, error) {
|
func (v *visitor) visitBooleanLiteral(ctx fql.IBooleanLiteralContext) (core.Expression, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user