diff options
-rw-r--r-- | pygments/lexers/_mapping.py | 6 | ||||
-rw-r--r-- | pygments/lexers/bugs.py | 298 | ||||
-rw-r--r-- | pygments/lexers/math.py | 284 |
3 files changed, 302 insertions, 286 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 00bef11b..6f342552 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -42,7 +42,7 @@ LEXERS = { 'BooLexer': ('pygments.lexers.dotnet', 'Boo', ('boo',), ('*.boo',), ('text/x-boo',)), 'BrainfuckLexer': ('pygments.lexers.other', 'Brainfuck', ('brainfuck', 'bf'), ('*.bf', '*.b'), ('application/x-brainfuck',)), 'BroLexer': ('pygments.lexers.other', 'Bro', ('bro',), ('*.bro',), ()), - 'BugsLexer': ('pygments.lexers.math', 'BUGS', ('bugs', 'winbugs', 'openbugs'), ('*.bugs',), ()), + 'BugsLexer': ('pygments.lexers.jags', 'BUGS', ('bugs', 'winbugs', 'openbugs'), ('*.bugs',), ()), 'CLexer': ('pygments.lexers.compiled', 'C', ('c',), ('*.c', '*.h', '*.idc'), ('text/x-chdr', 'text/x-csrc')), 'CMakeLexer': ('pygments.lexers.text', 'CMake', ('cmake',), ('*.cmake', 'CMakeLists.txt'), ('text/x-cmake',)), 'CObjdumpLexer': ('pygments.lexers.asm', 'c-objdump', ('c-objdump',), ('*.c-objdump',), ('text/x-c-objdump',)), @@ -124,7 +124,7 @@ LEXERS = { 'IokeLexer': ('pygments.lexers.jvm', 'Ioke', ('ioke', 'ik'), ('*.ik',), ('text/x-iokesrc',)), 'IrcLogsLexer': ('pygments.lexers.text', 'IRC logs', ('irc',), ('*.weechatlog',), ('text/x-irclog',)), 'JSONLexer': ('pygments.lexers.web', 'JSON', ('json',), ('*.json',), ('application/json',)), - 'JagsLexer': ('pygments.lexers.math', 'JAGS', ('jags',), ('*.jags',), ()), + 'JagsLexer': ('pygments.lexers.bugs', 'JAGS', ('jags',), ('*.jags',), ()), 'JadeLexer': ('pygments.lexers.web', 'Jade', ('jade', 'JADE'), ('*.jade',), ('text/x-jade',)), 'JavaLexer': ('pygments.lexers.jvm', 'Java', ('java',), ('*.java',), ('text/x-java',)), 'JavascriptDjangoLexer': ('pygments.lexers.templates', 'JavaScript+Django/Jinja', ('js+django', 'javascript+django', 'js+jinja', 'javascript+jinja'), (), ('application/x-javascript+django', 'application/x-javascript+jinja', 'text/x-javascript+django', 'text/x-javascript+jinja', 'text/javascript+django', 'text/javascript+jinja')), @@ -230,7 +230,7 @@ LEXERS = { 'SqliteConsoleLexer': ('pygments.lexers.sql', 'sqlite3con', ('sqlite3',), ('*.sqlite3-console',), ('text/x-sqlite3-console',)), 'SquidConfLexer': ('pygments.lexers.text', 'SquidConf', ('squidconf', 'squid.conf', 'squid'), ('squid.conf',), ('text/x-squidconf',)), 'SspLexer': ('pygments.lexers.templates', 'Scalate Server Page', ('ssp',), ('*.ssp',), ('application/x-ssp',)), - 'StanLexer': ('pygments.lexers.math', 'Stan', ('stan',), ('*.stan',), ()), + 'StanLexer': ('pygments.lexers.bugs', 'Stan', ('stan',), ('*.stan',), ()), 'SystemVerilogLexer': ('pygments.lexers.hdl', 'systemverilog', ('sv',), ('*.sv', '*.svh'), ('text/x-systemverilog',)), 'TclLexer': ('pygments.lexers.agile', 'Tcl', ('tcl',), ('*.tcl',), ('text/x-tcl', 'text/x-script.tcl', 'application/x-tcl')), 'TcshLexer': ('pygments.lexers.shell', 'Tcsh', ('tcsh', 'csh'), ('*.tcsh', '*.csh'), ('application/x-csh',)), diff --git a/pygments/lexers/bugs.py b/pygments/lexers/bugs.py new file mode 100644 index 00000000..584eca86 --- /dev/null +++ b/pygments/lexers/bugs.py @@ -0,0 +1,298 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.bugs + ~~~~~~~~~~~~~~~~~~~~ + + Lexers for BUGS-like languages for Bayesian statistical models. + + :copyright: Copyright 2012 by the Pygments team, + :license: BSD, see LICENSE for details. +""" +from pygments.lexer import RegexLexer, bygroups, include +from pygments.token import Comment, String, Punctuation, Keyword, Name, \ + Operator, Number, Text + +__all__ = ['JagsLexer', 'BugsLexer', 'StanLexer'] + +class BugsLexer(RegexLexer): + """ Pygments Lexer for Stan models """ + + name = 'BUGS' + aliases = ['bugs', 'winbugs', 'openbugs'] + filenames = ['*.bug'] + + _FUNCTIONS = [ + # Scalar functions + 'abs', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctanh', + 'cloglog', 'cos', 'cosh', 'cumulative', 'cut', 'density', 'deviance', + 'equals', 'expr', 'gammap', 'ilogit', 'icloglog', 'integral', 'log', + 'logfact', 'loggam', 'logit', 'max', 'min', 'phi', 'post.p.value', + 'pow', 'prior.p.value', 'probit', 'replicate.post', 'replicate.prior', + 'round', 'sin', 'sinh', 'solution', 'sqrt', 'step', 'tan', 'tanh', + 'trunc', + # Vector functions + 'inprod', 'interp.lin', 'inverse', 'logdet', 'mean', 'eigen.vals', + 'ode', 'prod', 'p.valueM', 'rank', 'ranked', 'replicate.postM', + 'sd', 'sort', 'sum', + ## Special + 'D', 'I', 'F', 'T', 'C'] + """ OpenBUGS built-in functions + + From http://www.openbugs.info/Manuals/ModelSpecification.html#ContentsAII + + This also includes + + - T, C, I : Truncation and censoring. ``T`` and ``C`` are in OpenBUGS. ``I`` in WinBUGS. + - D : ODE + - F : Functional http://www.openbugs.info/Examples/Functionals.html + + """ + + _DISTRIBUTIONS = ['dbern', 'dbin', 'dcat', 'dnegbin', 'dpois', + 'dhyper', 'dbeta', 'dchisqr', 'ddexp', 'dexp', + 'dflat', 'dgamma', 'dgev', 'df', 'dggamma', 'dgpar', + 'dloglik', 'dlnorm', 'dlogis', 'dnorm', 'dpar', + 'dt', 'dunif', 'dweib', 'dmulti', 'ddirch', 'dmnorm', + 'dmt', 'dwish'] + """ OpenBUGS built-in distributions + + Functions From http://www.openbugs.info/Manuals/ModelSpecification.html#ContentsAI + """ + + + tokens = { + 'whitespace' : [ + (r"\s+", Text), + ], + 'comments' : [ + # Comments + (r'#.*$', Comment.Single), + ], + 'root': [ + # Comments + include('comments'), + include('whitespace'), + # Block start + (r'(?s)(model)(\s|\n)+({)', + bygroups(Keyword.Namespace, Text, Punctuation), 'block') + ], + 'block' : [ + include('comments'), + include('whitespace'), + # Reserved Words + (r'(for|in)\b', Keyword.Reserved), + # Built-in Functions + (r'(%s)(?=\s*\()' + % r'|'.join(_FUNCTIONS + _DISTRIBUTIONS), + Name.Builtin), + # Regular variable names + (r'[A-Za-z][A-Za-z0-9_.]*', Name), + # Number Literals + (r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?', Number), + # Punctuation + (r'(\[|\]|\(|\)|:|,)', Punctuation), + # Assignment operators + # SLexer makes these tokens Operators. + (r'(<-|~)', Operator), + # Infix and prefix operators + (r'(\+|-|\*|/)', Operator), + # Block + (r'{', Punctuation, '#push'), + (r'}', Punctuation, '#pop'), + ] + } + +class JagsLexer(RegexLexer): + """ Pygments Lexer for JAGS """ + name = 'JAGS' + aliases = ['jags'] + filenames = ['*.jags'] + + ## JAGS + _FUNCTIONS = [ + 'abs', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctanh', + 'cos', 'cosh', 'cloglog', + 'equals', 'exp', 'icloglog', 'ifelse', 'ilogit', 'log', 'logfact', + 'loggam', 'logit', 'phi', 'pow', 'probit', 'round', 'sin', 'sinh', + 'sqrt', 'step', 'tan', 'tanh', 'trunc', 'inprod', 'interp.lin', + 'logdet', 'max', 'mean', 'min', 'prod', 'sum', 'sd', 'inverse', 'rank', 'sort', 't', + 'acos', 'acosh', 'asin', 'asinh', 'atan', + # Truncation/Censoring (should I include) + 'T', 'I'] + # Distributions with density, probability and quartile functions + _DISTRIBUTIONS = ['[dpq]%s' % x for x in + ['bern', 'beta', 'dchiqsqr', 'ddexp', 'dexp', + 'df', 'gamma', 'gen.gamma', 'logis', 'lnorm', + 'negbin', 'nchisqr', 'norm', 'par', 'pois', 'weib']] + # Other distributions without density and probability + _OTHER_DISTRIBUTIONS = [ + 'dt', 'dunif', 'dbetabin', 'dbern', 'dbin', 'dcat', 'dhyper', + 'ddirch', 'dmnorm', 'dwish', 'dmt', 'dmulti', 'dbinom', 'dchisq', + 'dnbinom', 'dweibull', 'ddirich'] + + tokens = { + 'whitespace' : [ + (r"\s+", Text), + ], + 'names' : [ + # Regular variable names + (r'\b[A-Za-z][A-Za-z0-9_.]*\b', Name), + ], + 'comments' : [ + # do not use stateful comments + (r'(?s)/\*.*?\*/', Comment.Multiline), + # Comments + (r'#.*$', Comment.Single), + ], + 'root': [ + # Comments + include('comments'), + include('whitespace'), + # Block start + (r'(?s)(model|data)(\s|\n)+({)', + bygroups(Keyword.Namespace, Text, Punctuation), 'block'), + # Variable declaration (TODO: improve) + (r'var\b', Keyword.Declaration, 'var') + ], + 'statements': [ + include('comments'), + include('whitespace'), + # Reserved Words + (r'(for|in)\b', Keyword.Reserved), + # Builtins + # Need to use lookahead because . is a valid char + (r'(%s)(?=\s*\()' % r'|'.join(_FUNCTIONS + + _DISTRIBUTIONS + + _OTHER_DISTRIBUTIONS), + Name.Builtin), + # Names + include('names'), + # Number Literals + (r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?', Number), + (r'(\[|\]|\(|\)|:|,)', Punctuation), + # Assignment operators + (r'(<-|~)', Operator), + # # JAGS includes many more than OpenBUGS + # |/|\|\||\&\&|>=?|<=?|[=!]?=|!|%.*?%|^)' + (r'(\+|-|\*|\/|\|\|[&]{2}|[<>=]=?|\^|%.*?%)', Operator), + ], + 'block' : [ + include('statements'), + (r';', Punctuation), + (r'{', Punctuation, '#push'), + (r'}', Punctuation, '#pop'), + ], + 'var' : [ + include('statements'), + (r';', Punctuation, '#pop'), + ] + } + +class StanLexer(RegexLexer): + """ Pygments Lexer for Stan models """ + name = 'Stan' + aliases = ['stan'] + filenames = ['*.stan'] + + _RESERVED = ('for', 'in', 'while', 'repeat', 'until', 'if', + 'then', 'else', 'true', 'false', 'T') + + _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', 'negative_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'] + + tokens = { + 'whitespace' : [ + (r"\s+", Text), + ], + 'comments' : [ + # do not use stateful comments + (r'(?s)/\*.*?\*/', Comment.Multiline), + # Comments + (r'(//|#).*$', Comment.Single), + ], + 'root': [ + # Comments + include('comments'), + # block start + include('whitespace'), + # Block start + (r'(?s)(%s)(\s*)({)' % + r'|'.join(('data', r'transformed\s+?data', + 'parameters', r'transformed\s+parameters', + 'model', r'generated\s+quantities')), + bygroups(Keyword.Namespace, Text, Punctuation), 'block') + ], + 'block' : [ + include('comments'), + include('whitespace'), + # Reserved Words + (r'(%s)\b' % r'|'.join(_RESERVED), Keyword.Reserved), + # Data types + (r'(%s)\b' % r'|'.join(_TYPES), Keyword.Type), + # Punctuation + (r"[;:,\[\]()]", Punctuation), + # Builtin + (r'(%s)(?=\s*\()' + % r'|'.join(_FUNCTIONS + + _DISTRIBUTIONS + + ['%s_log' % x for x in _DISTRIBUTIONS]), + Name.Builtin), + (r'(%s)(?=\s*\()' + % r'|'.join(_CONSTANTS), + Keyword.Constant), + # Special names ending in __, like lp__ + (r'\b[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), + # Real Literals + (r'-?[0-9]+(\.[0-9]+)?[eE]-?[0-9]+', Number.Float), + (r'-?[0-9]*\.[0-9]*', Number.Float), + # Integer Literals + (r'-?[0-9]+', Number.Integer), + # Assignment operators + # SLexer makes these tokens Operators. + (r'(<-|~)', Operator), + # Infix and prefix operators + (r"(\+|-|\.?\*|\.?/|\\|')", Operator), + # Block + (r'{', Punctuation, '#push'), + (r'}', Punctuation, '#pop'), + ] + } diff --git a/pygments/lexers/math.py b/pygments/lexers/math.py index be82b2b2..a6d7a5c5 100644 --- a/pygments/lexers/math.py +++ b/pygments/lexers/math.py @@ -21,7 +21,7 @@ from pygments.lexers import _scilab_builtins __all__ = ['JuliaLexer', 'JuliaConsoleLexer', 'MuPADLexer', 'MatlabLexer', 'MatlabSessionLexer', 'OctaveLexer', 'ScilabLexer', 'NumPyLexer', - 'RConsoleLexer', 'SLexer', 'JagsLexer', 'BugsLexer', 'StanLexer'] + 'RConsoleLexer', 'SLexer'] class JuliaLexer(RegexLexer): name = 'Julia' @@ -1070,285 +1070,3 @@ class SLexer(RegexLexer): def analyse_text(text): return '<-' in text -class BugsLexer(RegexLexer): - """ Pygments Lexer for Stan models """ - - name = 'BUGS' - aliases = ['bugs', 'winbugs', 'openbugs'] - filenames = ['*.bug'] - - _FUNCTIONS = [ - # Scalar functions - 'abs', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctanh', - 'cloglog', 'cos', 'cosh', 'cumulative', 'cut', 'density', 'deviance', - 'equals', 'expr', 'gammap', 'ilogit', 'icloglog', 'integral', 'log', - 'logfact', 'loggam', 'logit', 'max', 'min', 'phi', 'post.p.value', - 'pow', 'prior.p.value', 'probit', 'replicate.post', 'replicate.prior', - 'round', 'sin', 'sinh', 'solution', 'sqrt', 'step', 'tan', 'tanh', - 'trunc', - # Vector functions - 'inprod', 'interp.lin', 'inverse', 'logdet', 'mean', 'eigen.vals', - 'ode', 'prod', 'p.valueM', 'rank', 'ranked', 'replicate.postM', - 'sd', 'sort', 'sum', - ## Special - 'D', 'I', 'F', 'T', 'C'] - """ OpenBUGS built-in functions - - From http://www.openbugs.info/Manuals/ModelSpecification.html#ContentsAII - - This also includes - - - T, C, I : Truncation and censoring. ``T`` and ``C`` are in OpenBUGS. ``I`` in WinBUGS. - - D : ODE - - F : Functional http://www.openbugs.info/Examples/Functionals.html - - """ - - _DISTRIBUTIONS = ['dbern', 'dbin', 'dcat', 'dnegbin', 'dpois', - 'dhyper', 'dbeta', 'dchisqr', 'ddexp', 'dexp', - 'dflat', 'dgamma', 'dgev', 'df', 'dggamma', 'dgpar', - 'dloglik', 'dlnorm', 'dlogis', 'dnorm', 'dpar', - 'dt', 'dunif', 'dweib', 'dmulti', 'ddirch', 'dmnorm', - 'dmt', 'dwish'] - """ OpenBUGS built-in distributions - - Functions From http://www.openbugs.info/Manuals/ModelSpecification.html#ContentsAI - """ - - - tokens = { - 'whitespace' : [ - (r"\s+", Text), - ], - 'comments' : [ - # Comments - (r'#.*$', Comment.Single), - ], - 'root': [ - # Comments - include('comments'), - include('whitespace'), - # Block start - (r'(?s)(model)(\s|\n)+({)', - bygroups(Keyword.Namespace, Text, Punctuation), 'block') - ], - 'block' : [ - include('comments'), - include('whitespace'), - # Reserved Words - (r'(for|in)\b', Keyword.Reserved), - # Built-in Functions - (r'(%s)(?=\s*\()' - % r'|'.join(_FUNCTIONS + _DISTRIBUTIONS), - Name.Builtin), - # Regular variable names - (r'[A-Za-z][A-Za-z0-9_.]*', Name), - # Number Literals - (r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?', Number), - # Punctuation - (r'(\[|\]|\(|\)|:|,)', Punctuation), - # Assignment operators - # SLexer makes these tokens Operators. - (r'(<-|~)', Operator), - # Infix and prefix operators - (r'(\+|-|\*|/)', Operator), - # Block - (r'{', Punctuation, '#push'), - (r'}', Punctuation, '#pop'), - ] - } - -class JagsLexer(RegexLexer): - """ Pygments Lexer for JAGS """ - name = 'JAGS' - aliases = ['jags'] - filenames = ['*.jags'] - - ## JAGS - _FUNCTIONS = [ - 'abs', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctanh', - 'cos', 'cosh', 'cloglog', - 'equals', 'exp', 'icloglog', 'ifelse', 'ilogit', 'log', 'logfact', - 'loggam', 'logit', 'phi', 'pow', 'probit', 'round', 'sin', 'sinh', - 'sqrt', 'step', 'tan', 'tanh', 'trunc', 'inprod', 'interp.lin', - 'logdet', 'max', 'mean', 'min', 'prod', 'sum', 'sd', 'inverse', 'rank', 'sort', 't', - 'acos', 'acosh', 'asin', 'asinh', 'atan', - # Truncation/Censoring (should I include) - 'T', 'I'] - # Distributions with density, probability and quartile functions - _DISTRIBUTIONS = ['[dpq]%s' % x for x in - ['bern', 'beta', 'dchiqsqr', 'ddexp', 'dexp', - 'df', 'gamma', 'gen.gamma', 'logis', 'lnorm', - 'negbin', 'nchisqr', 'norm', 'par', 'pois', 'weib']] - # Other distributions without density and probability - _OTHER_DISTRIBUTIONS = [ - 'dt', 'dunif', 'dbetabin', 'dbern', 'dbin', 'dcat', 'dhyper', - 'ddirch', 'dmnorm', 'dwish', 'dmt', 'dmulti', 'dbinom', 'dchisq', - 'dnbinom', 'dweibull', 'ddirich'] - - tokens = { - 'whitespace' : [ - (r"\s+", Text), - ], - 'names' : [ - # Regular variable names - (r'\b[A-Za-z][A-Za-z0-9_.]*\b', Name), - ], - 'comments' : [ - # do not use stateful comments - (r'(?s)/\*.*?\*/', Comment.Multiline), - # Comments - (r'#.*$', Comment.Single), - ], - 'root': [ - # Comments - include('comments'), - include('whitespace'), - # Block start - (r'(?s)(model|data)(\s|\n)+({)', - bygroups(Keyword.Namespace, Text, Punctuation), 'block'), - # Variable declaration (TODO: improve) - (r'var\b', Keyword.Declaration, 'var') - ], - 'statements': [ - include('comments'), - include('whitespace'), - # Reserved Words - (r'(for|in)\b', Keyword.Reserved), - # Builtins - # Need to use lookahead because . is a valid char - (r'(%s)(?=\s*\()' % r'|'.join(_FUNCTIONS - + _DISTRIBUTIONS - + _OTHER_DISTRIBUTIONS), - Name.Builtin), - # Names - include('names'), - # Number Literals - (r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?', Number), - (r'(\[|\]|\(|\)|:|,)', Punctuation), - # Assignment operators - (r'(<-|~)', Operator), - # # JAGS includes many more than OpenBUGS - # |/|\|\||\&\&|>=?|<=?|[=!]?=|!|%.*?%|^)' - (r'(\+|-|\*|\/|\|\|[&]{2}|[<>=]=?|\^|%.*?%)', Operator), - ], - 'block' : [ - include('statements'), - (r';', Punctuation), - (r'{', Punctuation, '#push'), - (r'}', Punctuation, '#pop'), - ], - 'var' : [ - include('statements'), - (r';', Punctuation, '#pop'), - ] - } - -class StanLexer(RegexLexer): - """ Pygments Lexer for Stan models """ - name = 'Stan' - aliases = ['stan'] - filenames = ['*.stan'] - - _RESERVED = ('for', 'in', 'while', 'repeat', 'until', 'if', - 'then', 'else', 'true', 'false', 'T') - - _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', 'negative_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'] - - tokens = { - 'whitespace' : [ - (r"\s+", Text), - ], - 'comments' : [ - # do not use stateful comments - (r'(?s)/\*.*?\*/', Comment.Multiline), - # Comments - (r'(//|#).*$', Comment.Single), - ], - 'root': [ - # Comments - include('comments'), - # block start - include('whitespace'), - # Block start - (r'(?s)(%s)(\s*)({)' % - r'|'.join(('data', r'transformed\s+?data', - 'parameters', r'transformed\s+parameters', - 'model', r'generated\s+quantities')), - bygroups(Keyword.Namespace, Text, Punctuation), 'block') - ], - 'block' : [ - include('comments'), - include('whitespace'), - # Reserved Words - (r'(%s)\b' % r'|'.join(_RESERVED), Keyword.Reserved), - # Data types - (r'(%s)\b' % r'|'.join(_TYPES), Keyword.Type), - # Punctuation - (r"[;:,\[\]()]", Punctuation), - # Builtin - (r'(%s)(?=\s*\()' - % r'|'.join(_FUNCTIONS - + _DISTRIBUTIONS - + ['%s_log' % x for x in _DISTRIBUTIONS]), - Name.Builtin), - (r'(%s)(?=\s*\()' - % r'|'.join(_CONSTANTS), - Keyword.Constant), - # Special names ending in __, like lp__ - (r'\b[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), - # Real Literals - (r'-?[0-9]+(\.[0-9]+)?[eE]-?[0-9]+', Number.Float), - (r'-?[0-9]*\.[0-9]*', Number.Float), - # Integer Literals - (r'-?[0-9]+', Number.Integer), - # Assignment operators - # SLexer makes these tokens Operators. - (r'(<-|~)', Operator), - # Infix and prefix operators - (r"(\+|-|\.?\*|\.?/|\\|')", Operator), - # Block - (r'{', Punctuation, '#push'), - (r'}', Punctuation, '#pop'), - ] - } |