File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ requests == 2.22.0
Original file line number Diff line number Diff line change 1+ import re
2+ import requests
3+
4+ FUNCTION_SIGNATURES_FILE = "https://raw.githubusercontent.com/stan-dev/stan/develop/src/stan/lang/function_signatures.h"
5+ SYNTAX_FILE = "syntax/stan.vim"
6+ STAN_ADD_FUNCTIONS = [
7+ "add" ,
8+ "add_unary" ,
9+ "add_unary_vectorized" ,
10+ "add_binary" ,
11+ "add_ternary" ,
12+ "add_nullary" ,
13+ ]
14+
15+ # Request Stan file
16+ req = requests .get (FUNCTION_SIGNATURES_FILE )
17+ if req .status_code == requests .codes .ok :
18+ stan_file = req .text
19+ else :
20+ msg = "Could not request Stan file."
21+ raise RuntimeError (msg )
22+
23+ # Read syntax file
24+ with open (SYNTAX_FILE , "r" ) as f :
25+ syntax_file = f .read ()
26+
27+ # Find all functions from Stan file
28+ add_functions = "|" .join (STAN_ADD_FUNCTIONS )
29+ regex = r"(?<=[{}]\(['\"])(\w+)(?=['\"])" .format (add_functions )
30+ stan_functions = set (re .findall (regex , stan_file ))
31+ # Remove _log functions
32+ stan_functions = {
33+ function for function in stan_functions if not function .endswith ("_log" )
34+ }
35+ # Add bare distribution names
36+ stan_functions = stan_functions | {
37+ function [:- 4 ] for function in stan_functions if function .endswith ("_rng" )
38+ }
39+
40+ regex1 = r"(?<=syntax keyword stanFunction )(.*)"
41+ regex2 = r"(?<=syntax keyword stanConstant )(.*)"
42+ matches = re .findall (regex1 , syntax_file ) + re .findall (regex2 , syntax_file )
43+
44+ # Flatten
45+ highlighted_functions = set ([word for match in matches for word in match .split ()])
46+
47+ missing = stan_functions - highlighted_functions
48+ unnecessary = highlighted_functions - stan_functions
49+
50+ print ("Missing:" )
51+ print (missing )
52+ print ()
53+ print ("Unnecessary:" )
54+ print (unnecessary )
You can’t perform that action at this time.
0 commit comments