summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pygments/lexers/_stan_builtins.py85
-rw-r--r--pygments/lexers/math.py2
-rw-r--r--tests/examplefiles/example.stan161
3 files changed, 172 insertions, 76 deletions
diff --git a/pygments/lexers/_stan_builtins.py b/pygments/lexers/_stan_builtins.py
index 6a5d1060..05432f85 100644
--- a/pygments/lexers/_stan_builtins.py
+++ b/pygments/lexers/_stan_builtins.py
@@ -21,6 +21,91 @@ CONSTANTS=[ u'e',
u'positive_infinity',
u'sqrt2']
+CPP_RESERVED=[ 'alignas',
+ 'alignof',
+ 'and',
+ 'and_eq',
+ 'asm',
+ 'auto',
+ 'bitand',
+ 'bitor',
+ 'bool',
+ 'break',
+ 'case',
+ 'catch',
+ 'char',
+ 'char16_t',
+ 'char32_t',
+ 'class',
+ 'compl',
+ 'const',
+ 'constexpr',
+ 'const_cast',
+ 'continue',
+ 'decltype',
+ 'default',
+ 'delete',
+ 'do',
+ 'double',
+ 'dynamic_cast',
+ 'else',
+ 'enum',
+ 'explicit',
+ 'export',
+ 'extern',
+ 'false',
+ 'float',
+ 'for',
+ 'friend',
+ 'goto',
+ 'if',
+ 'inline',
+ 'int',
+ 'long',
+ 'mutable',
+ 'namespace',
+ 'new',
+ 'noexcept',
+ 'not',
+ 'not_eq',
+ 'nullptr',
+ 'operator',
+ 'or',
+ 'or_eq',
+ 'private',
+ 'protected',
+ 'public',
+ 'register',
+ 'reinterpret_cast',
+ 'return',
+ 'short',
+ 'signed',
+ 'sizeof',
+ 'static',
+ 'static_assert',
+ 'static_cast',
+ 'struct',
+ 'switch',
+ 'template',
+ 'this',
+ 'thread_local',
+ 'throw',
+ 'true',
+ 'try',
+ 'typedef',
+ 'typeid',
+ 'typename',
+ 'union',
+ 'unsigned',
+ 'using',
+ 'virtual',
+ 'void',
+ 'volatile',
+ 'wchar_t',
+ 'while',
+ 'xor',
+ 'xor_eq']
+
FUNCTIONS=[ u'Phi',
u'Phi_approx',
u'abs',
diff --git a/pygments/lexers/math.py b/pygments/lexers/math.py
index c3dd90a6..531a2030 100644
--- a/pygments/lexers/math.py
+++ b/pygments/lexers/math.py
@@ -1352,7 +1352,7 @@ class StanLexer(RegexLexer):
% 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),
- ('%s\b' % r'|'.join(_stan_builtins.CPP_RESERVED), Error),
+ ('%s\b' % r'|'.join(_stan_builtins.CPP_RESERVED), Keyword.Reserved),
# Regular variable names
(r'[A-Za-z][A-Za-z0-9_]*\b', Name),
# Real Literals
diff --git a/tests/examplefiles/example.stan b/tests/examplefiles/example.stan
index 5723403c..e936f54a 100644
--- a/tests/examplefiles/example.stan
+++ b/tests/examplefiles/example.stan
@@ -6,92 +6,103 @@ It is not a real model and will not compile
# also a comment
// also a comment
data {
- // valid name
- int abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_abc;
- // all types should be highlighed
- int a3;
- real foo[2];
- vector[3] bar;
- row_vector[3] baz;
- matrix[3,3] qux;
- simplex[3] quux;
- ordered[3] corge;
- positive_ordered[3] wibble;
- 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.;
- // beings with number
- //real 0foo;
- // begins with _
- //real _foo;
+ // valid name
+ int abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_abc;
+ // all types should be highlighed
+ int a3;
+ real foo[2];
+ vector[3] bar;
+ row_vector[3] baz;
+ matrix[3,3] qux;
+ simplex[3] quux;
+ ordered[3] corge;
+ positive_ordered[3] wibble;
+ corr_matrix[3] grault;
+ cov_matrix[3] garply;
+
+ real<lower=-1,upper=1> foo1;
+ real<lower=0> foo2;
+ real<upper=0> foo3;
}
transformed data {
- real xyzzy;
- int thud;
- row_vector grault2;
- matrix qux2;
-
- // all floating point literals should be recognized
- // all operators should be recognized
- // paren should be recognized;
- xyzzy <- 1234.5687 + .123 - (2.7e3 / 2E-5 * 135e-5);
- // integer literal
- thud <- -12309865;
- // ./ and .* should be recognized as operators
- grault2 <- grault .* garply ./ garply;
- // ' and \ should be regognized as operators
- qux2 <- qux' \ bar;
-
+ real xyzzy;
+ int thud;
+ row_vector grault2;
+ matrix qux2;
+
+ // all floating point literals should be recognized
+ // all operators should be recognized
+ // paren should be recognized;
+ xyzzy <- 1234.5687 + .123 - (2.7e3 / 2E-5 * 135e-5);
+ // integer literal
+ thud <- -12309865;
+ // ./ and .* should be recognized as operators
+ grault2 <- grault .* garply ./ garply;
+ // ' and \ should be regognized as operators
+ qux2 <- qux' \ bar;
+
}
parameters {
- real fred;
- real plugh;
-
+ real fred;
+ real plugh;
}
transformed parameters {
}
model {
- // ~, <- are operators,
- // T may be be recognized
- // normal is a function
- fred ~ normal(0, 1) T(-0.5, 0.5);
- // interior block
- {
- real tmp;
- // for, in should be highlighted
- for (i in 1:10) {
- tmp <- tmp + 0.1;
- }
- }
- // lp__ should be highlighted
- // normal_log as a function
- lp__ <- lp__ + normal_log(plugh, 0, 1);
+ // ~, <- are operators,
+ // T may be be recognized
+ // normal is a function
+ fred ~ normal(0, 1) T(-0.5, 0.5);
+ real tmp;
+ // C++ reserved
+ real public;
+
+ // control structures
+ for (i in 1:10) {
+ tmp <- tmp + 0.1;
+ }
+ tmp <- 0.0;
+ while (tmp < 5.0) {
+ tmp <- tmp + 1;
+ }
+ if (tmp > 0.0) {
+ print(tmp);
+ } else {
+ print(tmp);
+ }
- // print statement and string literal
- print("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_~@#$%^&*`'-+={}[].,;: ");
- print("Hello, world!");
- print("");
+ // operators
+ tmp || tmp;
+ tmp && tmp;
+ tmp == tmp;
+ tmp != tmp;
+ tmp < tmp;
+ tmp <= tmp;
+ tmp > tmp;
+ tmp >= tmp;
+ tmp + tmp;
+ tmp - tmp;
+ tmp * tmp;
+ tmp / tmp;
+ tmp .* tmp;
+ tmp ./ tmp;
+ ! tmp;
+ - tmp;
+ + tmp;
+ tmp ';
+ // lp__ should be highlighted
+ // 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;
- bar1 <- foo + 1;
+ real bar1;
+ bar1 <- foo + 1;
}
-## Baddness
-//foo <- 2.0;
-//foo ~ normal(0, 1);
-//not_a_block {
-//}
-
-/*
-what happens with this?
-*/
-// */