Commits

Tim Hatch committed 0ddcc99 Merge

Merged in jrnold/pygments-stan-fixes (pull request #112)

  • Participants
  • Parent commits a1fdd88, aa19b6e

Comments (0)

Files changed (3)

pygments/lexers/_stan_builtins.py

+# -*- coding: utf-8 -*-
+"""
+pygments.lexers._stan_builtins
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+This file contains the names of functions for Stan used by
+``pygments.lexers.math.StanLexer.
+
+:copyright: Copyright 2012 by the Pygments team, see AUTHORS.
+:license: BSD, see LICENSE for details.
+"""
+
+CONSTANTS=[   'e',
+    'epsilon',
+    'log10',
+    'log2',
+    'negative_epsilon',
+    'negative_infinity',
+    'not_a_number',
+    'pi',
+    'positive_infinity',
+    'sqrt2']
+
+FUNCTIONS=[   'Phi',
+    'abs',
+    'acos',
+    'acosh',
+    'asin',
+    'asinh',
+    'atan',
+    'atan2',
+    'atanh',
+    'bernoulli_log',
+    'beta_binomial_log',
+    'beta_log',
+    'binary_log_loss',
+    'binomial_coefficient_log',
+    'categorical_log',
+    'cauchy_log',
+    'cbrt',
+    'ceil',
+    'chi_square_log',
+    'cholesky_decompose',
+    'col',
+    'cols',
+    'cos',
+    'cosh',
+    'determinant',
+    'diag_matrix',
+    'diagonal',
+    'dirichlet_log',
+    'dot_product',
+    'dot_self',
+    'double_exponential_log',
+    'eigenvalues',
+    'eigenvalues_sym',
+    'erf',
+    'erfc',
+    'exp',
+    'exp2',
+    'expm1',
+    'exponential_cdf',
+    'exponential_log',
+    'fabs',
+    'fdim',
+    'floor',
+    'fma',
+    'fmax',
+    'fmin',
+    'fmod',
+    'gamma_log',
+    'hypergeometric_log',
+    'hypot',
+    'if_else',
+    'int_step',
+    'inv_chi_square_log',
+    'inv_cloglog',
+    'inv_gamma_log',
+    'inv_logit',
+    'inv_wishart_log',
+    'inverse',
+    'lbeta',
+    'lgamma',
+    'lkj_corr_cholesky_log',
+    'lkj_corr_log',
+    'lkj_cov_log',
+    'lmgamma',
+    'log',
+    'log10',
+    'log1m',
+    'log1p',
+    'log1p_exp',
+    'log2',
+    'log_sum_exp',
+    'logistic_log',
+    'logit',
+    'lognormal_cdf',
+    'lognormal_log',
+    'max',
+    'mean',
+    'min',
+    'multi_normal_cholesky_log',
+    'multi_normal_log',
+    'multi_student_t_log',
+    'multinomial_log',
+    'multiply_log',
+    'multiply_lower_tri_self_transpose',
+    'neg_binomial_log',
+    'normal_cdf',
+    'normal_log',
+    'ordered_logistic_log',
+    'pareto_log',
+    'poisson_log',
+    'pow',
+    'prod',
+    'round',
+    'row',
+    'rows',
+    'scaled_inv_chi_square_log',
+    'sd',
+    'sin',
+    'singular_values',
+    'sinh',
+    'softmax',
+    'sqrt',
+    'square',
+    'step',
+    'student_t_log',
+    'sum',
+    'tan',
+    'tanh',
+    'tgamma',
+    'trace',
+    'trunc',
+    'uniform_log',
+    'variance',
+    'weibull_cdf',
+    'weibull_log',
+    'wishart_log']
+
+DISTRIBUTIONS=[   'bernoulli',
+    'beta',
+    'beta_binomial',
+    'categorical',
+    'cauchy',
+    'chi_square',
+    'dirichlet',
+    'double_exponential',
+    'exponential',
+    'gamma',
+    'hypergeometric',
+    'inv_chi_square',
+    'inv_gamma',
+    'inv_wishart',
+    'lkj_corr',
+    'lkj_corr_cholesky',
+    'lkj_cov',
+    'logistic',
+    'lognormal',
+    'multi_normal',
+    'multi_normal_cholesky',
+    'multi_student_t',
+    'multinomial',
+    'neg_binomial',
+    'normal',
+    'ordered_logistic',
+    'pareto',
+    'poisson',
+    'scaled_inv_chi_square',
+    'student_t',
+    'uniform',
+    'weibull',
+    'wishart']
+

pygments/lexers/math.py

 
 from pygments.lexers.agile import PythonLexer
 from pygments.lexers import _scilab_builtins
+from pygments.lexers import _stan_builtins
 
 __all__ = ['JuliaLexer', 'JuliaConsoleLexer', 'MuPADLexer', 'MatlabLexer',
            'MatlabSessionLexer', 'OctaveLexer', 'ScilabLexer', 'NumPyLexer',
     filenames = ['*.stan']
 
     _RESERVED = ('for', 'in', 'while', 'repeat', 'until', 'if',
-                'then', 'else', 'true', 'false', 'T')
+                 'then', 'else', 'true', 'false', 'T', 
+                 'lower', 'upper', 'print')
 
     _TYPES = ('int', 'real', 'vector', 'simplex', 'ordered', 'row_vector',
-              'matrix', 'corr_matrix', 'cov_matrix')
-
-    # STAN 1.0 Manual, Chapter 20
-    _CONSTANTS = ['pi', 'e', 'sqrt2', 'log2', 'log10', 'nan', 'infinity',
-                  'epsilon', 'negative_epsilon']
-    _FUNCTIONS = ['abs', 'int_step', 'min', 'max',
-                  'if_else', 'step',
-                  'fabs', 'fdim',
-                  'fmin', 'fmax',
-                  'fmod',
-                  'floor', 'ceil', 'round', 'trunc',
-                  'sqrt', 'cbrt', 'square', 'exp', 'exp2', 'expm1',
-                  'log', 'log2', 'log10', 'pow', 'logit', 'inv_logit',
-                  'inv_cloglog', 'hypot', 'cos', 'sin', 'tan', 'acos',
-                  'asin', 'atan', 'atan2', 'cosh', 'sinh', 'tanh',
-                  'acosh', 'asinh', 'atanh', 'erf', 'erfc', 'Phi',
-                  'log_loss', 'tgamma', 'lgamma', 'lmgamma', 'lbeta',
-                  'binomial_coefficient_log',
-                  'fma', 'multiply_log', 'log1p', 'log1m', 'log1p_exp',
-                  'log_sum_exp',
-                  'rows', 'cols',
-                  'dot_product', 'prod', 'mean', 'variance', 'sd',
-                  'diagonal', 'diag_matrix', 'col', 'row',
-                  'softmax', 'trace', 'determinant', 'inverse', 'eigenvalue',
-                  'eigenvalues_sym', 'cholesky', 'singular_values',
-                  '(log)?normal_p', 'exponential_p', 'gamma_p', 'weibull_p']
-    _DISTRIBUTIONS = ['bernoulli', 'bernoulli_logit', 'binomial',
-                      'beta_binomial', 'hypergeometric', 'categorical',
-                      'ordered_logistic', 'neg_binomial', 'poisson',
-                      'multinomial', 'normal', 'student_t',
-                      'cauchy', 'double_exponential', 'logistic',
-                      'lognormal', 'chi_square', 'inv_chi_square',
-                      'scaled_inv_chi_square', 'exponential',
-                      'gamma', 'inv_gamma', 'weibull', 'pareto',
-                      'beta', 'uniform', 'dirichlet', 'multi_normal',
-                      'multi_normal_cholesky', 'multi_student_t',
-                      'wishart', 'inv_wishart', 'lkj_cov',
-                      'lkj_corr_cholesky']
+              'matrix', 'corr_matrix', 'cov_matrix', 'positive_ordered')
 
     tokens = {
         'whitespace' : [
             (r'(//|#).*$', Comment.Single),
             ],
         'root': [
+            # Stan is more restrictive on strings than this regex
+            (r'"[^"]*"', String),
             # Comments
             include('comments'),
             # block start
             (r"[;:,\[\]()<>]", Punctuation),
             # Builtin
             (r'(%s)(?=\s*\()'
-             % r'|'.join(_FUNCTIONS
-                         + _DISTRIBUTIONS 
-                         + ['%s_log' % x for x in _DISTRIBUTIONS]),
+             % r'|'.join(_stan_builtins.FUNCTIONS
+                         + _stan_builtins.DISTRIBUTIONS),
              Name.Builtin),
             (r'(%s)(?=\s*\()'
-             % r'|'.join(_CONSTANTS),
-             Keyword.Constant),
+             % 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),
             # Regular variable names

tests/examplefiles/example.stan

      matrix[3,3] qux;
      simplex[3] quux;
      ordered[3] corge;
+     positive_ordered[3] wibble;
      corr_matrix[3] grault;
      cov_matrix[3] garply;
 
    // normal_log as a function
    lp__ <- lp__ + normal_log(plugh, 0, 1);
 
+   // print statement and string literal
+   print("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_~@#$%^&*`'-+={}[].,;: ");
+   print("Hello, world!");
+   print("");
+
 }
 generated quantities {
    real bar1;