1# -*- coding: utf-8 -*-
2"""
3    pygments.lexers.floscript
4    ~~~~~~~~~~~~~~~~~~~~~~~~~
5
6    Lexer for FloScript
7
8    :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS.
9    :license: BSD, see LICENSE for details.
10"""
11
12from pygments.lexer import RegexLexer, include
13from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
14    Number, Punctuation
15
16__all__ = ['FloScriptLexer']
17
18
19class FloScriptLexer(RegexLexer):
20    """
21    For `FloScript <https://github.com/ioflo/ioflo>`_ configuration language source code.
22
23    .. versionadded:: 2.4
24    """
25
26    name = 'FloScript'
27    aliases = ['floscript', 'flo']
28    filenames = ['*.flo']
29
30    def innerstring_rules(ttype):
31        return [
32            # the old style '%s' % (...) string formatting
33            (r'%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
34             '[hlL]?[E-GXc-giorsux%]', String.Interpol),
35            # backslashes, quotes and formatting signs must be parsed one at a time
36            (r'[^\\\'"%\n]+', ttype),
37            (r'[\'"\\]', ttype),
38            # unhandled string formatting sign
39            (r'%', ttype),
40            # newlines are an error (use "nl" state)
41        ]
42
43    tokens = {
44        'root': [
45            (r'\n', Text),
46            (r'[^\S\n]+', Text),
47
48            (r'[]{}:(),;[]', Punctuation),
49            (r'\\\n', Text),
50            (r'\\', Text),
51            (r'(to|by|with|from|per|for|cum|qua|via|as|at|in|of|on|re|is|if|be|into|'
52             r'and|not)\b', Operator.Word),
53            (r'!=|==|<<|>>|[-~+/*%=<>&^|.]', Operator),
54            (r'(load|init|server|logger|log|loggee|first|over|under|next|done|timeout|'
55             r'repeat|native|benter|enter|recur|exit|precur|renter|rexit|print|put|inc|'
56             r'copy|set|aux|rear|raze|go|let|do|bid|ready|start|stop|run|abort|use|flo|'
57             r'give|take)\b', Name.Builtin),
58            (r'(frame|framer|house)\b', Keyword),
59            ('"', String, 'string'),
60
61            include('name'),
62            include('numbers'),
63            (r'#.+$', Comment.Singleline),
64        ],
65        'string': [
66            ('[^"]+', String),
67            ('"', String, '#pop'),
68        ],
69        'numbers': [
70            (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?', Number.Float),
71            (r'\d+[eE][+-]?[0-9]+j?', Number.Float),
72            (r'0[0-7]+j?', Number.Oct),
73            (r'0[bB][01]+', Number.Bin),
74            (r'0[xX][a-fA-F0-9]+', Number.Hex),
75            (r'\d+L', Number.Integer.Long),
76            (r'\d+j?', Number.Integer)
77        ],
78
79        'name': [
80            (r'@[\w.]+', Name.Decorator),
81            (r'[a-zA-Z_]\w*', Name),
82        ],
83    }
84