Skip to content
Snippets Groups Projects
Verified Commit cbbcdfff authored by Tamas Gal's avatar Tamas Gal :speech_balloon:
Browse files

Workaround for multiline comments in DETX

parent af58ad14
Branches
Tags v0.16.7
No related merge requests found
...@@ -441,9 +441,7 @@ end ...@@ -441,9 +441,7 @@ end
Create a `Detector` instance from an ASCII IO stream using the DETX specification. Create a `Detector` instance from an ASCII IO stream using the DETX specification.
""" """
function read_detx(io::IO) function read_detx(io::IO)
lines = readlines(io) comments, lines = _split_comments(readlines(io), DETECTOR_COMMENT_PREFIX)
comments = _extract_comments(lines, DETECTOR_COMMENT_PREFIX)
filter!(e->!startswith(e, DETECTOR_COMMENT_PREFIX) && !isempty(strip(e)), lines) filter!(e->!startswith(e, DETECTOR_COMMENT_PREFIX) && !isempty(strip(e)), lines)
...@@ -557,22 +555,39 @@ end ...@@ -557,22 +555,39 @@ end
""" """
function _extract_comments(lines<:Vector{AbstractString}, prefix<:AbstractString) function _split_comments(lines<:Vector{AbstractString}, prefix<:AbstractString)
Returns only the lines which are comments, identified by the `prefix`. The prefix is Returns a tuple of comments and content. Comment lines are identified by the `prefix`.
omitted. The prefix is omitted.
""" """
function _extract_comments(lines::Vector{T}, prefix::T) where {T<:AbstractString} function _split_comments(lines::Vector{T}, prefix::T) where {T<:AbstractString}
comments = String[] comments = String[]
content = String[]
prefix_length = length(prefix) prefix_length = length(prefix)
# Multiline comments are not part of the specification but
# there are DETX containing such (introduced by Jpp).
# This feature is just a workaround until we define proper
# multiline comments for DETX/DATX v6+
multilinemode = false
for line lines for line lines
if multilinemode
if length(findall(raw"\"", line)) == 1
multilinemode = false
end
push!(comments, line)
continue
end
if startswith(line, prefix) if startswith(line, prefix)
comment = strip(line[prefix_length+1:end]) comment = strip(line[prefix_length+1:end])
if length(findall(raw"\"", comment)) == 1
multilinemode = true
end
push!(comments, comment) push!(comments, comment)
end end
push!(content, line)
end end
comments comments, content
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment