Comments (5)
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.
@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.
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:
from docopt.
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.
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)
- Is docopt / docopt itself still being maintained? HOT 1
- Please upload a wheel package to pypi HOT 6
- get_docopts.sh fails on M1 Monterey 12.6
- Short options in docopt not returning correct values HOT 1
- [FeatureRequest] Allow hash comments in docstring ? HOT 4
- Make new release HOT 3
- try.docopt.org is offline HOT 1
- Dart port? HOT 1
- Make docopt exceptions public
- How to call "python -m mypackage [options]" HOT 1
- Is there some docopt validator? HOT 1
- Why cannot docopt parse args? HOT 3
- Please share wheel file on pypi HOT 1
- Docopt AssertionError
- Having same issues as #516
- Unix-style vs. Windows-style options HOT 2
- Abandonware status of docopt HOT 7
- Why is the docopt website not served through HTTPS?
- Any good reason not to use GitHub releases? HOT 1
- how to implement number argument? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docopt.