Skip to content

Commit 5535ff1

Browse files
committed
feat: handle public kw
1 parent 94852f4 commit 5535ff1

File tree

7 files changed

+58
-21
lines changed

7 files changed

+58
-21
lines changed

.github/workflows/jlpkgbutler-ci-master-workflow.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,13 @@ jobs:
1212
runs-on: ${{ matrix.os }}
1313
strategy:
1414
matrix:
15-
julia-version: ['1.0', '1.1', '1.2', '1.3', '1.4', '1.5', '1.6', '1.7', '1.8', '1.9', '1.10']
16-
julia-arch: [x64, x86]
15+
julia-version: ['1.0', '1.1', '1.2', '1.3', '1.4', '1.5', '1.6', '1.7', '1.8', '1.9', '1.10', '1.11']
1716
os: [ubuntu-latest, windows-latest, macOS-latest]
18-
exclude:
19-
- os: macOS-latest
20-
julia-arch: x86
21-
2217
steps:
23-
- uses: actions/checkout@v3
24-
- uses: julia-actions/setup-julia@v1
18+
- uses: actions/checkout@v4
19+
- uses: julia-actions/install-juliaup@v1
2520
with:
26-
version: ${{ matrix.julia-version }}
27-
arch: ${{ matrix.julia-arch }}
21+
julia-version: ${{ matrix.julia-version }}
2822
- uses: julia-actions/julia-buildpkg@v1
2923
env:
3024
PYTHON: ""
@@ -37,4 +31,3 @@ jobs:
3731
files: ./lcov.info
3832
flags: unittests
3933
token: ${{ secrets.CODECOV_TOKEN }}
40-

.github/workflows/jlpkgbutler-ci-pr-workflow.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@ jobs:
99
runs-on: ${{ matrix.os }}
1010
strategy:
1111
matrix:
12-
julia-version: ['1.0', '1.1', '1.2', '1.3', '1.4', '1.5', '1.6', '1.7', '1.8', '1.9', '1.10']
13-
julia-arch: [x64, x86]
12+
julia-version: ['1.0', '1.1', '1.2', '1.3', '1.4', '1.5', '1.6', '1.7', '1.8', '1.9', '1.10', '1.11']
1413
os: [ubuntu-latest, windows-latest, macOS-latest]
15-
exclude:
16-
- os: macOS-latest
17-
julia-arch: x86
1814

1915
steps:
20-
- uses: actions/checkout@v3
21-
- uses: julia-actions/setup-julia@v1
16+
- uses: actions/checkout@v4
17+
- uses: julia-actions/install-juliaup@v1
2218
with:
23-
version: ${{ matrix.julia-version }}
24-
arch: ${{ matrix.julia-arch }}
19+
julia-version: ${{matrix.julia-version}}
2520
- uses: julia-actions/julia-buildpkg@v1
2621
env:
2722
PYTHON: ""

src/components/internals.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,21 @@ function parse_nonstd_identifier(ps)
366366
end
367367
end
368368

369+
function parse_public_item(ps::ParseState)
370+
if kindof(ps.nt) === Tokens.AT_SIGN
371+
parse_macroname(next(ps))
372+
elseif kindof(ps.nt) === Tokens.EX_OR
373+
parse_unary(ps, INSTANCE(next(ps)))
374+
elseif isoperator(ps.nt)
375+
next(ps)
376+
EXPR(:OPERATOR, ps.nt.startbyte - ps.t.startbyte, 1 + ps.t.endbyte - ps.t.startbyte, val(ps.t, ps))
377+
elseif is_nonstd_identifier(ps)
378+
parse_nonstd_identifier(ps)
379+
else
380+
INSTANCE(next(ps))
381+
end
382+
end
383+
369384
function parse_importexport_item(ps, is_colon = false)
370385
if kindof(ps.nt) === Tokens.AT_SIGN
371386
parse_macroname(next(ps))

