-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make Parsers a weakdep #78
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module ParsersExt | ||
using Parsers | ||
using InlineStrings: InlineString, InlineString1, addcodeunit | ||
|
||
Parsers.xparse(::Type{T}, buf::AbstractString, pos, len, options, ::Type{S}=T) where {T <: InlineString, S} = | ||
Parsers.xparse(T, codeunits(buf), pos, len, options, S) | ||
|
||
function Parsers.xparse(::Type{T}, source::Union{AbstractVector{UInt8}, IO}, pos, len, options::Parsers.Options, ::Type{S}=T) where {T <: InlineString, S} | ||
res = Parsers.xparse(String, source, pos, len, options, PosLen) | ||
code = res.code | ||
overflowed = false | ||
poslen = res.val | ||
if !Parsers.valueok(code) || Parsers.sentinel(code) | ||
x = T() | ||
else | ||
poslen = res.val | ||
if T === InlineString1 | ||
if poslen.len != 1 | ||
overflowed = true | ||
x = T() | ||
else | ||
Parsers.fastseek!(source, poslen.pos) | ||
x = InlineString1(Parsers.peekbyte(source, poslen.pos)) | ||
Parsers.fastseek!(source, pos + res.tlen - 1) | ||
end | ||
elseif Parsers.escapedstring(code) || !(source isa AbstractVector{UInt8}) | ||
if poslen.len > (sizeof(T) - 1) | ||
overflowed = true | ||
x = T() | ||
else | ||
# manually build up InlineString | ||
i = poslen.pos | ||
maxi = i + poslen.len | ||
x = T() | ||
Parsers.fastseek!(source, i - 1) | ||
while i < maxi | ||
b = Parsers.peekbyte(source, i) | ||
if b == options.e | ||
i += 1 | ||
Parsers.incr!(source) | ||
b = Parsers.peekbyte(source, i) | ||
end | ||
x, overflowed = addcodeunit(x, b) | ||
i += 1 | ||
Parsers.incr!(source) | ||
end | ||
Parsers.fastseek!(source, maxi) | ||
end | ||
else | ||
vlen = poslen.len | ||
if vlen > (sizeof(T) - 1) | ||
# @show T, vlen, sizeof(T) | ||
overflowed = true | ||
x = T() | ||
else | ||
# @show poslen.pos, vlen | ||
x = T(source, poslen.pos, vlen) | ||
end | ||
end | ||
end | ||
if overflowed | ||
code |= Parsers.OVERFLOW | ||
end | ||
return Parsers.Result{S}(code, res.tlen, x) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question for my own edification, not really related to the PR: If two packages (say InlineStrings and SaxophoneHorse) have extensions for Parsers, both call their extension module
ParsersExt
, and you load InlineStrings, SaxophoneHorse, and Parsers, what happens? That is, does the convention of naming an extension module<main package><weakdep>Ext
provide functional disambiguation or is it more for the benefit of the human?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind, mostly answered my own question. Extension modules having the same name doesn't cause any issues, so I suppose the naming convention is more for the human's benefit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they have different UUID so the loading system can distinguish them.