Skip to content
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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Paalon
Copy link
Contributor

@Paalon Paalon commented Jun 17, 2024

  • Bug fix. Current implementation is broken but doesn't fail tests fortunately (or unfortunately?).
  • 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!

* 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!`
@kescobo kescobo added the bug label Jun 18, 2024
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)
Copy link
Collaborator

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...

Copy link
Collaborator

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

@Paalon
Copy link
Contributor Author

Paalon commented Jun 20, 2024

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.
Copy link
Contributor

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)
Copy link
Contributor

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")
```
@Paalon
Copy link
Contributor Author

Paalon commented Jun 21, 2024

I made a mistake with the Git operation.

@Paalon Paalon reopened this Jun 21, 2024
@Paalon Paalon mentioned this pull request Jun 22, 2024
forwardchar_breakline!(stream)
i += 1
if peek(stream.input) == b_line_feed
i += 1
Copy link
Contributor

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?

@kescobo
Copy link
Collaborator

kescobo commented Jun 25, 2024

Where does this one stand?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants