diff --git a/src/scanner.jl b/src/scanner.jl index 084a57e..0e8127a 100644 --- a/src/scanner.jl +++ b/src/scanner.jl @@ -352,43 +352,49 @@ end # Checkers # -------- -const whitespace = "\0 \t\r\n\u0085\u2028\u2029" +yaml_1_1_is_whitespace(c::Char) = + c == '\0' || c == ' ' || c == '\t' || + c == '\r' || c == '\n' || + c == '\u85' || c == '\u2028' || c == '\u2029' - -function check_directive(stream::TokenStream) +check_directive(stream::TokenStream) = stream.column == 0 -end -function check_document_start(stream::TokenStream) +check_document_start(stream::TokenStream) = stream.column == 0 && - prefix(stream.input, 3) == "---" && - in(peek(stream.input, 3), whitespace) -end + prefix(stream.input, 3) == "---" && + yaml_1_1_is_whitespace(peek(stream.input, 3)) - function check_document_end(stream::TokenStream) - stream.column == 0 && - prefix(stream.input, 3) == "..." && - (in(peek(stream.input, 3), whitespace) || peek(stream.input, 3) === nothing) - end +check_document_end(stream::TokenStream) = + stream.column == 0 && + prefix(stream.input, 3) == "..." && begin + c = peek(stream.input, 3) + yaml_1_1_is_whitespace(c) || c === nothing + end function check_block_entry(stream::TokenStream) - in(peek(stream.input, 1), whitespace) + cnext = peek(stream.input, 1) + yaml_1_1_is_whitespace(cnext) end -function check_key(stream::TokenStream) - stream.flow_level > 0 || in(peek(stream.input, 1), whitespace) -end +check_key(stream::TokenStream) = + stream.flow_level > 0 || begin + cnext = peek(stream.input, 1) + yaml_1_1_is_whitespace(cnext) + end -function check_value(stream::TokenStream) - cnext = peek(stream.input, 1) - stream.flow_level > 0 || in(cnext, whitespace) || cnext === nothing -end +check_value(stream::TokenStream) = + stream.flow_level > 0 || begin + cnext = peek(stream.input, 1) + yaml_1_1_is_whitespace(cnext) || cnext === nothing + end function check_plain(stream::TokenStream) - !in(peek(stream.input), "\0 \t\r\n\u0085\u2028\u2029-?:,[]{}#&*!|>\'\"%@`\uFEFF") || - (!in(peek(stream.input, 1), whitespace) && - (peek(stream.input) == '-' || (stream.flow_level == 0 && - in(peek(stream.input), "?:")))) + c = peek(stream.input) + !(yaml_1_1_is_whitespace(c) || c in "-?:,[]{}#&*!|>\'\"%@`\uFEFF") || begin + cnext = peek(stream.input, 1) + !yaml_1_1_is_whitespace(cnext) && (c == '-' || stream.flow_level == 0 && (c == '?' || c == ':')) + end end @@ -1411,10 +1417,10 @@ function scan_plain(stream::TokenStream) while true c = peek(stream.input, length) cnext = peek(stream.input, length + 1) - if in(c, whitespace) || + if yaml_1_1_is_whitespace(c) || c === nothing || (stream.flow_level == 0 && c == ':' && - (cnext === nothing || in(cnext, whitespace))) || + (cnext === nothing || yaml_1_1_is_whitespace(cnext))) || (stream.flow_level != 0 && in(c, ",:?[]{}")) break end