Skip to content

Commit

Permalink
Accept symbol for require, pinclude (close #49)
Browse files Browse the repository at this point in the history
  • Loading branch information
noteflakes committed Jan 22, 2018
1 parent a6d7c10 commit 067cece
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
12 changes: 7 additions & 5 deletions lib/lyp/etc/lyp.ly
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
(ly:parser-include-string parser str)))

(define (lyp:include parser location path once) (let* (
(path (if (symbol? path) (symbol->string path) path))
(current-dir (lyp:this-dir))
(abs-path (if (lyp:absolute-path? path)
path
Expand Down Expand Up @@ -146,7 +147,8 @@
)

% command form
require = #(define-void-function (parser location ref)(string?) (let* (
require = #(define-void-function (parser location ref)(string-or-symbol?) (let* (
(ref (if (symbol? ref) (symbol->string ref) ref))
(name (lyp:ref->name ref))
(package-dir (lyp:name->dir name))
(entry-point-path (lyp:join-path package-dir "package.ly"))
Expand All @@ -160,14 +162,14 @@ require = #(define-void-function (parser location ref)(string?) (let* (
))
))

pinclude = #(define-void-function (parser location path)(string?)
pinclude = #(define-void-function (parser location path)(string-or-symbol?)
(lyp:include parser location path #f))

pcondInclude = #(define-void-function (parser location expr path)(scheme? string?)
pcondInclude = #(define-void-function (parser location expr path)(scheme? string-or-symbol?)
(if expr (lyp:include parser location path #f)))

pincludeOnce = #(define-void-function (parser location path)(string?)
pincludeOnce = #(define-void-function (parser location path)(string-or-symbol?)
(lyp:include parser location path #t))

pcondIncludeOnce = #(define-void-function (parser location expr path)(scheme? string?)
pcondIncludeOnce = #(define-void-function (parser location expr path)(scheme? string-or-symbol?)
(if expr (lyp:include parser location path #t)))
2 changes: 1 addition & 1 deletion lib/lyp/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def resolve_tree
end
end

DEP_RE = /\\(require|include|pinclude|pincludeOnce) "([^"]+)"/.freeze
DEP_RE = /\\(require|include|pinclude|pincludeOnce)\s+(?:"|#')?([^\s"]+)"?/.freeze
INCLUDE = "include".freeze
PINCLUDE = "pinclude".freeze
PINCLUDE_ONCE = "pincludeOnce".freeze
Expand Down
16 changes: 8 additions & 8 deletions spec/resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ def resolver(tree = Lyp::DependencyLeaf.new, opts = {})
end
end

it "supports require with symbol instead of string" do
with_packages(:simple) do
resolver = resolver('spec/user_files/simple_symbol.ly')
o = resolver.compile_dependency_tree
expect(o.dependencies.keys).to eq(%w{a c})
end
end

it "correctly resolves a circular dependency" do
with_packages(:circular) do
r = resolver('spec/user_files/circular.ly').resolve_package_dependencies
Expand Down Expand Up @@ -274,14 +282,6 @@ def resolver(tree = Lyp::DependencyLeaf.new, opts = {})
"#{$packages_dir}/b@abc"
)

r = resolver('spec/user_files/b.ly').resolve_package_dependencies

expect(r[:definite_versions]).to eq(%w{b@def c@0.3.0})
expect(r[:package_refs]).to eq({"b" => "b", "c" => "c"})
expect(r[:package_dirs]['b']).to eq(
"#{$packages_dir}/b@def"
)

r = resolver('spec/user_files/b_def.ly').resolve_package_dependencies

expect(r[:definite_versions]).to eq(%w{b@def c@0.3.0})
Expand Down
3 changes: 3 additions & 0 deletions spec/user_files/simple_symbol.ly
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\require a
#(ly:message "simple\n")
\require #'c
3 changes: 3 additions & 0 deletions spec/user_files/the-works-symbols.ly
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\require dummy

\require #'dummy

0 comments on commit 067cece

Please sign in to comment.