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

Add operator detecting for c/cpp #3964

Open
wants to merge 137 commits into
base: main
Choose a base branch
from
Open

Conversation

TOMWT-qwq
Copy link

@TOMWT-qwq TOMWT-qwq commented Jan 13, 2024

  • Add operator detecting for c/cpp.
  • Fix FUNCTION_DECLARATION not matching overloading operator.

Changes

  • Defined OPERATOR constant and added it somewhere.
  • Modified something related to FUNCTION_DECLARATION.

Add symbol
Add symbol
Add symbol
@joshgoebel
Copy link
Member

When you say symbol do you mean operator? If so we'd do this by first putting all the operators (including multi-character ones like !=) into an array then using our own regex.either function to build the actual regex.

@TOMWT-qwq TOMWT-qwq marked this pull request as draft January 14, 2024 04:17
Modified according to [this](highlightjs#3964 (comment)).
@TOMWT-qwq TOMWT-qwq marked this pull request as ready for review January 14, 2024 04:28
Copy link

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

7 files changed

Total change +573 B

View Changes
file base pr diff
es/core.min.js 8.17 KB 8.17 KB +2 B
es/highlight.min.js 8.17 KB 8.17 KB +2 B
es/languages/arduino.min.js 4.61 KB 4.75 KB +144 B
es/languages/cpp.min.js 2.59 KB 2.73 KB +140 B
highlight.min.js 8.2 KB 8.21 KB +2 B
languages/arduino.min.js 4.61 KB 4.76 KB +144 B
languages/cpp.min.js 2.6 KB 2.73 KB +139 B

@joshgoebel
Copy link
Member

joshgoebel commented Jan 14, 2024

I cleaned up the PR a bit to better match our coding standards... but I think the reason this hasn't been done before if the issue with <... sometimes it's an operator, sometimes it's the start of a template... so that case would need to be properly handled. (or maybe this will prove to be simpler in C++ since we only use it inside FUNCTION_TYPE_RE)... not sure.

Right now there are a ton of failing markup tests... you'll need to go thru them and see which are operator related (which will simply need to be updated) and which are template related.

There is a line (you can uncomment) in the test/markup test code that will just "replace" the test result files with whatever we generate - it can be helpful for updating result files but if you do this please proof all the changes by hand to guarantee they are as expected.

@TOMWT-qwq
Copy link
Author

Nothing is matched according to the tests. Is regex.escape(x) working properly? I can't find its defination from the package downloaded here

@TOMWT-qwq TOMWT-qwq changed the title Add symbol detecting for cpp Add operator detecting for cpp Jan 15, 2024
TOMWT-qwq and others added 8 commits January 15, 2024 22:18
Fix this `=` unable to be matched.
Fix a typo.
Implement it gracefully.
Remove duplicated rules.
@joshgoebel
Copy link
Member

So sorry I forgot to push the main file that does the linking... if pull and build it should work now.

Copy link

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

7 files changed

Total change +731 B

View Changes
file base pr diff
es/core.min.js 8.17 KB 8.22 KB +47 B
es/highlight.min.js 8.17 KB 8.22 KB +47 B
es/languages/arduino.min.js 4.61 KB 4.76 KB +151 B
es/languages/cpp.min.js 2.59 KB 2.73 KB +146 B
highlight.min.js 8.2 KB 8.25 KB +45 B
languages/arduino.min.js 4.61 KB 4.76 KB +150 B
languages/cpp.min.js 2.6 KB 2.74 KB +145 B

@TOMWT-qwq
Copy link
Author

ok I'll deal with those tests

relevance: 0
match: FUNCTION_TITLE,
scope: 'title',
keywords: "operator",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

图片
It is working now.

src/languages/c.js Outdated Show resolved Hide resolved
@TOMWT-qwq
Copy link
Author

TOMWT-qwq commented Jan 28, 2024

You know, a powerful part of hljs is contains: ["self"]. However, a regex is not that powerful. I've tried to do smth, but it doesn't work as expected. I don't think we can recognize everything clearly like a complier now.

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

Successfully merging this pull request may close these issues.

None yet

3 participants