Skip to content

Commit 53aabde

Browse files
github-actions[bot]CompatHelper Juliasunxd3
authored
CompatHelper: bump compat for JuliaSyntax to 1, (keep existing compat) (#287)
This pull request changes the compat entry for the `JuliaSyntax` package from `0.4` to `0.4, 1`. This keeps the compat entries for earlier versions. Note: I have not tested your package with this new compat entry. It is your responsibility to make sure that your package tests pass before you merge this pull request. --------- Co-authored-by: CompatHelper Julia <[email protected]> Co-authored-by: Xianda Sun <[email protected]> Co-authored-by: Xianda Sun <[email protected]>
1 parent 4673439 commit 53aabde

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ GraphMakie = "0.5"
5959
GraphPlot = "0.6"
6060
Graphs = "1"
6161
JSON = "0.21"
62-
JuliaSyntax = "0.4"
62+
JuliaSyntax = "1"
6363
LinearAlgebra = "1.10"
6464
LogDensityProblems = "2"
6565
LogDensityProblemsAD = "1"

src/parser/bugs_parser.jl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ function ProcessState(text::String, replace_period=true, allow_eq=true)
1313
# the tokenizer will actually parsing the program string according to Julia syntax, then return the tokens
1414
# which means that if the program doesn't follow Julia syntax, the token stream will contain "error" tokens
1515
# so we remove these "error" tokens here
16-
token_vec = filter(x -> kind(x) != K"error", tokenize(text))
16+
token_vec = filter(
17+
x -> kind(x) != K"error", tokenize(text; operators_as_identifiers=false)
18+
)
1719
disallowed_words = [
18-
t for
19-
t in token_vec if kind(t) WHITELIST && kind(t) JULIA_RESERVED_WORDS_W_O_FOR
20+
t for t in token_vec if
21+
kind(t) WHITELIST && kind(t) JULIA_RESERVED_WORDS_W_O_FOR && kind(t) !== K"Bool" # in JuliaSyntax 1.0, `true` and `false` are parsed as K`Bool`
2022
]
2123
if !isempty(disallowed_words)
2224
diagnostics = [
@@ -31,11 +33,11 @@ function ProcessState(text::String, replace_period=true, allow_eq=true)
3133
)
3234
end
3335

34-
WHITELIST = KSet"Whitespace Comment NewlineWs EndMarker for in , { } ( ) [ ] : ; ~ < - <-- = + - * / ^ . Identifier Integer Float TOMBSTONE error"
36+
WHITELIST = KSet"Whitespace Comment NewlineWs EndMarker for in , { } ( ) [ ] : ; ~ < - <-- = + - * / ^ . Identifier Bool Integer Float TOMBSTONE error"
3537
# Julia reserved words are parsed to special tokens, to allow using these as variable names, we need to wrap them
3638
# in `var"..."` to avoid syntax error in the generated Julia program
3739
# full list of possible tokens are here: https://github.com/JuliaLang/JuliaSyntax.jl/blob/main/src/kinds.jl
38-
JULIA_RESERVED_WORDS_W_O_FOR = KSet"baremodule begin break catch const continue do else elseif end export false finally function global if import let local macro module quote return struct true try using where while"
40+
JULIA_RESERVED_WORDS_W_O_FOR = KSet"baremodule begin break catch const continue do export elseif end export finally function global if import let local macro module quote return struct try using where while"
3941

4042
function ProcessState(ps::ProcessState)
4143
return ProcessState(
@@ -218,7 +220,7 @@ end
218220

219221
function process_statements!(ps::ProcessState)
220222
process_trivia!(ps)
221-
while peek(ps) KSet"for Identifier" || peek(ps) JULIA_RESERVED_WORDS_W_O_FOR
223+
while peek(ps) KSet"for Identifier Bool" || peek(ps) JULIA_RESERVED_WORDS_W_O_FOR
222224
if peek(ps) == K"for"
223225
process_for!(ps)
224226
else
@@ -418,7 +420,7 @@ function process_identifier_led_expression!(ps, terminators=KSet"; NewlineWs End
418420
giveup!(ps)
419421
end
420422
end
421-
elseif peek(ps) JULIA_RESERVED_WORDS_W_O_FOR
423+
elseif peek(ps) JULIA_RESERVED_WORDS_W_O_FOR || peek(ps) == K"Bool"
422424
if peek(ps, 2) == K"("
423425
push!(ps.julia_token_vec, "var\"$(peek_raw(ps))\"") # wrap in `var"..."` to avoid syntax error
424426
discard!(ps) # consume the function name
@@ -524,7 +526,7 @@ function process_variable!(ps::ProcessState, allow_indexing=true)
524526

525527
# if a simple variable, just consume it and return
526528
if peek(ps, 2) KSet". ["
527-
if peek(ps) JULIA_RESERVED_WORDS_W_O_FOR
529+
if peek(ps) JULIA_RESERVED_WORDS_W_O_FOR || peek(ps) == K"Bool"
528530
push!(ps.julia_token_vec, "var\"$(peek_raw(ps))\"") # wrap in `var"..."` to avoid syntax error
529531
discard!(ps) # discard the variable name
530532
else
@@ -540,8 +542,10 @@ function process_variable!(ps::ProcessState, allow_indexing=true)
540542
return nothing
541543
end
542544
variable_name_buffer = String[]
543-
while peek(ps) == K"Identifier" || peek(ps) JULIA_RESERVED_WORDS_W_O_FOR
544-
if peek(ps) JULIA_RESERVED_WORDS_W_O_FOR
545+
while peek(ps) == K"Identifier" ||
546+
peek(ps) JULIA_RESERVED_WORDS_W_O_FOR ||
547+
peek(ps) == K"Bool"
548+
if peek(ps) JULIA_RESERVED_WORDS_W_O_FOR || peek(ps) == K"Bool"
545549
push!(variable_name_buffer, "var\"$(peek_raw(ps))\"") # wrap in `var"..."` to avoid syntax error
546550
else
547551
push!(variable_name_buffer, peek_raw(ps))
@@ -568,7 +572,7 @@ function process_variable!(ps::ProcessState, allow_indexing=true)
568572
process_trivia!(ps)
569573
end
570574
else # cases like `a[i]` then first consume the variable name
571-
if peek(ps) JULIA_RESERVED_WORDS_W_O_FOR
575+
if peek(ps) JULIA_RESERVED_WORDS_W_O_FOR || peek(ps) == K"Bool"
572576
push!(ps.julia_token_vec, "var\"$(peek_raw(ps))\"") # wrap in `var"..."` to avoid syntax error
573577
discard!(ps) # discard the variable name
574578
else

0 commit comments

Comments
 (0)