How can I parse a quoted string with Parsers.jl

Viewed 64

Julia’s CSV.jl parses csv files with quoted strings. It uses Parsers.jl to do this. Yet from the documentation of Parsers.jl it is not clear how to parse a double-quoted string on its own. How would I do that? As a secondary question, what is the supported set of escape sequences that Parsers.jl uses?

1 Answers

You can pass arbitrary characters to indicate quotation and escape characters via Parsers.Options. For example,

using Parsers

str = "{-1}"
oq, cq, e = UInt8('{'), UInt8('}'), UInt8('\\')

res = Parsers.xparse(Int64, str; openquotechar=oq, closequotechar=cq, escapechar=e)
x, code, tlen = res.val, res.code, res.tlen
print(x)
Related