diff --git a/src/parsing/proto_options.jl b/src/parsing/proto_options.jl index bdcd4ca..fab7440 100644 --- a/src/parsing/proto_options.jl +++ b/src/parsing/proto_options.jl @@ -15,9 +15,13 @@ function _parse_option_value(ps) # TODO: proper value parsing with validation str_val = val(readtoken(ps)) # C-style string literals spanning multiple lines if nk == Tokens.STRING_LIT && nnk == Tokens.STRING_LIT + iob = IOBuffer() + write(iob, str_val) while peekkind(ps) == Tokens.STRING_LIT - str_val = string(@view(str_val[begin:end-1]), val(readtoken(ps))) + seek(iob, position(iob) - 1) + write(iob, @view(val(readtoken(ps))[begin+1:end])) end + str_val = String(take!(iob)) end return has_minus ? string("-", str_val) : str_val end @@ -94,4 +98,4 @@ function _parse_option!(ps::ParserState, options::Dict{String,Union{String,Dict{ options[option_name] = _parse_option_value(ps) end return nothing -end \ No newline at end of file +end diff --git a/test/test_parser.jl b/test/test_parser.jl index f898cae..7a98b96 100644 --- a/test/test_parser.jl +++ b/test/test_parser.jl @@ -146,6 +146,26 @@ end @test p.definitions["A"].fields[1].type.reference_type == Parsers.MESSAGE end + @testset "Single nested non-empty message proto file with default value" begin + s, p, ctx = translate_simple_proto("message A { optional string a = 1 [ default = \"b\" ]; }") + + @test haskey(p.definitions, "A") + @test p.definitions["A"] isa Parsers.MessageType + @test p.definitions["A"].fields[1].name == "a" + @test p.definitions["A"].fields[1].type isa Parsers.StringType + @test p.definitions["A"].fields[1].options["default"] == "\"b\"" + end + + @testset "Single nested non-empty message proto file with default value on several lines" begin + s, p, ctx = translate_simple_proto("message A { optional string a = 1 [ default = \"b;\"\n\t\"\"\n\t\"c\" ]; }") + + @test haskey(p.definitions, "A") + @test p.definitions["A"] isa Parsers.MessageType + @test p.definitions["A"].fields[1].name == "a" + @test p.definitions["A"].fields[1].type isa Parsers.StringType + @test p.definitions["A"].fields[1].options["default"] == "\"b;c\"" + end + @testset "Single self-referential message proto file" begin s, p, ctx = translate_simple_proto("message A { optional A a = 1; }")