src/components/keywords.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ function parse_kw(ps::ParseState)
7272
return @default ps parse_abstract(ps)
7373
elseif k === Tokens.PRIMITIVE
7474
return @default ps parse_primitive(ps)
75+
elseif k === Tokens.PUBLIC
76+
return @default ps parse_public(ps)
7577
elseif k === Tokens.TYPE
7678
return EXPR(:IDENTIFIER, ps)
7779
elseif k === Tokens.STRUCT
@@ -157,6 +159,23 @@ function parse_primitive(ps::ParseState)
157159
return ret
158160
end
159161

162+
function parse_public(ps::ParseState)
163+
args = EXPR[]
164+
trivia = EXPR[EXPR(ps)]
165+
166+
push!(args, parse_importexport_item(ps))
167+
168+
prevpos = position(ps)
169+
while iscomma(ps.nt)
170+
push!(trivia, EXPR(next(ps)))
171+
arg = parse_importexport_item(ps)
172+
push!(args, arg)
173+
prevpos = loop_check(ps, prevpos)
174+
end
175+
176+
return EXPR(:public, args, trivia)
177+
end
178+
160179
function parse_mutable(ps::ParseState)
161180
if kindof(ps.nt) === Tokens.STRUCT
162181
kw = EXPR(ps)

src/interface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
isidentifier(x::EXPR) = headof(x) === :IDENTIFIER || headof(x) === :NONSTDIDENTIFIER
33
isoperator(x::EXPR) = headof(x) === :OPERATOR
44
isnonstdid(x::EXPR) = headof(x) === :NONSTDIDENTIFIER
5-
iskeyword(x::EXPR) = headof(x) in (:ABSTRACT, :BAREMODULE, :BEGIN, :BREAK, :CATCH, :CONST, :CONTINUE, :DO, :ELSE, :ELSEIF, :END, :EXPORT, :FINALLY, :FOR, :FUNCTION, :GLOBAL, :IF, :IMPORT, :importall, :LET, :LOCAL, :MACRO, :MODULE, :MUTABLE, :NEW, :OUTER, :PRIMITIVE, :QUOTE, :RETURN, :STRUCT, :TRY, :TYPE, :USING, :WHILE)
5+
iskeyword(x::EXPR) = headof(x) in (:ABSTRACT, :BAREMODULE, :BEGIN, :BREAK, :CATCH, :CONST, :CONTINUE, :DO, :ELSE, :ELSEIF, :END, :EXPORT, :FINALLY, :FOR, :FUNCTION, :GLOBAL, :IF, :IMPORT, :importall, :LET, :LOCAL, :MACRO, :MODULE, :MUTABLE, :NEW, :OUTER, :PRIMITIVE, :PUBLIC, :QUOTE, :RETURN, :STRUCT, :TRY, :TYPE, :USING, :WHILE)
66
isliteral(x::EXPR) = isstringliteral(x) || iscmd(x) || ischar(x) || headof(x) in (:INTEGER, :BININT, :HEXINT, :OCTINT, :FLOAT, :NOTHING, :TRUE, :FALSE)
77
ispunctuation(x::EXPR) = is_comma(x) || is_lparen(x) || is_rparen(x) || is_lsquare(x) || is_rsquare(x) || is_lbrace(x) || is_rbrace(x) || headof(x) === :ATSIGN || headof(x) === :DOT
88
isstringliteral(x) = headof(x) === :STRING || headof(x) === :TRIPLESTRING

src/spec.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ function tokenkindtoheadmap(k::Tokens.Kind)
387387
return :OUTER
388388
elseif k === Tokens.PRIMITIVE
389389
return :PRIMITIVE
390+
elseif k === Tokens.PUBLIC
391+
return :PUBLIC
390392
elseif k === Tokens.QUOTE
391393
return :QUOTE
392394
elseif k === Tokens.RETURN

test/parser/test_keyword_blocks.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,16 @@ end""" |> test_expr
189189
end""" |> test_expr
190190
@test "f() do x body end" |> test_expr
191191
end
192+
193+
if VERSION > v"1.11-"
194+
@testitem "public" begin
195+
using CSTParser: remlineinfo!
196+
include("../shared.jl")
197+
198+
@test """public foo""" |> test_expr
199+
@test """public foo, bar""" |> test_expr
200+
@test """public foo,
201+
bar
202+
""" |> test_expr
203+
end
204+
end

0 commit comments

Comments
 (0)