Skip to content

[Bug Fix, No Breaking] Rewrite forwardchars!(::TokenStream, ::Integer).#198

Open
Paalon wants to merge 9 commits intoJuliaData:masterfrom
Paalon:y11-forwardchars
Open

[Bug Fix, No Breaking] Rewrite forwardchars!(::TokenStream, ::Integer).#198
Paalon wants to merge 9 commits intoJuliaData:masterfrom
Paalon:y11-forwardchars

Conversation

@Paalon
Copy link
Copy Markdown
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
Comment thread 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
Copy Markdown
Member

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
Copy Markdown
Member

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
Copy Markdown
Contributor Author

Paalon commented Jun 20, 2024

Now depends on #225.

Comment thread src/scanner.jl
# 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
Copy Markdown
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).

Comment thread src/scanner.jl Outdated

# 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
Copy Markdown
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.

Paalon added 2 commits June 21, 2024 15:14
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 Paalon closed this Jun 21, 2024
@Paalon Paalon force-pushed the y11-forwardchars branch from c516939 to b207f14 Compare June 21, 2024 07:12
@Paalon
Copy link
Copy Markdown
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
Comment thread src/scanner.jl
forwardchar_breakline!(stream)
i += 1
if peek(stream.input) == b_line_feed
i += 1
Copy link
Copy Markdown
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
Copy Markdown
Member

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