Skip to content

Commit

Permalink
Merge pull request #29 from simonschoelly/fixes_for_julia_1.0
Browse files Browse the repository at this point in the history
Fixes for julia v0.7 and v1.0
  • Loading branch information
CarloLucibello authored Sep 1, 2018
2 parents a0c0da6 + f56f599 commit 1b384cc
Show file tree
Hide file tree
Showing 37 changed files with 426 additions and 370 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ os:
- linux
- osx
julia:
- 0.3
- 0.4
- 0.7
- 1.0
- nightly
notifications:
email: false
Expand All @@ -13,4 +13,4 @@ notifications:
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia --check-bounds=yes -e 'Pkg.clone(pwd()); Pkg.build("ParserCombinator"); Pkg.test("ParserCombinator"; coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("ParserCombinator")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'using Pkg; cd(Pkg.dir("ParserCombinator")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
5 changes: 2 additions & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
julia 0.3
Compat 0.7.12
julia 0.7
AutoHashEquals 0.0.8

Nullables
10 changes: 5 additions & 5 deletions src/ParserCombinator.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

module ParserCombinator

using Compat
using Nullables
using AutoHashEquals
import Base: start, next, done, endof, getindex, colon, isless, size, hash
import Base: iterate, getindex, isless, size, hash,
axes, lastindex, firstindex
import Base: ==, ~, +, &, |, >=, >, |>, !
using Printf: @printf

export Matcher,
diagnostic, forwards, LineSource, LineIter,
Expand Down Expand Up @@ -32,9 +34,7 @@ Star, Plus, Star!, Plus!, StarList, StarList!, PlusList, PlusList!,
@with_names, set_name,
@with_pre, @with_post, set_fix,
TrySource, Try, parse_try, parse_try_dbg, parse_try_cache, parse_try_cache_dbg,
Parsers

FAST_REGEX = isdefined(Main, :FAST_REGEX) ? Main.FAST_REGEX : VERSION >= v"0.4.0-dev+6325"
Parsers, axes, lastindex

include("core/types.jl")
include("core/sources.jl")
Expand Down
31 changes: 15 additions & 16 deletions src/core/debug.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


# a Config instance that delegates to another, printing information about
# messages as they are sent. WARNING: makes a pile of assumptions about the
# source being a string.
Expand All @@ -8,7 +6,7 @@
# construct your own with any type by using the delegate=... keyword. see
# test/calc.j for an example.

type Debug{S,I}<:Config{S,I}
mutable struct Debug{S,I}<:Config{S,I}
source::S
stack::Vector
delegate::Config{S,I}
Expand All @@ -17,13 +15,13 @@ type Debug{S,I}<:Config{S,I}
max_depth::Int
max_iter
n_calls::Int
function Debug(source::S; delegate=NoCache, kargs...)
function Debug{S, I}(source::S; delegate=NoCache, kargs...) where {S,I}
k = delegate{S,I}(source; kargs...)
@compat new(k.source, k.stack, k, Vector{Int}(), 0, 0, start(k.source), 0)
new{S, I}(k.source, k.stack, k, Vector{Int}(), 0, 0, firstindex(k.source), 0)
end
end
# i don't get why this is necessary, but it seems to work
Debug(source; kargs...) = Debug{typeof(source),typeof(start(source))}(source; kargs...)
Debug(source; kargs...) = Debug{typeof(source),typeof(firstindex(source))}(source; kargs...)

parent(k::Debug) = parent(k.delegate)

Expand Down Expand Up @@ -77,7 +75,7 @@ if VERSION < v"0.4-"
shorten(s) = s
else
# shorten(s) = replace(s, r"(?:[a-zA-Z]+\.)+([a-zA-Z]+)", s"\1")
shorten(s) = replace(s, r"(?:[a-zA-Z]+\.)+([a-zA-Z]+)",
shorten(s) = replace(s, r"(?:[a-zA-Z]+\.)+([a-zA-Z]+)" =>
Base.SubstitutionString("\1"))
end

Expand All @@ -103,25 +101,25 @@ indent(k::Debug; max=MAX_IND) = repeat(" ", k.depth[end] % max)
src(::Any, ::Any; max=MAX_SRC) = pad(truncate("...", max), max)
src(s::AbstractString, i::Int; max=MAX_SRC) = pad(truncate(escape_string(s[i:end]), max), max)

function debug{S<:AbstractString}(k::Debug{S}, e::Execute)
function debug(k::Debug{S}, e::Execute) where {S<:AbstractString}
@printf("%3d:%s %02d %s%s->%s\n",
e.iter, src(k.source, e.iter), k.depth[end], indent(k), e.parent.name, e.child.name)
end

function short(s::Value)
result = string(s)
if ismatch(r"^Any", result)
if occursin(r"^Any", result)
result = result[4:end]
end
truncate(result, MAX_RES)
end

function debug{S<:AbstractString}(k::Debug{S}, s::Success)
function debug(k::Debug{S}, s::Success) where {S<:AbstractString}
@printf("%3d:%s %02d %s%s<-%s\n",
s.iter, src(k.source, s.iter), k.depth[end], indent(k), parent(k).name, short(s.result))
end

function debug{S<:AbstractString}(k::Debug{S}, f::Failure)
function debug(k::Debug{S}, f::Failure) where {S<:AbstractString}
@printf(" :%s %02d %s%s<-!!!\n",
pad(" ", MAX_SRC), k.depth[end], indent(k), parent(k).name)
end
Expand All @@ -138,17 +136,17 @@ function src(s::LineAt, i::LineIter; max=MAX_SRC)
end
end

function debug{S<:LineAt}(k::Debug{S}, e::Execute)
function debug(k::Debug{S}, e::Execute) where {S<:LineAt}
@printf("%3d,%-3d:%s %02d %s%s->%s\n",
e.iter.line, e.iter.column, src(k.source, e.iter), k.depth[end], indent(k), e.parent.name, e.child.name)
end

function debug{S<:LineAt}(k::Debug{S}, s::Success)
function debug(k::Debug{S}, s::Success) where {S<:LineAt}
@printf("%3d,%-3d:%s %02d %s%s<-%s\n",
s.iter.line, s.iter.column, src(k.source, s.iter), k.depth[end], indent(k), parent(k).name, short(s.result))
end

function debug{S<:LineAt}(k::Debug{S}, f::Failure)
function debug(k::Debug{S}, f::Failure) where {S<:LineAt}
@printf(" :%s %02d %s%s<-!!!\n",
pad(" ", MAX_SRC), k.depth[end], indent(k), parent(k).name)
end
Expand All @@ -157,16 +155,17 @@ end
# this does nothing except delegate and, by simply "being seen" during
# disparch above, toggle debug state.

@auto_hash_equals type Trace<:Delegate
@auto_hash_equals mutable struct Trace<:Delegate
name::Symbol
matcher::Matcher
Trace(matcher) = new(:Trace, matcher)
end

@auto_hash_equals immutable TraceState<:DelegateState
@auto_hash_equals struct TraceState<:DelegateState
state::State
end


# must handle both success and failure so that detection can occur above

success(k::Config, m::Trace, s, t, i, v::Value) = Success(TraceState(t), i, v)
Expand Down
Loading

0 comments on commit 1b384cc

Please sign in to comment.