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

(c-likes) Macro including single < breaks because it thinks it's a string #1964

Closed
paladox opened this issue Jan 31, 2019 · 10 comments · Fixed by #2265
Closed

(c-likes) Macro including single < breaks because it thinks it's a string #1964

paladox opened this issue Jan 31, 2019 · 10 comments · Fixed by #2265
Labels
good first issue Should be easier for first time contributors help welcome Could use help from community language

Comments

@paladox
Copy link
Member

paladox commented Jan 31, 2019

@joshgoebel
Copy link
Member

I can't make any sense of this or these links. If there is a bug with a specific language syntax please tell us which and if you could provide a jsfiddle reproducing the issue that'd be great:

Template you can use:
https://jsfiddle.net/ajoshguy/nagkqytv/

@joshgoebel joshgoebel added needs reproduction Needs a reproducible example or sample and removed question labels Oct 13, 2019
@joshgoebel joshgoebel changed the title Messed up syntax highlighting involving macros (language?) Messed up syntax highlighting involving macros Oct 13, 2019
@joshgoebel
Copy link
Member

Ping.

@paladox
Copy link
Member Author

paladox commented Oct 20, 2019

@yyyc514 really sorry for the late reply.

If you do:

#include "ios/chrome/browser/ui/ui_util.h"

#import <UIKit/UIKit.h>

#include "base/logging.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#include "ui/base/device_form_factor.h"
#include "ui/gfx/ios/uikit_util.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif

bool IsIPadIdiom() {
  return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET;
}

const CGFloat kPortraitWidth[INTERFACE_IDIOM_COUNT] = {
    320,  // IPHONE_IDIOM
    768   // IPAD_IDIOM
};

bool IsHighResScreen() {
  return [[UIScreen mainScreen] scale] > 1.0;
}

bool IsPortrait() {
  UIInterfaceOrientation orient = GetInterfaceOrientation();
// If building with an SDK prior to iOS 8 don't worry about
// UIInterfaceOrientationUnknown because it wasn't defined.
#if !defined(__IPHONE_8_0) || __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0
  return UIInterfaceOrientationIsPortrait(orient);
#else
  return UIInterfaceOrientationIsPortrait(orient) ||
         orient == UIInterfaceOrientationUnknown;
#endif  // SDK
}

bool IsLandscape() {
  return UIInterfaceOrientationIsLandscape(GetInterfaceOrientation());
}

For example, everything from #if !defined(__IPHONE_8_0) || __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0 and below is coloured in red (even IsLandscape() and any other function or what not after).

@joshgoebel
Copy link
Member

Are you specifying the language? If so which language?

@paladox
Copy link
Member Author

paladox commented Oct 20, 2019

@yyyc514 It's objectivec.

@joshgoebel
Copy link
Member

Can you make a fiddle that shows the issue? I gave you a template above?

@paladox
Copy link
Member Author

paladox commented Oct 22, 2019

@yyyc514 ah, sorry here's the fiddle: https://jsfiddle.net/8bvgu065/

@joshgoebel
Copy link
Member

Thanks so much. It's the <. We likely think it's the start of a string and then can't ever find the end of the string, so comment goes on forever.

The grammar needs to be fixed to look-ahead and make sure there is actually an end > and if not to not consider it a string. Also figuring out what is and isn't allowed inside a path string might help also... ie #include < some file> probably isn't allowed... so just figuring out what is valid might be one quick fix for this.

@joshgoebel
Copy link
Member

This probably has connections to the other C-like grammars also. (for someone wanting to work on a fix)

@joshgoebel joshgoebel added good first issue Should be easier for first time contributors help welcome Could use help from community language and removed needs reproduction Needs a reproducible example or sample labels Oct 22, 2019
@joshgoebel joshgoebel changed the title (language?) Messed up syntax highlighting involving macros (c-likes) Macro including single < breaks because it thinks it's a string Oct 22, 2019
davidben added a commit to davidben/highlight.js that referenced this issue Nov 10, 2019
The objectivec highlighting had a few bugs and was missing a few
features:

- Expressions including < was misidentified as a string like <stdio.h>
  (fixes highlightjs#1964).

- Keywords like if, else, endif, etc. were not highlighted.

- The escape sequences in string literals were not parsed.

- Line continuations were not parsed.

- Comments were not parsed.

Fix all these and pull in the preprocessor test from cpp. (This is
actually objectivec's first markup test. It probably could do with tests
beyond just this feature.)
davidben added a commit to davidben/highlight.js that referenced this issue Nov 10, 2019
The objectivec highlighting had a few bugs and was missing a few
features:

- Expressions with < were misidentified as a string like <stdio.h>
  (fixes highlightjs#1964).

- Keywords like if, else, endif, etc. were not highlighted.

- The escape sequences in string literals were not parsed.

- Line continuations were not parsed.

- Comments were not parsed.

Fix all these and pull in the preprocessor test from cpp. (This is
actually objectivec's first markup test. It probably could do with tests
beyond just this feature.)
davidben added a commit to davidben/highlight.js that referenced this issue Nov 10, 2019
The objectivec highlighting had a few bugs and was missing a few
features:

- Expressions with < were misidentified as a string like <stdio.h>
  (fixes highlightjs#1964).

- Keywords like if, else, endif, etc. were not highlighted.

- The escape sequences in string literals were not parsed.

- Line continuations were not parsed.

- Comments were not parsed.

Fix all these by adapting cpp's preprocessor definition. Pull in the
preprocessor test from cpp. (This is actually objectivec's first markup
test. It probably could do with tests beyond just this feature.)
@davidben
Copy link
Contributor

Looks like this is specific to objectivec. The objectivec syntax definition is separate from the cpp one, with a much simpler preprocessor definition. #2265 syncs this part up.

davidben added a commit to davidben/highlight.js that referenced this issue Nov 12, 2019
The objectivec highlighting had a few bugs and was missing a few
features:

- Expressions with < were misidentified as a string like <stdio.h>
  (fixes highlightjs#1964).

- Keywords like if, else, endif, etc. were not highlighted.

- The escape sequences in string literals were not parsed.

- Line continuations were not parsed.

- Comments were not parsed.

Fix all these by adapting cpp's preprocessor definition. Pull in the
preprocessor test from cpp. (This is actually objectivec's first markup
test. It probably could do with tests beyond just this feature.)
joshgoebel pushed a commit that referenced this issue Nov 12, 2019
The objectivec highlighting had a few bugs and was missing a few
features:

- Expressions with < were misidentified as a string like <stdio.h>
  (fixes #1964).
- Keywords like if, else, endif, etc. were not highlighted.
- The escape sequences in string literals were not parsed.
- Line continuations were not parsed.
- Comments were not parsed.

Fix all these by adapting cpp's preprocessor definition. Pull in the
preprocessor test from cpp. (This is actually objectivec's first markup
test. It probably could do with tests beyond just this feature.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

3 participants