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

Error parsing {string[]=} array with GCC optional notation #110

Open
yvele opened this issue Feb 24, 2020 · 3 comments
Open

Error parsing {string[]=} array with GCC optional notation #110

yvele opened this issue Feb 24, 2020 · 3 comments

Comments

@yvele
Copy link

yvele commented Feb 24, 2020

Following gajus/eslint-plugin-jsdoc#494

Parsing {string[]=} throws an error:

Syntax Error
Expected "...", "/", "[", "|", [ \t], [\n], [\r], or end of input but "=" found.

Note that as a workaround one can wrap the type with parenthesis {(string[])=} but it looks very unnecessary 🤷‍♂

@brettz9

This comment has been minimized.

@brettz9
Copy link
Contributor

brettz9 commented Feb 25, 2020

The docs at https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System#optional do not speak to the issue of whether parentheses are required. I don't think the format of string[]= would provide any ambiguities (so as to call for parentheses) since it seems clear it referring to the whole array as optional (and not to it meaning that it could be a plain string, with the arrayness being optional), so this proposed change makes sense to me.

@brettz9
Copy link
Contributor

brettz9 commented Mar 7, 2020

@yvele : While I am waiting a reply from https://stackoverflow.com/questions/60578125/does-closure-support-jsdoc-array-syntax-like-string , in looking at catharsis, the type parser for jsdoc (which also, when disabling "jsdoc" mode, can support Closure), you can see that at least it believes that Closure doesn't support even the string[] syntax without the optional operator:

var jsdocType = 'string[]';  // Closure Compiler expects Array.<string>

And indeed when I test it on Runkit, Catharsis will complain about this unless I add the "jsdoc" option mode.

I don't know if this could be out-of-date, though, so if I don't hear back on Stackoverflow, maybe we can file an issue with Closure.

As far as the optional = modifier , in testing on Runkit (see at https://runkit.com/brettz9/5e63ae5e0b919b0020ed7fe1 ), I see that the parentheses are necessary even in the jsdoc mode which permits the string[] syntax:

var catharsis = require("catharsis")
catharsis.parse('(string[])=', {jsdoc: true});

...since if you change this to remove the parentheses, an error will be thrown instead of the parsed result that is returned here.

(If you like, there is also the grammar source for Catharsis: https://github.com/hegemonic/catharsis/blob/master/lib/parser.pegjs )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants