Git Product home page Git Product logo

better-cpp-syntax's Introduction

Screen Shot 2022-02-11 at 12 01 19 PM

Sponsors

Easy pair programming with any IDE. Duckly enables you to talk, share your code in real-time, server and terminal with people using different IDEs.
Try it out for free


What does this extension do?

This will get you the bleeding-edge syntax highlighting for C++. Which means your theme will be able to color your code better. This used to be a fix, but then VS Code starting using it as the official source for C and C++ highlighting.

NOTE: The default VS Code theme does not color much. Switch to the Dark+ theme (installed by default) or use a theme like one of the following to benefit from the changes:

How do I use the extension?

Just install the VS Code extension and the changes will automatically be applied to all relevant files.
Link: https://marketplace.visualstudio.com/items?itemName=jeff-hykin.better-cpp-syntax

Comparison (Material Theme)

compare

How do I use the grammar? (as an upstream for my non-vs code editor)

  1. Watch the the "Major Changes" thread here to know when I change licenses, the codebase structure, or just major highlighting changes.
  2. I support non-VS Code usecases. E.g. yes, you are welcome to open issues like this one that don't affect VS Code.

What is different from atom/language-c?

It fixes:

  • The issue of single quotes inside #error and #warning being highlighted when then shouldn't be
  • The issue of initialization functions only highlighting the first parenthesis
  • The bug that treats the 'and' and 'or' operator as functions (instead of operators) when they are followed by ()'s
  • Old C99 function highlighting that broke the standard function highlighting
  • The failure of highlighting for the semicolon after namespaces
  • The missing operator overloading symbols
  • The failure to tag operator overloading functions as functions
  • The failure to tag implicit operator overrides
  • The marking of some %'s as invalid inside of strings atom/language-c#289
  • The highlighting of namespaces with ::'s atom/language-c#260
  • The issue of the C++ syntax depending on (and getting screwed up by) the C syntax
  • multiple inheritance atom/language-c#245
  • And many many more issues (#318, #309, #270, #246, etc)

It adds:

  • Parameter highlighting
  • Highlighting of embedded assembly code (if you have an assembly syntax installed)
  • Function-pointer highlighting
  • Lambda highlighting
  • C++14 literal support (100'000ms)
  • Template definition syntax highlighting (including C++ 2020 syntax)
  • Better object identification
  • Improved scope resolution :: syntax
  • Highlighting of templated function calls aFunction<int>(arguments)
  • Additional specificity for many existing tags
  • Many other features

Like this extension?

Contributing

If you'd like to help improve the syntax, take a look at main/main.rb. And make sure to take a look at documentation/CONTRIBUTING.md to get a better idea of how the code works.

Planned future fixes/features:

  • Add tagging for type-casting statements
  • Add tagging for custom types words
  • Better support for dereferenced/pointer tagging
  • Full C++ 2020 support (module imports, arrow return types, etc.)
  • Improving template types

What if I see a highlighting bug?

Let me know! Post an issue on https://github.com/jeff-hykin/better-cpp-syntax I love regular expressions, and PR's are always welcome.

Did you write all of this yourself?

The original JSON was taken from https://github.com/atom/language-c
@matter123 wrote every massive pull request, from simple bugfixes up to the entire textmate testing suite
@j-cortial has fixed many lingering bugs
The #error fix was taken from fnadeau's pull request here: atom/language-c#251
Thank you @matter123, @j-cortial, and @fnadeau!
The rest of the ruby is authored by @jeff-hykin

better-cpp-syntax's People

Contributors

a-stewart avatar asottile avatar davidgoldman avatar dependabot[bot] avatar dodoent avatar hyrious avatar j-cortial avatar jeff-hykin avatar jogo- avatar mansoormohsin avatar matter123 avatar peaceshi avatar soroshsabz avatar yanpas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

better-cpp-syntax's Issues

Unit Testing

This is probably going to take awhile, but it needs to be done in order to prevent introducing new bugs when fixing old ones.

Normally unit tests are not so bad when written beforehand, but when there's already ~3000 lines of untested code its a bit more difficult.

Space between class access specifier and colon

Describe the bug

  • OS and Version: Ubuntu 18.04.2 LTS
  • VS Code Version: 1.31.1
  • Better C++ Syntax Extension Version: 1.4.13
  • Other extensions you installed (and if the issue persists after disabling them): C/C++. The issue persists after disabling it.
  • A clear and concise description of what the bug is: When adding a space between a class access specifier, such as 'public', and the colon, the access specifier loses its coloring.

To Reproduce

  1. Create a new file with extension '.cpp'.
  2. Input the code below in the newly created file.
class C
{
  public :
};
  1. Try removing the space between 'public' and ':'. The keyword should be colored.

Expected behavior
The keyword shall be colored regardless of space between the keyword and colon.

Screenshots
Screenshot from 2019-03-11 17-12-48

Additional context
This issue exists with default VS code highlighting as well. I'm not sure if it's syntactically correct, but it compiles on GCC/clang.

Inheritance access specifier not colorized at linebreak

Describe the bug

  • OS and Version: Ubuntu 18.04.2 LTS
  • VS Code Version: 1.31.1
  • Better C++ Syntax Extension Version: 1.4.11
  • Other extensions you installed (and if the issue persists after disabling them): C/C++. The issue persists after disabling it.
  • A clear and concise description of what the bug is: When linebreaking after an inheritance colon, the access specifier, such as 'public', is not colorized.

To Reproduce

  1. Create a new file with extension '.cpp'.
  2. Input the code below in the newly created file. Note the linebreak after the colon.
class B
{};

class A : 
  public B
{};
  1. Try removing the linebreak, writing 'public B' on the same line as 'class A'. The keyword is suddenly colorized.

Expected behavior
The 'public' keyword should be colorized regardless if there is a linebreak or not.

Screenshots
screenshot from 2019-03-08 15-36-37

Additional context
This issue exists with default VS code highlighting as well.

Multiline Comments

A multiline comment with preceding asterisks on each line highlights weird in VS Code. (See below). I'd like to see the entire comment green in this example, not just everything after the first line. Can this fix be included in the extension?

NOTE: The end */ will be green if it's moved up a line.

selection_084

universal-charcter-names not allowed in identifiers

According to the standard identifiers are allowed to contain universal-character-names ([lex.name]/1).
Universal-character-names are of the the pattern /\\u[0-9a-fA-F]{4}/ or /\\U[0-9a-fA-F{8}/. When these characters are inserted into a place where identifiers are expected highlighting breaks.

Screenshot from 2019-03-12 11-14-12

generate_c.rb does not generate grammar

generate_c.rb is not able to generate syntaxes/c.tmLanguage.json as It appears to be a stub and c_grammar is not a Grammar object. Additionally generate_c.rb is missing several referenced variables:

  • function_definition_pattern
  • probably_a_parameter_2_groups
  • operator_overload_4_groups
  • variable_name_without_bounds
  • non_primitive_types
  • primitive_types

This issue precludes fixing issues in the C grammar.

Base classes without access specifier not tagged.

Example code:

class foo : bar {};
class foo : public bar {};

One line 1 bar has the scope meta.class-struct-block.cpp source.cpp.
One line 2 bar has the scope entity.name.type.inherited.cpp meta.class-struct-block.cpp source.cpp.
The scope for bar on each line should be identical.
This is not a regression, and the issue existed prior to #49.

function names containing keywords are colored incorrectly

Functions that start with delete or namespace are not colored as functions, and the keyword portion is colored as a keyword.

Additionally, functions whose names are identifiers with special meaning are again not colored as functions.

See photo.
screenshot from 2019-03-07 10-02-55

This issue is not present in the default c/cpp grammar
screenshot from 2019-03-07 10-02-32

Thanks

meta.processor and meta.struct are never closed

atom/language-c#267

#pragma once

#include <type_traits>

#define IsPointDef(...) \
    template<> \
    struct IsPoint<__VA_ARGS__> \
        {\
        static const bool isPoint = true;\
                }

#define ArrayBasedPointDef(T) \
    IsPointDef(T); \
    template<> \
    struct IsArrayBasedPoint<T>:public std::true_type \
        {};



#define XYBasedPointDef(T) \
    IsPointDef(T); \
    template<> \
    struct IsXYBasedPoint<T>:public std::true_type \
{};

#define TypeTAndUIsPoint \
    template<typename T, typename U, class = typename std::enable_if<IsPoint<T>::isPoint>::type, class = typename std::enable_if<IsPoint<U>::isPoint>::type>

namespace Navigation
{
    namespace Utils
    {
        template<typename T>
        struct IsPoint
        {
            static const bool isPoint = false;
        };

        template<typename T>
        struct IsArrayBasedPoint
        {
            static const bool value = false;
        };

        template<typename T>
        struct IsXYBasedPoint
        {
            static const bool value = false;
        };

    }
}

Two open angle brackets in template argument list disables syntax highlighting for rest of file.

If a template has two 2 < (including the one after template than most syntax highlighting is disabled for the rest of the file.

Screenshot from 2019-03-16 11-50-27

The rest of the file has the TM scope of template.definition. It looks like the issue first appeared in 1.4.0 ( 1.3.3 does not exhibit this issue).

For debugging

namespace test {
	template <class T>
	struct test {
		template <class U = std::vector<int>>
		bool operator()(U k) {}
	};
	struct test2 {
		bool operator()() = delete;
	};
} // namespace test

// no syntax highlighting
class test2 {};

When in a namespace, function like keywords at start of line is tagged as a constructor.

Example code:

namespace {
	using A = decltype(5);
	decltype(5) B = A();
}

This effects decltype, static_assert, template deduction guides (migh not be incorrect however), some macros.
This is because the namespace pattern includes :constructors before $base.

Removing :constructors seems to have almost no negative side effects. (One exception is test::test(){} is not tagged as a constructor, it is also not tagged outside of a namespace currently as well, so a better solution should be found). I cannot think of why constructors should be treated differently inside/outside a namespace.

enum types missing highlighting

From: #45
Effects: C, C++

In the declaration enum bar b;, bar has incorrect highlighting. bar has the scope of source.{c,cpp}, it should have the scope entity.name.type.{c,cpp} source.{c,cpp}

Image:
C++

Example:

enum bar b;
int foo() {
    enum bar b;
}

Preprocessor conditional logic

atom/language-c#269
atom/language-c#290
atom/language-c#280

Almost all of these involve code that is highlighted differently because of preprocessor statements.
Most of them are impossible because the TextMate parser needs to find the end of something, but the preprocessor makes it possible for there to be two ends, and TextMate can't handle conditional endings.

However, one improvement that probably can be made, is that the macros should not include any of the TextMate range patterns. This is because if they do, they can screw up the entire rest of the file.

some consistent characteristics of highlight

For a class or struct name, guarantee consistency in the whole file.
My vscode define a struct such as in a .cpp file:
image
I hope the node and MAX can have the same color in the main function.
Can I have some ways to solve this?

No color for symbols

This extension
image

VSCode default
image

This is a minor issue, but +, * and & all lost its color when using this extension, ideally they should be highlighted with a different color than int.

[[attributes]] break syntax highlighting until `{`

Similar to #37 after a C++ attribute [[fallthrough]],[[nodiscard]], etc. Syntax highlighting breaks until {.

Example

switch(test) {
	case 1:
	break;
	case 2: [[fallthrough]];
	case 3: break; // no syntax highlighting
}
void func1();
[[noreturn]] void func2(/*syntax highlighting*/); // no syntax highlighting
struct st { // syntax highlighting works now
};
void func3();

Image:
Screenshot from 2019-04-01 19-53-11

Grammer causes exception in vscode-textmate

The grammar causes visual studio code to have a type error in the form of [renderer1] [error] Cannot create property 'id' on string 't': TypeError: Cannot create property 'id' on string 't' git-bisect has determined that the offending commit is 216543b. The issue is found in VSCode 1.32 and insiders as well as the standalone https://github.com/Microsoft/vscode-textmate/ package. The type error seems to have little if any impact on the actual application of scopes, It does however seem to occasionally cause the theme to not be applied.

Screen Shot 2019-03-20 at 1 44 25 PM

example:

namespace test {
	class test {
		test(){};
	};
} // namespace test

if constexpr causes incorrect syntax highlighting for rest of line

Example code

int main() {
      if constexpr(std::is_signed_v<char>>) { // no syntax highlighting
      }
}

The entirety of constexpr(std::is_signed_v<char>>) { // no syntax highlighting has the scope of meta.function-call.

Additionally, the developer tools console has the error [2] - Grammar is in an endless loop - Grammar pushed the same rule without advancing.

Neither the begin or end of the range pattern for "c_function_call" consume any characters. Per microsoft/vscode-textmate#12 VSCode has limited support for zero width range matches.

variables not being tokenized

Variables are not being tokenized in global or local scope. This is an issue with C syntax but possibly exists in C++ as well.

Screen Shot 2019-03-27 at 10 32 44 PM

Screen Shot 2019-03-27 at 10 33 04 PM

new and delete not colorized

Describe the bug

  • OS and Version: Ubuntu 18.04.2 LTS
  • VS Code Version: 1.32.3
  • Better C++ Syntax Extension Version: 1.6.5
  • Other extensions you installed (and if the issue persists after disabling them): C/C++. The issue persists after disabling it.
  • A clear and concise description of what the bug is: The keywords 'new' and 'delete' are not colorized at all.

To Reproduce

  1. Create a new file with extension '.cpp'.
  2. Input the code below in the newly created file.
int main()
{
    int* i = new int;
    delete i;
}

Expected behavior
'new' and 'delete' should be colorized.

Additional context
May be true for other keywords as well.

Types in C are missing highlighting

From #45
Effects: C

The code fragment struct f foo has incorrect highlighting. f has the scope source.c when it should have entity.name.type.c source.c

Image:
C
Example:

struct f foo;
int func() {
    struct f foo;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.