Commits

Jeffrey Arnold  committed cc94146

StanLexer: accounted for new bound syntax

  • Participants
  • Parent commits 2216ca3

Comments (0)

Files changed (2)

File pygments/lexers/math.py

 
 class BugsLexer(RegexLexer):
     """
-    Pygments Lexer for Stan models.
+    Pygments Lexer for OpenBugs and WinBugs models.
 
     *New in Pygments 1.6.*
     """
                   '(log)?normal_p', 'exponential_p', 'gamma_p', 'weibull_p']
     _DISTRIBUTIONS = ['bernoulli', 'bernoulli_logit', 'binomial',
                       'beta_binomial', 'hypergeometric', 'categorical',
-                      'ordered_logistic', 'negative_binomial', 'poisson',
+                      'ordered_logistic', 'neg_binomial', 'poisson',
                       'multinomial', 'normal', 'student_t',
                       'cauchy', 'double_exponential', 'logistic',
                       'lognormal', 'chi_square', 'inv_chi_square',
             (r"\s+", Text),
             ],
         'comments' : [
-            # do not use stateful comments
             (r'(?s)/\*.*?\*/', Comment.Multiline),
             # Comments
             (r'(//|#).*$', Comment.Single),
             # Data types
             (r'(%s)\b' % r'|'.join(_TYPES), Keyword.Type),
             # Punctuation
-            (r"[;:,\[\]()]", Punctuation),
+            (r"[;:,\[\]()<>]", Punctuation),
             # Builtin
             (r'(%s)(?=\s*\()'
              % r'|'.join(_FUNCTIONS
              % r'|'.join(_CONSTANTS),
              Keyword.Constant),
             # Special names ending in __, like lp__
-            (r'\b[A-Za-z][A-Za-z0-9_]*__\b', Name.Builtin.Pseudo),
+            (r'[A-Za-z][A-Za-z0-9_]*__\b', Name.Builtin.Pseudo),
             # Regular variable names
-            (r'\b[A-Za-z][A-Za-z0-9_]*\b', Name),
+            (r'[A-Za-z][A-Za-z0-9_]*\b', Name),
             # Real Literals
             (r'-?[0-9]+(\.[0-9]+)?[eE]-?[0-9]+', Number.Float),
             (r'-?[0-9]*\.[0-9]*', Number.Float),
             (r'-?[0-9]+', Number.Integer),
             # Assignment operators
             # SLexer makes these tokens Operators. 
-            (r'(<-|~)', Operator),
-            # Infix and prefix operators
-            (r"(\+|-|\.?\*|\.?/|\\|')", Operator),
+            (r'<-|~', Operator),
+            # Infix and prefix operators (and = )
+            (r"\+|-|\.?\*|\.?/|\\|'|=", Operator),
             # Block delimiters
             (r'[{}]', Punctuation),
             ]

File tests/examplefiles/example.stan

      corr_matrix[3] grault;
      cov_matrix[3] garply;
 
+     real<lower=-1,upper=1> foo1;
+     real<lower=0> foo2;
+     real<upper=0> foo3;
+
      // bad names
      // includes .
-     real foo.;
+     // real foo.;
      // beings with number
      //real 0foo;
      // begins with _
 
 }
 generated quantities {
-   real foo1;
-   foo1 <- foo + 1;
+   real bar1;
+   bar1 <- foo + 1;
 }
 
 ## Baddness