Wednesday, December 14, 2022

[FIXED] How to get comments and string in regex?

Issue

i have create a programming language KAGSA, and i have to create a syntax highlighter i start with VSCode highlighter i write every thing well but i have problem with regex of strings (more than one line) and comments (more than one line) this is the code : Match is the code: Comments :

"comments": {
            "patterns": [{
                "name": "comment.line.shebang.kagsa",
                "match": "//..*|/\\*(.*?|\n)*\\*/|//|/\\**\\*"
            }]
        },

The problem is wit the /*Comment*/ comment. and string code :

"strings": {
            "name": "string.quoted.double.kagsa",
            "patterns": [{
                "name": "string.quoted.double.kagsa",
                "match": "'(.*?)'|\"(.*?)\"|``(.*?|\n)*``"
            }]
        },

my problem is with ``String`` and the Color i get :

[the output color][https://i.stack.imgur.com/NPbS0.png]


Solution

You have this issue because match doesn't work for multiline string literals. I found a similar problem. As said by Gama11 in his answer:

Try to use a begin / end pattern instead of a simple match.



Answered By - Tim Shidlovskii
Answer Checked By - Clifford M. (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.