forked from pinecoders/pinecoders.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpine_lexer.py
25 lines (23 loc) · 1.19 KB
/
pine_lexer.py
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
from pygments.lexer import RegexLexer
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
Number, Literal, Punctuation, Generic, Other, Error
# Many examples are here https://bitbucket.org/birkenfeld/pygments-main/src/default/pygments/lexers/
class PinePygmentsLexer(RegexLexer):
name = 'pine'
tokens = {
'root': [
(r'\#([0-9a-fA-F]{8})|\#([0-9a-fA-F]{6})', Literal), # Color literal
(r'[0-9]+', Number.Integer),
(r'(\.\d+|[0-9]+\.[0-9]*)([eE][-+]?[0-9]+)?', Number.Float),
(r'\s+', Text.Whitespace),
(r'//.*?$', Comment),
(r'(for|if|else|var)\b', Keyword),
(r'(open|high|low|close|volume|time|hl2|hlc3|ohlc4)\b', Name.Constant), # Built-in series 'open', 'high', ...
(r'(study|strategy|plot|plotshape|plotchar|plotarrow|fill|hline|input)\b', Name.Entity), # Annotation function
(r'[\w\.]+', Name.Other),
(r'\+|\-|\*|\/|\%|\=|\[|\]|and|or|not|\?|\:|\<|\>|\!', Operator),
(r'\(|\)|\,', Punctuation),
(r'"(\\\\|\\"|[^"])*"', String.Double),
(r"'(\\\\|\\'|[^'])*'", String.Single),
]
}