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

Scanner for YAML 1.2 #187

Open
Paalon opened this issue Jun 15, 2024 · 3 comments
Open

Scanner for YAML 1.2 #187

Paalon opened this issue Jun 15, 2024 · 3 comments

Comments

@Paalon
Copy link
Contributor

Paalon commented Jun 15, 2024

YAML.jl v0.4.10 scanner is specific to YAML v1.1. Therefore we'll need the following modules to support YAML v1.2 #186:

# YAML_1_1.jl

# A module for YAML 1.1.
# https://yaml.org/spec/1.1/
module YAML_1_1

# [22] b-line-feed ::= #xA /*LF*/
const b_line_feed = '\xa'

# [23] b-carriage-return ::= #xD /*CR*/
const b_carriage_return = '\xd'

# [24] b-next-line ::= #x85 /*NEL*/
const b_next_line = '\u85'

# [25] b-line-separator ::= #x2028 /*LS*/
const b_line_separator = '\u2028'

# [26] b-paragraph-separator ::= #x2029 /*PS*/
const b_paragraph_separator = '\u2028'

# [27] b-char ::=   b-line-feed | b-carriage-return | b-next-line
#                 | b-line-separator | b-paragraph-separator
is_b_char(c::Char) =
    c == b_line_feed || c == b_carriage_return | c == b_next_line ||
    c == b_line_separator || c == b_paragraph_separator

end # module YAML_1_1
# YAML_1_2.jl

# A module for YAML 1.2.
# https://yaml.org/spec/1.2.2/
module YAML_1_2

# [24] b-line-feed ::= x0A
const b_line_feed = '\x0a'

# [25] b-carriage-return ::= x0D
const b_carriage_return = '\x0d'

# [26] b-char ::= b-line-feed | b-carriage-return
is_b_char(c::Char) = c == b_line_feed || c == b_carriage_return

end # module YAML_1_2
# scanner.jl

include("YAML_1_1.jl")
using .YAML_1_1
include("YAML_1_2.jl")
using .YAML_1_2

# when processing YAML 1.1
if YAML_1_1.is_b_char(c)
    # hogehoge
end

# when processing YAML 1.2
if YAML_1_2.is_b_char(c)
    # fugafuga
end
@Paalon
Copy link
Contributor Author

Paalon commented Jun 21, 2024

@GunnarFarneback @kescobo If we use versions traits overall the scanner functions, the ultimate implementation will be

function scan_something(version::YAMLVersion, stream::TokenStream)
    subprocess1(version, stream)
    subprocess2(version, stream)
end

Is this good at performance compared to naive ones (the above implementation)?

@GunnarFarneback
Copy link
Contributor

Yes, there's basically no overhead related to the traits. Not that I think the overhead would have been significant with any other approach either.

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

No branches or pull requests

3 participants