Skip to content

Commit

Permalink
Special token for empty string.
Browse files Browse the repository at this point in the history
  • Loading branch information
orenbenkiki committed Apr 11, 2024
1 parent 5aed40b commit 6536bc9
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ version = "0.17.2"

[[deps.HDF5_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "LazyArtifacts", "LibCURL_jll", "Libdl", "MPICH_jll", "MPIPreferences", "MPItrampoline_jll", "MicrosoftMPI_jll", "OpenMPI_jll", "OpenSSL_jll", "TOML", "Zlib_jll", "libaec_jll"]
git-tree-sha1 = "6384c847ff5056c5624e30e75b3ca48902cae0ac"
git-tree-sha1 = "82a471768b513dc39e471540fdadc84ff80ff997"
uuid = "0234f1f7-429e-5d53-9886-15a909be8d59"
version = "1.14.3+2"
version = "1.14.3+3"

[[deps.Hwloc_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
Expand Down
2 changes: 1 addition & 1 deletion docs/v0.1.0/.documenter-siteinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-10T08:11:56","documenter_version":"1.3.0"}}
{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-10T20:22:24","documenter_version":"1.3.0"}}
2 changes: 1 addition & 1 deletion docs/v0.1.0/search_index.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion docs/v0.1.0/tokens.html
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,11 @@ <h2 id="Tokenization">
<a href="tokens.html#Daf.Tokens.Token">
<code>Token
</code>
</a>. Anything else is reported as an invalid character.
</a>. As a special case,
<code>&#39;&#39;
</code> is converted to an empty string, which is otherwise impossible to represent (write
<code>\&#39;\&#39;
</code> to prevent this). Anything else is reported as an invalid character.
</p>
<div class="admonition is-info">
<header class="admonition-header">Note
Expand Down
12 changes: 10 additions & 2 deletions src/tokens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ into a single line (discarding line breaks and comments), and the squashed expre
is reasonable for dealing with `Daf` queries which are expected to be "relatively simple".
When tokenizing, we discard the spaces. Anything that matches the [`VALUE_REGEX`](@ref) is considered to be a value
[`Token`](@ref). Anything that matches the `operators` is considered to be an operator [`Token`](@ref). Anything else is
reported as an invalid character.
[`Token`](@ref). Anything that matches the `operators` is considered to be an operator [`Token`](@ref). As a special
case, `''` is converted to an empty string, which is otherwise impossible to represent (write `\\'\\'` to prevent this).
Anything else is reported as an invalid character.
!!! note
Expand All @@ -195,6 +196,13 @@ function tokenize(string::AbstractString, operators::Regex)::Vector{Token}
continue
end

if startswith(rest_of_string, "''")
push!(tokens, Token(false, "", token_index, first_index, first_index + 2, "''"))
first_index += 2
rest_of_string = rest_of_string[3:end]
continue
end

value = match(VALUE_REGEX, rest_of_string)
if value !== nothing
@assert value.offset == 1
Expand Down
2 changes: 2 additions & 0 deletions test/tokens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ nested_test("tokens") do
nested_test("single") do
@test token_strings("1") == String["1"]
@test token_strings("x") == String["x"]
@test token_strings("''") == String[""]
@test token_strings("\\'\\'") == String["''"]
end

nested_test("multiple") do
Expand Down

0 comments on commit 6536bc9

Please sign in to comment.