Warning, /frameworks/syntax-highlighting/autotests/folding/highlight.stan.fold is written in an unsupported language. File is not indexed.
0001 <beginfold id='1'>/*</beginfold id='1'> Stan Highlighting Example 0002 0003 This file contains a syntatically correct but nonsensical Stan program that 0004 includes almost every feature of the language needed to validate syntax 0005 highlighters. It will compile (as of Stan 2.17.1), but it does nothing 0006 useful. 0007 0008 Author: Jeffrey Arnold <jeffrey.anold@gmail.com> 0009 Copyright: Jeffrey Arnold (2018) 0010 License: MIT 0011 0012 <endfold id='1'>*/</endfold id='1'> 0013 // line comment 0014 # deprecated line comment 0015 functions <beginfold id='2'>{</beginfold id='2'> 0016 #include stuff.stan 0017 #include "morestuff.stan" 0018 #include 'moststuff.stan' 0019 #include <evenmorestuff.stan> 0020 0021 // declarations 0022 void oof(real x); 0023 0024 // definitions 0025 // return types 0026 void oof(real x) <beginfold id='2'>{</beginfold id='2'> 0027 print("print ", x); 0028 <endfold id='2'>}</endfold id='2'> 0029 <beginfold id='1'>/*</beginfold id='1'> 0030 @param x A number 0031 @return x + 1 0032 <endfold id='1'>*/</endfold id='1'> 0033 real foo(real x) <beginfold id='2'>{</beginfold id='2'> 0034 return x; 0035 <endfold id='2'>}</endfold id='2'> 0036 int bar(int x) <beginfold id='2'>{</beginfold id='2'> 0037 return x; 0038 <endfold id='2'>}</endfold id='2'> 0039 vector baz(vector x) <beginfold id='2'>{</beginfold id='2'> 0040 return x; 0041 <endfold id='2'>}</endfold id='2'> 0042 row_vector qux(row_vector x) <beginfold id='2'>{</beginfold id='2'> 0043 return x; 0044 <endfold id='2'>}</endfold id='2'> 0045 matrix quux(matrix x) <beginfold id='2'>{</beginfold id='2'> 0046 return x; 0047 <endfold id='2'>}</endfold id='2'> 0048 // numbers of arguments 0049 void corge() <beginfold id='2'>{</beginfold id='2'> 0050 print("no parameters"); 0051 <endfold id='2'>}</endfold id='2'> 0052 void grault(int a, real b, vector c, row_vector d, matrix f) <beginfold id='2'>{</beginfold id='2'> 0053 print("many parameters"); 0054 <endfold id='2'>}</endfold id='2'> 0055 void garply(real a, real[] b, real[,] c, real[,,] d) <beginfold id='2'>{</beginfold id='2'> 0056 print("array arguments"); 0057 <endfold id='2'>}</endfold id='2'> 0058 // array return types 0059 int[] waldo(int[] x) <beginfold id='2'>{</beginfold id='2'> 0060 return x; 0061 <endfold id='2'>}</endfold id='2'> 0062 int[,] fred(int[,] x) <beginfold id='2'>{</beginfold id='2'> 0063 return x; 0064 <endfold id='2'>}</endfold id='2'> 0065 int[,,] plough(int[,,] x) <beginfold id='2'>{</beginfold id='2'> 0066 return x; 0067 <endfold id='2'>}</endfold id='2'> 0068 // data only function argument 0069 real plugh(data real x) <beginfold id='2'>{</beginfold id='2'> 0070 return x; 0071 <endfold id='2'>}</endfold id='2'> 0072 // ode function 0073 real[] ode_func(real a, real[] b, real[] c, real[] d, int[] e) <beginfold id='2'>{</beginfold id='2'> 0074 return b; 0075 <endfold id='2'>}</endfold id='2'> 0076 <endfold id='2'>}</endfold id='2'> 0077 data <beginfold id='2'>{</beginfold id='2'> 0078 // non-int variable types 0079 int x_int; 0080 real x_real; 0081 real y_real; 0082 vector[1] x_vector; 0083 ordered[1] x_ordered; 0084 positive_ordered[1] x_positive_ordered; 0085 simplex[1] x_simplex; 0086 unit_vector[1] x_unit_vector; 0087 row_vector[1] x_row_vector; 0088 matrix[1, 1] x_matrix; 0089 cholesky_factor_corr[2] x_cholesky_factor_corr; 0090 cholesky_factor_cov[2] x_cholesky_factor_cov; 0091 cholesky_factor_cov[2, 3] x_cholesky_factor_cov_2; 0092 corr_matrix[2] x_corr_matrix; 0093 cov_matrix[2] x_cov_matrix; 0094 0095 // range constraints 0096 real<lower = 0., upper = 1.> alpha; 0097 real<lower = 0.> bravo; 0098 real<upper = 1.> charlie; 0099 0100 // arrays 0101 int echo[1]; 0102 int foxtrot[1, 1]; 0103 int golf[1, 1, 1]; 0104 0105 // identifier with all valid letters 0106 real abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789; 0107 0108 // hard pattern 0109 real<lower = (bravo < charlie), upper = (bravo > charlie)> ranger; 0110 0111 // identifier patterns 0112 real a; 0113 real a3; 0114 real a_3; 0115 real Sigma; 0116 real my_cpp_style_variable; 0117 real myCamelCaseVariable; 0118 real abcdefghijklmnojk; 0119 // names beginning with keywords 0120 real iffffff; 0121 real whilest; 0122 // name ending with truncation 0123 real fooT; 0124 0125 // new array syntax 0126 array [N] real foo_new; 0127 <endfold id='2'>}</endfold id='2'> 0128 0129 transformed data <beginfold id='2'>{</beginfold id='2'> 0130 // declaration and assignment 0131 int india = 1; 0132 real romeo = 1.0; 0133 row_vector[2] victor = [1, 2]; 0134 matrix[2, 2] mike = [[1, 2], [3, 4]]; 0135 real sierra[2] = <beginfold id='2'>{</beginfold id='2'>1., 2.<endfold id='2'>}</endfold id='2'>; 0136 complex zulu = 3+4.1i; 0137 <endfold id='2'>}</endfold id='2'> 0138 parameters <beginfold id='2'>{</beginfold id='2'> 0139 real hotel; 0140 real<offset = 0., multiplier = 1.> alpha; 0141 <endfold id='2'>}</endfold id='2'> 0142 transformed parameters <beginfold id='2'>{</beginfold id='2'> 0143 real juliette; 0144 juliette = hotel * 2.; 0145 <endfold id='2'>}</endfold id='2'> 0146 model <beginfold id='2'>{</beginfold id='2'> 0147 real x; 0148 int k; 0149 vector[2] y = [1., 1.]'; 0150 matrix[2, 2] A = [[1., 1.], [1., 1.]]; 0151 real odeout[2, 2]; 0152 real algout[2, 2]; 0153 0154 // if else statements 0155 if (x_real < 0) x = 0.; 0156 0157 if (x_real < 0) <beginfold id='2'>{</beginfold id='2'> 0158 x = 0.; 0159 <endfold id='2'>}</endfold id='2'> 0160 0161 if (x_real < 0) x = 0.; 0162 else x = 1.; 0163 0164 if (x_real < 0) <beginfold id='2'>{</beginfold id='2'> 0165 x = 0.; 0166 <endfold id='2'>}</endfold id='2'> else <beginfold id='2'>{</beginfold id='2'> 0167 x = 1.; 0168 <endfold id='2'>}</endfold id='2'> 0169 0170 if (x_real < 0) x = 0.; 0171 else if (x_real > 1) x = 1.; 0172 else x = 0.5; 0173 0174 if (x_real < 0) <beginfold id='2'>{</beginfold id='2'> 0175 x = 0.; 0176 <endfold id='2'>}</endfold id='2'> else if (x_real > 1) <beginfold id='2'>{</beginfold id='2'> 0177 x = 1.; 0178 <endfold id='2'>}</endfold id='2'> else <beginfold id='2'>{</beginfold id='2'> 0179 x = 0.5; 0180 <endfold id='2'>}</endfold id='2'> 0181 0182 // for loops 0183 for (i in 1:5) <beginfold id='2'>{</beginfold id='2'> 0184 print("i = ", i); 0185 <endfold id='2'>}</endfold id='2'> 0186 // for (j in echo) { 0187 // print("j = ", j); 0188 // } 0189 // while loop 0190 while (1) <beginfold id='2'>{</beginfold id='2'> 0191 break; 0192 continue; 0193 <endfold id='2'>}</endfold id='2'> 0194 0195 // reject statement 0196 reject("reject statment ", x_real); 0197 0198 // print statement 0199 print("print statement ", x_real); 0200 print("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_~@#$%^&*`'-+={}[].,;: "); 0201 0202 // increment log probability statements; 0203 target += 1.; 0204 0205 // valid integer literals 0206 k = 0; 0207 k = 1; 0208 k = -1; 0209 k = 256; 0210 k = -127098; 0211 k = 007; 0212 0213 // valid real literals 0214 x = 0.0; 0215 x = 1.0; 0216 x = 3.14; 0217 x = 003.14; 0218 x = -217.9387; 0219 x = 0.123; 0220 x = .123; 0221 x = 1.; 0222 x = -0.123; 0223 x = -.123; 0224 x = -1.; 0225 x = 12e34; 0226 x = 12E34; 0227 x = 12.e34; 0228 x = 12.E34; 0229 x = 12.0e34; 0230 x = 12.0E34; 0231 x = .1e34; 0232 x = .1E34; 0233 x = -12e34; 0234 x = -12E34; 0235 x = -12.e34; 0236 x = -12.E34; 0237 x = -12.0e34; 0238 x = -12.0E34; 0239 x = -.1e34; 0240 x = -.1E34; 0241 x = 12e-34; 0242 x = 12E-34; 0243 x = 12.e-34; 0244 x = 12.E-34; 0245 x = 12.0e-34; 0246 x = 12.0E-34; 0247 x = .1e-34; 0248 x = .1E-34; 0249 x = -12e-34; 0250 x = -12E-34; 0251 x = -12.e-34; 0252 x = -12.E-34; 0253 x = -12.0e-34; 0254 x = -12.0E-34; 0255 x = -.1e-34; 0256 x = -.1E-34; 0257 x = 12e+34; 0258 x = 12E+34; 0259 x = 12.e+34; 0260 x = 12.E+34; 0261 x = 12.0e+34; 0262 x = 12.0E+34; 0263 x = .1e+34; 0264 x = .1E+34; 0265 x = -12e+34; 0266 x = -12E+34; 0267 x = -12.e+34; 0268 x = -12.E+34; 0269 x = -12.0e+34; 0270 x = -12.0E+34; 0271 x = -.1e+34; 0272 x = -.1E+34; 0273 0274 // imaginary literals 0275 complex z = 3 + 3i; 0276 z = 2.3i; 0277 z = 3.4e10i; 0278 z = 0i; 0279 0280 // assignment statements 0281 x = 1; 0282 x += 1.; 0283 x -= 1.; 0284 x *= 1.; 0285 x /= 1.; 0286 y .*= x_vector; 0287 y ./= x_vector; 0288 0289 // operators 0290 x = x_real && 1; 0291 x = x_real || 1; 0292 x = x_real < 1.; 0293 x = x_real <= 1.; 0294 x = x_real > 1.; 0295 x = x_real >= 1.; 0296 x = x_real + 1.; 0297 x = x_real - 1.; 0298 x = x_real * 1.; 0299 x = x_real / 1.; 0300 x = x_real ^ 2.; 0301 x = x_real % 2; 0302 x = !x_real; 0303 x = +x_real; 0304 x = -x_real; 0305 x = x_int ? x_real : 0.; 0306 0307 y = x_row_vector'; 0308 y = x_matrix \ x_vector; 0309 y = x_vector .* x_vector; 0310 y = x_vector ./ x_vector; 0311 0312 // parenthized expression 0313 x = (x_real + x_real); 0314 0315 // block statement 0316 <beginfold id='2'>{</beginfold id='2'> 0317 real z; 0318 z = 1.; 0319 <endfold id='2'>}</endfold id='2'> 0320 0321 profile("profile-test") <beginfold id='2'>{</beginfold id='2'> 0322 real z; 0323 z = 1.; 0324 <endfold id='2'>}</endfold id='2'> 0325 // built-in functions 0326 x = log(1.); 0327 x = exp(1.); 0328 0329 // non-built-in function 0330 x = foo(1.); 0331 0332 // constants and nullary functions 0333 x = machine_precision(); 0334 x = pi(); 0335 x = e(); 0336 x = sqrt2(); 0337 x = log2(); 0338 x = log10(); 0339 // special values 0340 x = not_a_number(); 0341 x = positive_infinity(); 0342 x = negative_infinity(); 0343 x = machine_precision(); 0344 // log probability 0345 x = target(); 0346 0347 // sampling statement 0348 x_real ~ normal(0., 1.); 0349 0350 // truncation 0351 x_real ~ normal(0., 1.) T[-1., 1.]; 0352 x_real ~ normal(0., 1.) T[, 1.]; 0353 x_real ~ normal(0., 1.) T[-1., ]; 0354 x_real ~ normal(0., 1.) T[ , ]; 0355 0356 // transformation on lhs of sampling 0357 log(x_real) ~ normal(0., 1.); 0358 0359 // lhs indexes 0360 y[1] = 1.; 0361 A[1, 2] = 1.; 0362 A[1][2] = 1.; 0363 0364 // special functions 0365 odeout = integrate_ode(ode_func, <beginfold id='2'>{</beginfold id='2'>1.<endfold id='2'>}</endfold id='2'>, x_real, <beginfold id='2'>{</beginfold id='2'>1.<endfold id='2'>}</endfold id='2'>, <beginfold id='2'>{</beginfold id='2'>1.<endfold id='2'>}</endfold id='2'>, <beginfold id='2'>{</beginfold id='2'>1.<endfold id='2'>}</endfold id='2'>, <beginfold id='2'>{</beginfold id='2'>0<endfold id='2'>}</endfold id='2'>); 0366 odeout = integrate_ode_bdf(ode_func, <beginfold id='2'>{</beginfold id='2'>1.<endfold id='2'>}</endfold id='2'>, x_real, <beginfold id='2'>{</beginfold id='2'>1.<endfold id='2'>}</endfold id='2'>, <beginfold id='2'>{</beginfold id='2'>1.<endfold id='2'>}</endfold id='2'>, <beginfold id='2'>{</beginfold id='2'>1.<endfold id='2'>}</endfold id='2'>, <beginfold id='2'>{</beginfold id='2'>0<endfold id='2'>}</endfold id='2'>, 0367 x_real, x_real, x_int); 0368 odeout = integrate_ode_rk45(ode_func, <beginfold id='2'>{</beginfold id='2'>1.<endfold id='2'>}</endfold id='2'>, x_real, <beginfold id='2'>{</beginfold id='2'>1.<endfold id='2'>}</endfold id='2'>, <beginfold id='2'>{</beginfold id='2'>1.<endfold id='2'>}</endfold id='2'>, <beginfold id='2'>{</beginfold id='2'>1.<endfold id='2'>}</endfold id='2'>, <beginfold id='2'>{</beginfold id='2'>0<endfold id='2'>}</endfold id='2'>, 0369 x_real, x_real, x_int); 0370 // algout = algebra_solver(algebra_func, x_vector, x_vector, {1.}, {0}); 0371 0372 // distribution functions 0373 x = normal_lpdf(0.5 | 0., 1.); 0374 x = normal_cdf(0.5, 0., 1.); 0375 x = normal_lcdf(0.5 | 0., 1.); 0376 x = normal_lccdf(0.5 | 0., 1.); 0377 x = binomial_lpmf(1 | 2, 0.5); 0378 0379 // deprecated features 0380 foo <- 1; 0381 increment_log_prob(0.0); 0382 y_hat = integrate_ode(sho, y0, t0, ts, theta, x_r, x_i); 0383 x = get_lp(); 0384 x = multiply_log(1.0, 1.0); 0385 x = binomial_coefficient_log(1.0, 1.0); 0386 // deprecated distribution functions versions 0387 x = normal_log(0.5, 0.0, 1.0); 0388 x = normal_cdf_log(0.5, 0.0, 1.0); 0389 x = normal_ccdf_log(0.5, 0.0, 1.0); 0390 0391 <endfold id='2'>}</endfold id='2'> 0392 generated quantities <beginfold id='2'>{</beginfold id='2'> 0393 real Y; 0394 // rng function 0395 Y = normal_rng(0., 1.); 0396 <endfold id='2'>}</endfold id='2'>