[Bug Fix, No Breaking] Rewrite forwardchars!(::TokenStream, ::Integer).#198
[Bug Fix, No Breaking] Rewrite forwardchars!(::TokenStream, ::Integer).#198Paalon wants to merge 9 commits intoJuliaData:masterfrom
forwardchars!(::TokenStream, ::Integer).#198Conversation
* 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!`
| 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.
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.
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.
chacater -> character (in a number of places).
|
|
||
| # 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.
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.
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!