1+ from pygments .lexer import RegexLexer
2+ from pygments .token import Text , Comment , Operator , Keyword , Name , String , \
3+ Number , Literal , Punctuation , Generic , Other , Error
4+
5+ # Many examples are here https://bitbucket.org/birkenfeld/pygments-main/src/default/pygments/lexers/
6+ class PinePygmentsLexer (RegexLexer ):
7+ name = 'pine'
8+
9+ tokens = {
10+ 'root' : [
11+ (r'\#([0-9a-fA-F]{8})|\#([0-9a-fA-F]{6})' , Literal ), # Color literal
12+ (r'[0-9]+' , Number .Integer ),
13+ (r'(\.\d+|[0-9]+\.[0-9]*)([eE][-+]?[0-9]+)?' , Number .Float ),
14+ (r'\s+' , Text .Whitespace ),
15+ (r'//.*?$' , Comment ),
16+ (r'(for|if|else|var)\b' , Keyword ),
17+ (r'(open|high|low|close|volume|time|hl2|hlc3|ohlc4)\b' , Name .Constant ), # Built-in series 'open', 'high', ...
18+ (r'(study|strategy|plot|plotshape|plotchar|plotarrow|fill|hline|input)\b' , Name .Entity ), # Annotation function
19+ (r'[\w\.]+' , Name .Other ),
20+ (r'\+|\-|\*|\/|\%|\=|\[|\]|and|or|not|\?|\:|\<|\>|\!' , Operator ),
21+ (r'\(|\)|\,' , Punctuation ),
22+ (r'"(\\\\|\\"|[^"])*"' , String .Double ),
23+ (r"'(\\\\|\\'|[^'])*'" , String .Single ),
24+ ]
25+ }
0 commit comments