ziaw avatar ziaw committed cc2a077

fix expr injection into quasiquotation

Comments (0)

Files changed (2)

pygments/lexers/dotnet.py

                 (r'\$\s*"', String, 'splice-string'),
                 (r'\$\s*<#', String, 'splice-string2'),
                 (r'<#', String, 'recursive-string'),
+
+                (r'(<\[)\s*(' + cs_ident + ':)?', Keyword),
+                (r'\]\>', Keyword),
+
+                # quasiquotation only
+                (r'\$' + cs_ident, Name), 
+                (r'(\$)(\()', bygroups(Name, Punctuation), 'splice-string-content'),
+
                 (r'[~!%^&*()+=|\[\]:;,.<>/?-]', Punctuation),
                 (r'[{}]', Punctuation),
                 (r'@"(\\\\|\\"|[^"])*"', String),
                 (r'"(\\\\|\\"|[^"\n])*["\n]', String),
                 (r"'\\.'|'[^\\]'", String.Char),
-                (r"[0-9](\.[0-9]*)?([eE][+-][0-9]+)?"
-                 r"[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?", Number),
+		(r"0[xX][0-9a-fA-F]+[Ll]?", Number),
+                (r"[0-9](\.[0-9]*)?([eE][+-][0-9]+)?[flFLdD]?", Number),
                 (r'#[ \t]*(if|endif|else|elif|define|undef|'
                  r'line|error|warning|region|endregion|pragma)\b.*?\n',
                  Comment.Preproc),
                 (r'(abstract|and|as|base|catch|def|delegate|'
                 r'enum|event|extern|false|finally|'
                 r'fun|implements|interface|internal|'
-                r'is|macro|match|matches|module|mutable|new|'
+                r'is|macro|match|matches|mutable|new|'
                 r'null|out|override|params|partial|private|'
                 r'protected|public|ref|sealed|static|'
                 r'syntax|this|throw|true|try|type|typeof|'
                 r'virtual|volatile|when|where|with|'
                 r'assert|assert2|async|break|checked|continue|do|else|'
                 r'ensures|for|foreach|if|late|lock|new|nolate|'
-                r'otherwise|regexp|repeat|requires|return|surroundwith|unchecked|unless|using|while|yield)\b', Keyword),
-                (r'(global)(::)', bygroups(Keyword, Punctuation)),
+                r'otherwise|regexp|repeat|requires|return|surroundwith|'
+                r'unchecked|unless|using|while|yield)\b', Keyword),
                 (r'(bool|byte|char|decimal|double|float|int|long|object|sbyte|'
-                 r'short|string|uint|ulong|ushort)\b\??', Keyword.Type),
+                 r'short|string|uint|ulong|ushort|void|array|list)\b\??', Keyword.Type),
+                (r'(:>?)\s*(' + cs_ident + r'\??)', bygroups(Punctuation, Keyword.Type)),
                 (r'(class|struct|variant|module)(\s+)', bygroups(Keyword, Text), 'class'),
                 (r'(namespace|using)(\s+)', bygroups(Keyword, Text), 'namespace'),
                 (cs_ident, Name),
             ],
             'splice-string': [
                 (r'[^"$]',  String), 
-                (r'\$\(', Name, 'splice-string-content'),
-                (r'\$', Name, 'splice-string-ident'),
+                (r'\$' + cs_ident, Name),
+                (r'(\$)(\()', bygroups(Name, Punctuation), 'splice-string-content'),
                 (r'\\"',  String),
                 (r'"',  String, '#pop')
             ],
             'splice-string2': [
                 (r'[^#<>$]',  String), 
-                (r'\$\(', Name, 'splice-string-content'),
-                (r'\$', Name, 'splice-string-ident'),
+                (r'\$' + cs_ident, Name),
+                (r'(\$)(\()', bygroups(Name, Punctuation), 'splice-string-content'),
                 (r'<#',  String, '#push'),
                 (r'#>',  String, '#pop')
             ],
                 (r'if|match', Keyword), 
                 (r'[~!%^&*+=|\[\]:;,.<>/?-]', Punctuation),
                 (cs_ident, Name), 
-                (r'\(', Name, '#push'),
-                (r'\)', Name, '#pop')
-            ],
-            'splice-string-ident': [
-                (cs_ident,  Name, '#pop'), 
-                (r'.',  String, '#pop')
-            ],
+                (r'\(', Punctuation, '#push'),
+                (r'\)', Punctuation, '#pop')
+            ]
         }
 
     def __init__(self, **options):

tests/examplefiles/nemerle_sample.n

     public virtual someMethod(str : string) : list[double]
     {
       def x = "simple string";
-      def x = $"simple $splice string";
+      def x = $"simple $splice string $(spliceMethod())";
       def x = <#
         recursive <# string #> sample
       #>;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.