Jeffrey Arnold committed 9275098

cleaning up StanLexer

Comments (0)

Files changed (2)


 :license: BSD, see LICENSE for details.
-CONSTANTS=[   'e',
+CONSTANTS = [   'e',
-FUNCTIONS=[   'Phi',
+FUNCTIONS = [   'Phi',
-DISTRIBUTIONS=[   'bernoulli',
+DISTRIBUTIONS = [   'bernoulli',


             return 0
 class StanLexer(RegexLexer):
-    """
-    Pygments Lexer for Stan models.
+    """Pygments Lexer for Stan models. 
+    The Stan modeling language is specified in the *Stan 1.0.3
+    Modeling Language Manual* `pdf
+    <>`_.
     *New in Pygments 1.6.*
     name = 'Stan'
     filenames = ['*.stan']
     _RESERVED = ('for', 'in', 'while', 'repeat', 'until', 'if',
-                 'then', 'else', 'true', 'false', 'T',
+                 'then', 'else', 'true', 'false',
                  'lower', 'upper', 'print')
     _TYPES = ('int', 'real', 'vector', 'simplex', 'ordered', 'row_vector',
                         'model', r'generated\s+quantities')),
              bygroups(Keyword.Namespace, Text, Punctuation)),
             # Reserved Words
-            (r'(%s)\b' % r'|'.join(_RESERVED), Keyword.Reserved),
+            (r'(%s)\b' % r'|'.join(_RESERVED), Keyword),
+            # Truncation
+            (r'T(?=\s*\[)', Keyword),
             # Data types
             (r'(%s)\b' % r'|'.join(_TYPES), Keyword.Type),
             # Punctuation
             (r"[;:,\[\]()<>]", Punctuation),
-            # Builtin
+            # functions. check that they are followed  by (
-             % r'|'.join(_stan_builtins.FUNCTIONS
-                         + _stan_builtins.DISTRIBUTIONS),
+             % r'|'.join(_stan_builtins.FUNCTIONS),
+             Name.Builtin),
+            (r'(%s)(?=\s*\()'
+             % r'|'.join(_stan_builtins.DISTRIBUTIONS),
              % r'|'.join(_stan_builtins.CONSTANTS), Keyword.Constant),
             # Special names ending in __, like lp__
             (r'[A-Za-z][A-Za-z0-9_]*__\b', Name.Builtin.Pseudo),
+            # Mark Reserved C++ words as errors
             ('%s\b' % r'|'.join(_stan_builtins.CPP_RESERVED), Error),
             # Regular variable names
             (r'[A-Za-z][A-Za-z0-9_]*\b', Name),
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
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.