diff options
Diffstat (limited to 'pygments/lexers/math.py')
-rw-r--r-- | pygments/lexers/math.py | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/pygments/lexers/math.py b/pygments/lexers/math.py index a6d7a5c5..ead579e3 100644 --- a/pygments/lexers/math.py +++ b/pygments/lexers/math.py @@ -1010,34 +1010,40 @@ class SLexer(RegexLexer): ], 'valid_name': [ (r'[a-zA-Z][0-9a-zA-Z\._]+', Text), - (r'`.+`', String.Backtick), + # can begin with ., but not if that is followed by a digit + (r'\.[a-zA-Z_][0-9a-zA-Z\._]+', Text), ], 'punctuation': [ - (r'\[|\]|\[\[|\]\]|\$|\(|\)|@|:::?|;|,', Punctuation), + (r'\[{1,2}|\]{1,2}|\(|\)|;|,', Punctuation), ], 'keywords': [ - (r'for(?=\s*\()|while(?=\s*\()|if(?=\s*\()|(?<=\s)else|' - r'(?<=\s)break(?=;|$)|return(?=\s*\()|function(?=\s*\()', + (r'(if|else|for|while|repeat|in|next|break|return|switch|function)' + r'(?![0-9a-zA-Z\._])', Keyword.Reserved) ], 'operators': [ - (r'<-|-|==|<=|>=|<|>|&&|&|!=|\|\|?', Operator), - (r'\*|\+|\^|/|%%|%/%|=', Operator), - (r'%in%|%*%', Operator) + (r'<<?-|->>?|-|==|<=|>=|<|>|&&?|!=|\|\|?|\?', Operator), + (r'\*|\+|\^|/|!|%[^%]*%|=|~|\$|@|:{1,3}', Operator) ], 'builtin_symbols': [ - (r'(NULL|NA|TRUE|FALSE|NaN)\b', Keyword.Constant), + (r'(NULL|NA(_(integer|real|complex|character)_)?|' + r'Inf|TRUE|FALSE|NaN|\.\.(\.|[0-9]+))' + r'(?![0-9a-zA-Z\._])', + Keyword.Constant), (r'(T|F)\b', Keyword.Variable), ], 'numbers': [ - (r'(?<![0-9a-zA-Z\)\}\]`\"])(?=\s*)[-\+]?[0-9]+' - r'(\.[0-9]*)?(E[0-9][-\+]?(\.[0-9]*)?)?', Number), - (r'\.[0-9]*(E[0-9][-\+]?(\.[0-9]*)?)?', Number), + # hex number + (r'0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?', Number.Hex), + # decimal number + (r'[+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?[Li]?', + Number), ], 'statements': [ include('comments'), # whitespaces (r'\s+', Text), + (r'`.*?`', String.Backtick), (r'\'', String, 'string_squote'), (r'\"', String, 'string_dquote'), include('builtin_symbols'), @@ -1060,10 +1066,10 @@ class SLexer(RegexLexer): # ('\}', Punctuation, '#pop') #], 'string_squote': [ - (r'[^\']*\'', String, '#pop'), + (r'([^\'\\]|\\.)*\'', String, '#pop'), ], 'string_dquote': [ - (r'[^\"]*\"', String, '#pop'), + (r'([^"\\]|\\.)*"', String, '#pop'), ], } |