Giter VIP home page Giter VIP logo

Comments (5)

keleshev avatar keleshev commented on July 30, 2024

Yes, I already created a bugfix branch in order to fix this. The problem with [<name>] and <name>... is that they are very greedy—they will try to match no matter what follows them. This problem requires some thought.

from docopt.

Met48 avatar Met48 commented on July 30, 2024

@halst I've made progress on fixing this in my experimental branch: see the full diff and file. There's still some refactoring and tests cases needed, but the core code is done. It passes all language agnostic tests and fully resolves this issue.

Any feedback would be appreciated. I realize it is a lot of changes, but I think it's necessary to resolve the issue. The existing implementation places all flow control in the match methods, which makes it difficult to try alternate input interpretations when there's a failure. I tried two other approaches to the issue: state restoration after failures (backtracking) and simultaneous testing of other input interpretations. This NFA solution implements the latter, as I found the code to be a lot cleaner than the backtracking solution.

from docopt.

keleshev avatar keleshev commented on July 30, 2024

I really appreciate your effort; I will need some time to read and understand the code. It would be great if you could write a couple of (github) comments in commits' diffs:

Met48@fe9f6de
Met48@d2b293b

from docopt.

keleshev avatar keleshev commented on July 30, 2024

So far I can say that your code works pretty well. The only "funny" behavior I could find was this:

>>> docopt('usage: prog <a>... <b>', '1 2 3')
{'<a>': ['1', '2', '3'],
 '<b>': '3'}

Although current version of docopt can't do that at all :-)

from docopt.

Met48 avatar Met48 commented on July 30, 2024

Thanks for taking a look! It definitely needs test cases, as that behaviour was was one of the first I had implemented! I'm working on that though, having just got tox set up and the language agnostic tests running through pytest.

I can think of a couple of fixes to that issue which I'll look at tonight, the quickest being a deepcopy of collected in traverse.append.

I don't really want to comment on the commits since I'm rebasing the branch, so I'll mention the general method here.


For the most part it's a modification of this regular expression matching algorithm. The usage pattern is converted into a NFA which the traverse function navigates.

This NFA has only two node types, Literal and Split. All containers (like Required)

Literal nodes include Argument and Command. The traverse function calls their next method, which modifies the arguments and collected lists before returning the next node.

Split nodes have two child nodes and allow for multiple execution paths. When the traverse function encounters one, it adds both child nodes to its list of nodes to process. Each loop it processes all nodes in this list simultaneously.

The NFA is generated by the assemble methods. Each Container subclasses implement this method differently, to connect their child nodes correctly. Required just connects them in sequence, for instance. Either creates a Split nodes as necessary so that each child is its own branch.

from docopt.

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.