Skip to content
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ authors = ["Caleb Allen <[email protected]> and contributors"]
version = "0.3.4"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Match = "7eb4fadd-790c-5f42-8a69-bfa0b872bfbf"
PikaParser = "3bbf5609-3e7b-44cd-8549-7c69f321e792"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Expand Down
5 changes: 5 additions & 0 deletions develop.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Revise
using VimBindings
ENV["JULIA_DEBUG"] = "Parse,ParseClauses"
using REPL
REPL.activate(VimBindings.Parse);
3 changes: 2 additions & 1 deletion src/VimBindings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ include("command.jl")
include("motion.jl")
include("registers.jl")
include("operator.jl")
include("parse.jl")
# include("parse.jl")
include("pika_parse.jl")
include("changes.jl")
include("execute.jl")
include("lineeditalt.jl")
Expand Down
1 change: 1 addition & 0 deletions src/command.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ end

struct TextObjectCommand <: Command
r1 :: Int
# TODO separate name into two char parts
name :: String
end

Expand Down
2 changes: 1 addition & 1 deletion src/parse.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Parse
# include("pika_parse.jl")
import DataStructures: OrderedDict
using ..Commands
using ..Motions
using ..Util
import ..Util.@debug

export well_formed, matched_rule, parse_command, synonym, partial_well_formed

Expand Down
100 changes: 100 additions & 0 deletions src/parse_clauses.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""
The functions for the parser to call to fold a parse rule

the first argument of a clause function is the match.view
the subsequent arguments are the subvalues

All methods in this module except `clause` and `clauses` MUST be for
parsing a clause as defined in VimBindings.Parse
"""
module ParseClauses

using ..Motions, ..Commands
export clause

# TODO make this a const value
"""
Get the methods in this
"""
function clauses()
all_names = names(ParseClauses, all=true)
filter(setdiff(all_names,
(:ParseClauses, Symbol("#eval"), Symbol("#include"),
:clause, :clauses, :eval))) do fn_name
!startswith(string(fn_name), "#")
end
end
# clauses = [x for x in names(ParseClauses, all=true) if getproperty(ParseClauses,x) isa Function && x ∉ (:eval, :include)]
function clause(match, subvals)
sym = match.rule
sym = Symbol(replace(string(match.rule), "-" => "_"))
# dump(match)
# e.g. motion-1 becomes motion_1
# @debug "Executing clause $(string(sym))" match.view subvals
if !(sym in clauses())
@warn "No function for clause: `$sym` exists" f_name=sym args=(match.view, subvals...) types=typeof.(subvals)
if !isempty(subvals)
if length(subvals) == 1
return subvals[1]
else
error("Ambigous clause: can't fold match with $(length(subvals)) subvals.")
end
return subvals
end
return match.view
else
@debug "Clause `$sym`" f_name=sym args=(match.view,subvals...) types=typeof.(subvals)
end
# TODO get the fields and save them to a const dict.
f = getfield(ParseClauses, sym)
return f(match.view, subvals...)
end

repeat(a::AbstractString, args...) = parse(Int, a)

count(_, repeat::Int) = repeat

count(_) = 1

char(s::AbstractString) = s[1]

motion(m::AbstractString) = m[1]

motions(_, count::Int, name::AbstractChar) = SimpleMotionCommand(count, name)

operator(_, name::AbstractString) = name[1]

operators(_, count::Int, name::Char) = (count, name)

operator_command(_, op::Tuple{Int, AbstractChar}, cmd::Union{MotionCommand, TextObjectCommand}) =
OperatorCommand(op[1], op[2], cmd)

textobject(_, count::Int, a_or_i::AbstractString, object_type::AbstractString) =
(count, a_or_i[1], object_type[1])

textobject_command(_, op::Tuple{Int, Char}, textobject::Tuple{Int, Char, Char}) =
OperatorCommand(
op[1], op[2],
# TODO separate name into two char parts
TextObjectCommand(textobject[1], textobject[2] * textobject[3])
)

insert_command(_, name::AbstractString) = InsertCommand(name[1])

zero_command(_, zero::AbstractString) = ZeroCommand()

synonym(_, name::AbstractString) = name[1]

synonym_command(_, count::Int, name::Char) = SynonymCommand(count, name)

history(_, name::AbstractString) = name[1]
# history(_, name::AbstractString) = name == "^R" ? '\x12' : name[1]

history_command(_, count::Int, name::Char) = HistoryCommand(count, name)

lineoperator_command(_, count::Int, op::AbstractString) = LineOperatorCommand(count, op[1])

replace_command(_, count::Int, r, replacement::Char) = ReplaceCommand(count, replacement)


end
Loading