Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes parsing of [default: x] in some cases on Win. #23

Closed
wants to merge 2 commits into from

Conversation

rhorenov
Copy link

Hi,

there is a problem if the option definition spans over multiple lines, then parsing of the [default: x] was not working on Windows - tested on MS Visual Studio 2015.

This is due to the differences in regex's multiline property implementations.

On some platforms - Linux libstd++ the multiline property is off,
on some platforms - msvc2015 the multiline property is on.

It cannot be changed programmatically AFAIK.

I was not able to come up with a regex expression which
would work on Linux and on Windows as well. So I tried to be
smart and replace '\n' by '\f' in the string beforehand.
The regex was easy and worked on Linux and Windows just fine -
up until I tried a longer option definition. Then the msvc2015
regex failed with 'stack' exception. Hence this change.

It splits the option definition section by a simple regex
which does not use the problematic '$'.

Tell me what you think. All tests are passing.

Regards,
Roman

modified:   docopt.cpp
modified:   docopt_util.h

If the option definition spans over multiple lines, then
parsing of the [default: x] was not working on Windows -
tested on MS Visual Studio 2015.

This is due to the differences in regex's multiline property
implementation.

On some platforms - Linux libstd++ the multiline property is off,
on some platforms - msvc2015 the multiline property is on.

It cannot be changed programmatically AFAIK.

I was not able to come up with a regex expression which
would work on Linux and on Windows as well. So I tried to be
smart and replace '\n' by '\f' in the string beforehand.
The regex was easy and worked on Linux and Windows just fine
- up until I tried a longer option definition.
Then the msvc2015 regex failed with 'stack' exception. Hence
this change.

It splits the option definition section by a simple regex
which does not use the problematic '$'.

	modified:   docopt.cpp
	modified:   docopt_util.h
Usage:
    prog [--foo <foo_>] [--baz <baz_>]

Options:
    --foo <foo_>
                    Foo [default: 42]
    --baz <baz_>
                    Baz [default: 1]

	modified:   testcases.docopt
@jaredgrubb
Copy link
Member

Docopt.cpp is a port of the original docopt, and the test-case file comes directly from there. I'm hesitant to fork that file without good reason.

Would you be willing to offer your test-case to that repo first? (https://github.com/docopt/docopt) I've already verified it passes the original docopt, so I think it would be a valuable addition!

Then, I think we can pull your patch+test direclty in. Sound ok?

@rhorenov rhorenov closed this Mar 26, 2019
@rhorenov rhorenov deleted the fix_parse_defaults branch March 26, 2019 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants