GithubHelp home page GithubHelp logo

Comments (3)

ndmitchell avatar ndmitchell commented on June 10, 2024

Yeah, the current API is probably not lazy by definition, and I think 2 is probably the right solution - but I'm not super sure. I've never used this API in anger, so it's really something best directed by real use cases. Having it not be lazy at all is probably a bad solution - it effectively caps the size of documents that can be processed, and it doesn't look like it should be that hard to make it lazy.

from tagsoup.

ChristopherKing42 avatar ChristopherKing42 commented on June 10, 2024

Probably the cleanest solution to number 2 would look sort of like this:

data Trees = Branch {tag :: String, afterOpen :: Trees, afterClose :: Maybe Trees} | NoTrees

(that type is simplified of course). afterClose is Nothing if there is no closing tag. tag and afterOpen can be determined lazily. Evaluating afterClose to Nothing or Just _ would requires tracing the document until you reach the closing tag or the end of the enclosing tag or the end of the document.

We could implement option 3 in addition to option 1 right now without changing the API. It would be a function like:

tagTreeLazy :: Eq str => (str -> Bool) -> [Tag str] -> [TagTree str]

Where the str -> Bool is whether or not the tag should have a closing tag. The only thing left to consider for that solution is what happens when it's wrong.

from tagsoup.

ndmitchell avatar ndmitchell commented on June 10, 2024

I'm not adverse to an API change if that's what we think is needed. I'm not sure I have enough a good model for an API. Perhaps the existing data type with:

tagTree :: Eq str => (str -> Bool) -> [Tag str] -> ([TagTree str], [str])

That gives you the pipe of TagTree values, plus the second component being the list of things that were expected to get shut but didn't. You would never emit a TagClose unless it was unmatched. Then the "sanity" condition would be that the first list doesn't contain TagClose and the second list is empty.

from tagsoup.

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.