-
Notifications
You must be signed in to change notification settings - Fork 46
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
[Bug Fix, No Breaking] Rewrite forwardchars!(::TokenStream, ::Integer)
.
#198
base: master
Are you sure you want to change the base?
Conversation
* Bug fix. * Change to use `yaml_1_1_` prefix for YAML 1.1's `forwardchars!`. * Add `yaml_1_2_forwardchars!` for YAML 1.2's `forwardchars!`. * Add some helper functions for `forwardchars!`: * `forwardchar_skip!` * `forwardchar_nobreak!` * `forwardchar_breakline!`
src/scanner.jl
Outdated
yaml_1_1_is_b_specific(c::Char) = c == yaml_1_1_b_line_separator || c == yaml_1_1_b_paragraph_separator | ||
# YAML 1.1 [29] b-generic ::= ( b-carriage-return b-line-feed) | b-carriage-return | b-line-feed | b-next-line | ||
# YAML 1.1 [33] b-ignored-any ::= b-generic | b-specific | ||
function yaml_1_1_forwardchars!(stream::TokenStream, n::Integer=1) |
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.
Thinking again about the design here - do we want to use dispatch? That is, instead of having totally diffeering functions, could we have something like
abstract type YAMLVersion end
struct YAMLV1_1 <: YAMLVersion end
forwardchars!(::YAMLV1_1, stream::TokenStream, n::Integer=1) #...
etc...
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.
Then we can even make a version that doesn't take the first argument, that dispatches to whichever version we want to be the default
Now depends on #225. |
# Advance the stream by k characters. | ||
function forwardchars!(stream::TokenStream, k::Integer=1) | ||
for _ in 1:k | ||
# Advance the stream by a chacater and the index. |
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.
chacater -> character (in a number of places).
src/scanner.jl
Outdated
end | ||
|
||
# Advance the stream by `n` characters. | ||
# YAML 1.2 [28] b-break ::= ( b-carriage-return b-line-feed ) | b-carriage-return | b-line-feed | ||
function forwardchars!(::YAMLVersion{Symbol("1.2")}, stream::TokenStream, n::Integer=1) |
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.
It would be nicer if we could have just one forwardchars!
function for both versions and dispatch on the version where they do differ.
Here we use abstract type & subtyping because it's common traits pattern in Julia. We do not need to export these objects because we can use strings for versions in user-facing functions like: ```julia function load(str::AbstractString; version::YAMLVersion) # ... end function load(str::AbstractString; version::AbstractString) version == "1.1" ? load(str, version=YAMLV1_1()) : version == "1.2" ? load(str, version=YAMLV1_2()) : throw(ErrorException()) end load(str, version="1.1") ```
I made a mistake with the Git operation. |
* Sort out functions. * Add `b-char` for YAML 1.2. * Add comments to `forwardchars!`.
forwardchar_breakline!(stream) | ||
i += 1 | ||
if peek(stream.input) == b_line_feed | ||
i += 1 |
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.
How come V1.1 does a forwardchar_skip!
here but not V1.2?
Where does this one stand? |
yaml_1_1_
prefix for YAML 1.1'sforwardchars!
.yaml_1_2_forwardchars!
for YAML 1.2'sforwardchars!
.forwardchars!
:forwardchar_skip!
forwardchar_nobreak!
forwardchar_breakline!