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

(CPP) Declaring multiple variables with parentheticals treated as invalid #3148

Closed
edemaine opened this issue Apr 17, 2021 · 4 comments · Fixed by #3155
Closed

(CPP) Declaring multiple variables with parentheticals treated as invalid #3148

edemaine opened this issue Apr 17, 2021 · 4 comments · Fixed by #3155
Labels
bug good first issue Should be easier for first time contributors help welcome Could use help from community language

Comments

@edemaine
Copy link
Contributor

edemaine commented Apr 17, 2021

Declaring multiple variadic variables with initializers generates an invalid error.

Example code (which Github also seems to highlight inconsistently):

vector<int> e(n), depth(n);

Highlight.js 10.4.0 and 10.7.2 generate an Illegal lexeme "," for mode "function" error. Direct reproduction:

require('highlight.js/lib/core').highlight('vector<int> e(n), depth(n);', {language: 'cpp'})

Issue #2917 seems related, and perhaps this has a similarly easy fix.

On the plus side, I just learned about the ignoreIllegals setting, so I'll probably just switch to using that in my context.

@joshgoebel
Copy link
Member

which Github also seems to highlight inconsistently)

Probably because it's impossible to pattern match and know for sure WHAT it is. The first part is probably matching as a function then it doesn't know what to do with the rest.

It's not really a function at all, though I'm not sure we'd be able to tell otherwise. The simple fix here might be to just add , to the end rule of function causing it to end as soon as it see the , - which would probably result in behavior similar to what GitHub is doing....

@joshgoebel
Copy link
Member

I just learned about the ignoreIllegals setting, so I'll probably just switch to using that in my context.

You probably should. See the thread I just posted. I think the use cases for illegals (outside our internal use for auto-detection) are pretty slim.

@joshgoebel joshgoebel added bug good first issue Should be easier for first time contributors help welcome Could use help from community language labels Apr 20, 2021
@joshgoebel
Copy link
Member

The simple fix here might be...

@edemaine Want to make an attempt at a PR?

@edemaine
Copy link
Contributor Author

edemaine commented Apr 20, 2021

Sure. What branch should I be diffing against? master doesn't build (because of #3094). Oops, sorry, I was on an old fork.

@edemaine edemaine changed the title (CPP) Declaring multiple variadic variables treated as invalid (CPP) Declaring multiple variables with parentheticals treated as invalid Apr 20, 2021
edemaine added a commit to edemaine/highlight.js that referenced this issue Apr 20, 2021
edemaine added a commit to edemaine/highlight.js that referenced this issue Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Should be easier for first time contributors help welcome Could use help from community language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants