77QingLiu / vscode-SAS.tmLanguage

TextMate grammar based Syntax Highlighting for SAS as used in Visual Studio code
https://marketplace.visualstudio.com/items?itemName=77qingliu.sas-syntax
MIT License
22 stars 7 forks source link

line_comment_string issue/question #2

Closed JLWFuQrioea69ugsykvQcg closed 6 years ago

JLWFuQrioea69ugsykvQcg commented 6 years ago

The "line_comment_string" works as intended when the comment is on it's own line with nothing preceding it. How would I modify the syntax below to accommodate scenarios where the comment occurs within a data step, etc. and follows valid code? I've attached a sample below where "test comment 1" highlights correctly, but "test comment 2" which follows the set statement does not. The SAS code works as intended but he highlighting does not flag it. I know I can move all my comments to their own line but this isn't always ideal depending on the comment and formatting.

   "line_comment_string": {
        "name": "comment.line.sas",
        "begin": "(^[\\s%]*\\*)",
        "end": ";",
        "beginCaptures":{
            "0":{
                "name": "punctuation.definition.comment"
            }
        },        
        "patterns": [
            {
                "name": "constant.character.escape.sas",
                "match": "\\\\."
            }
        ]
    },

            data members.mbe_mrn ;
            * test comment1 ;
                set members.mbe_mrn_0 ; * test comment2;
                if end_date = . then end_date = '31DEC4000'd ;
                if start_date = end_date then
                    delete ;
            run ;
JLWFuQrioea69ugsykvQcg commented 6 years ago

Ok so I thought I figured it out but not so much. I want it to identify the comment in a line with other code and mark it as a comment only if it's followed by a ";". How would I do that?

JLWFuQrioea69ugsykvQcg commented 6 years ago

Ok I think I solved my issue using an "or" with a positive lookbehind looking for a ";". This is my syntax: "(^[\s%]\*)|(?<=;)[\s%]\*" It seems to work everywhere I checked it and not mess up other highlighting.