Giter VIP home page Giter VIP logo

Comments (5)

davidsantiago avatar davidsantiago commented on June 3, 2024

How is this "not working?" I can only kind of try to check the two lines of code, and one problem is that s/children is not a function. The other problem is that s/child is a function, but it doesn't take a list as argument, it takes varargs. You'd want to do something like (apply s/child _yf2) in the select call. But maybe its neither of those issues.

from hickory.

FrankC01 avatar FrankC01 commented on June 3, 2024

David

First of all: Great piece of work! It really fits a need with a easy to use
API.

Issue: I believe you are correct. I was assuming (barring the typo on
s/children vs. s/child) that it took a list so I believe the apply will
work. I will let you know.

Regards,

Frank

Axiom:1, Inc.
Phone: (800) 558-5119
Fax: (800) 531-2819
Web: http://www.axiom1inc.com http://www.axiom1inc.com/

From: David Santiago [email protected]
Reply-To: davidsantiago/hickory
<reply+i-30463540-46d81b3b783fdaf5e3bd6d476d71aebca55a4d29-5435165@reply.git
hub.com>
Date: Sunday, March 30, 2014 at 2:02 PM
To: davidsantiago/hickory [email protected]
Cc: Frank Castellucci [email protected]
Subject: Re: [hickory] Question: Regarding Evaluation (#14)

How is this "not working?" I can only kind of try to check the two lines of
code, and one problem is that s/children is not a function. The other
problem is that s/child is a function, but it doesn't take a list as
argument, it takes varargs. You'd want to do something like (apply s/child
_yf2) in the select call. But maybe its neither of those issues.


Reply to this email directly or view it on GitHub
#14 (comment) .

from hickory.

FrankC01 avatar FrankC01 commented on June 3, 2024

Yes, not making much headway.

What I am trying to do is parse a user query grammar and produce hickory selectors as a result to then pass to a generalized thread (-> (select (s/child _my_generated_selectors) in-data) first ...).

I am lost on how to generate the selectors. For example, I am doing something like this in the parser transform:

(cond
  (= x :tag) (fn [...]  `(s/tag :tagname))
  (= x :att) (fn [...] `(s/attr :attname)))

And the types come back as clojure.lang.Cons

Does that shine a better light?

from hickory.

davidsantiago avatar davidsantiago commented on June 3, 2024

Thank you!

I'm afraid I'm still not able to understand very well what you are doing. It's probably too complicated to explain in an issue. But, it does look from this snippet like you should be expecting a Cons somewhere around there: you're returning a function that returns a Cons due to the quoting. The s/tag and s/attr (and all the selectors) return functions, and you can plug those directly into s/select, stick them in lists, pass them to other selector functions. So I don't know why they are getting wrapped in a function, but that is probably an aspect of your design unrelated to the use of Hickory.

Since I'm not able to figure out what is going on, I would suggest that you first try to get the Hickory code working by crafting by hand (in the repl, say) a query that you'd like to be able to run. That is, manually type in the code you'd like your query grammar to compile to. Once you have that working, work on making your parser generate that (or equivalent) code from the actual user input.

from hickory.

FrankC01 avatar FrankC01 commented on June 3, 2024

Got it working, as soon as I removed the syntax quoting and un-quoting as per your comment it works like a baby!
''''
(-> (s/select (apply s/child (->> (hfm "(#tag head) (#tag title)")
(hfm-transform))) _r0))
=> [{:type :element, :attrs nil, :tag :title, :content ["Yahoo"]}]
''''

For some reason I had it in my head that they had to be quoted.

from hickory.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.