summaryrefslogtreecommitdiff
path: root/tests/examplefiles/example.stan
blob: 03b7b1b592e88c154d7450d53516359d37f8cc86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* 
A file for testing Stan syntax highlighting. 

It is not a real model and will not compile
*/
# also a comment
// also a comment
functions {
  void f1(void a, real b) {
    return 1 / a;
  }
  real f2(int a, vector b, real c) {
    return a + b + c;
  }
}
data {
  // valid name
  int abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_abc;
  // all types should be highlighted
  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;
  cholesky_factor_cov[3] waldo;
  cholesky_factor_corr[3] waldo2;
  
  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 recognized as operators
  qux2 <- qux' \ bar;
  
}
parameters {
  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);
  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);
  }

  // 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;
  + tmp;
  tmp ';

  // lp__ should be highlighted
  // normal_log as a function
  lp__ <- lp__ + normal_log(plugh, 0, 1);
  increment_log_prob(normal_log(plugh, 0, 1));
  
  // print statement and string literal
  print("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_~@#$%^&*`'-+={}[].,;: ");
  print("Hello, world!");
  print("");

  // reject statement
  reject("I just don't like it");
  
}
generated quantities {
  real bar1;
  bar1 <- foo + 1;
}