Skip to content

Commit 2eb464e

Browse files
committed
Use APITools
1 parent 2745351 commit 2eb464e

4 files changed

Lines changed: 25 additions & 22 deletions

File tree

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ git:
2020
# uncomment the following lines to override the default test script
2121
script:
2222
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
23-
- julia -e 'p="https://github.com/JuliaString"; s=".jl.git"; Pkg.clone("$p/Strs$s") ; Pkg.clone("$p/Format$s"); Pkg.clone("$p/StrLiterals$s"); Pkg.clone(pwd()); Pkg.test("StrFormat"; coverage=true)'
23+
- julia -e 'VERSION < v"0.7.0-DEV" || (using Pkg); d="https://github.com/JuliaString" ; for n in ("APITools", "StrAPI", "CharSetEncodings", "Chars", "StrBase") ; Pkg.clone("$d/$n.jl") ; end ; Pkg.add("Format"); Pkg.clone("$d/StrLiterals.jl"); Pkg.clone(pwd()); Pkg.test("StrFormat"; coverage=true)'
2424
after_success:
2525
# push coverage results to Coveralls
26-
- julia -e 'cd(Pkg.dir("StrFormat")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
26+
- julia -e 'VERSION < v"0.7.0-DEV" || (using Pkg); cd(Pkg.dir("StrFormat")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
2727
# push coverage results to Codecov
28-
- julia -e 'cd(Pkg.dir("StrFormat")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
28+
- julia -e 'VERSION < v"0.7.0-DEV" || (using Pkg); cd(Pkg.dir("StrFormat")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'

REQUIRE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
julia 0.6
22
Format
3-
Strs
43
StrLiterals

src/StrFormat.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ Licensed under MIT License, see LICENSE.md
77
"""
88
module StrFormat
99

10-
using Format, StrLiterals
10+
using APITools, Format
11+
@api init
1112

12-
parse_error(s) = throw(StrLiterals._ParseError(s))
13-
14-
_check_exp(ex) =
15-
isa(ex, Expr) && (ex.head === :continue) && parse_error("Incomplete expression")
13+
@api extend StrAPI, CharSetEncodings, Chars, StrBase, StrLiterals
1614

1715
function _parse_format(str, pos, fun)
18-
ex, j = StrLiterals._parse(str, pos; greedy=false)
19-
_check_exp(ex)
20-
ex, k = StrLiterals._parse(string("a", str[pos:j-1]), 1, greedy=true)
21-
_check_exp(ex)
16+
ex, j = parse(Expr, str, pos; greedy=false)
17+
check_expr(ex)
18+
ex, k = parse(Expr, string("a", str[pos:j-1]), 1, greedy=true)
19+
check_expr(ex)
2220
isa(ex, Symbol) && (println(string("a", str[pos:j-1])) ; dump(ex))
2321
ex.args[1] = fun
2422
ex, j
@@ -28,7 +26,7 @@ function _parse_fmt(sx::Vector{Any}, s::AbstractString, unescape::Function,
2826
i::Integer, j::Integer, k::Integer)
2927
# Move past \\, k should point to '%'
3028
c, k = next(s, k)
31-
done(s, k) && parse_error("Incomplete % expression")
29+
check_done(s, k, "Incomplete % expression")
3230
# Handle interpolation
3331
isempty(s[i:j-1]) || push!(sx, unescape(s[i:j-1]))
3432
if s[k] == '('
@@ -39,7 +37,7 @@ function _parse_fmt(sx::Vector{Any}, s::AbstractString, unescape::Function,
3937
beg = k
4038
while true
4139
c, k = next(s, k)
42-
done(s, k) && parse_error("Incomplete % expression")
40+
check_done(s, k, "Incomplete % expression")
4341
s[k] == '(' && break
4442
end
4543
ex, j = _parse_format(s, k, Format.cfmt)
@@ -53,16 +51,16 @@ function _parse_pyfmt(sx::Vector{Any}, s::AbstractString, unescape::Function,
5351
i::Integer, j::Integer, k::Integer)
5452
# Move past \\, k should point to '{'
5553
c, k = next(s, k)
56-
done(s, k) && parse_error("Incomplete {...} Python format expression")
54+
check_done(s, k, "Incomplete {...} Python format expression")
5755
# Handle interpolation
5856
isempty(s[i:j-1]) || push!(sx, unescape(s[i:j-1]))
5957
beg = k # start location
6058
c, k = next(s, k)
6159
while c != '}'
62-
done(s, k) && parse_error(string("\\{ missing closing } in ", c))
60+
check_done(s, k, string("\\{ missing closing } in ", c))
6361
c, k = next(s, k)
6462
end
65-
done(s, k) && parse_error("Missing (expr) in Python format expression")
63+
check_done(s, k, "Missing (expr) in Python format expression")
6664
c, k = next(s, k)
6765
c == '(' || parse_error(string("Missing (expr) in Python format expression: ", c))
6866
# Need to find end to parse to
@@ -73,8 +71,10 @@ function _parse_pyfmt(sx::Vector{Any}, s::AbstractString, unescape::Function,
7371
end
7472

7573
function __init__()
76-
StrLiterals.interpolate['%'] = _parse_fmt
77-
StrLiterals.interpolate['{'] = _parse_pyfmt
74+
interpolate['%'] = _parse_fmt
75+
interpolate['{'] = _parse_pyfmt
7876
end
7977

78+
@api freeze
79+
8080
end # module StrFormat

test/runtests.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# License is MIT: LICENSE.md
22

3-
@static VERSION < v"0.7.0-DEV" ? (using Base.Test) : (using Test)
3+
using APITools, Format
4+
@api init
45

5-
using Format, Strs, StrLiterals, StrFormat
6+
@api test StrAPI, CharSetEncodings, Chars, StrBase
7+
@api test StrLiterals, StrFormat
8+
9+
@static V6_COMPAT ? (using Base.Test) : (using Test)
610

711
@testset "C Formatting" begin
812
@testset "int" begin

0 commit comments

Comments
 (0)