Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
elpi.py173 linesDownload Raw Back to lexers
1"""2    pygments.lexers.elpi3    ~~~~~~~~~~~~~~~~~~~~4 5    Lexer for the `Elpi <http://github.com/LPCIC/elpi>`_ programming language.6 7    :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.8    :license: BSD, see LICENSE for details.9"""10 11from pygments.lexer import RegexLexer, bygroups, include12from pygments.token import Text, Comment, Operator, Keyword, Name, String, \13    Number, Punctuation14 15__all__ = ['ElpiLexer']16 17 18class ElpiLexer(RegexLexer):19    """20    Lexer for the Elpi programming language.21    """22 23    name = 'Elpi'24    url = 'http://github.com/LPCIC/elpi'25    aliases = ['elpi']26    filenames = ['*.elpi']27    mimetypes = ['text/x-elpi']28    version_added = '2.11'29 30    lcase_re = r"[a-z]"31    ucase_re = r"[A-Z]"32    digit_re = r"[0-9]"33    schar2_re = r"([+*^?/<>`'@#~=&!])"34    schar_re = rf"({schar2_re}|-|\$|_)"35    idchar_re = rf"({lcase_re}|{ucase_re}|{digit_re}|{schar_re})"36    idcharstarns_re = rf"({idchar_re}*(\.({lcase_re}|{ucase_re}){idchar_re}*)*)"37    symbchar_re = rf"({lcase_re}|{ucase_re}|{digit_re}|{schar_re}|:)"38    constant_re = rf"({ucase_re}{idchar_re}*|{lcase_re}{idcharstarns_re}|{schar2_re}{symbchar_re}*|_{idchar_re}+)"39    symbol_re = r"(,|<=>|->|:-|;|\?-|->|&|=>|\bas\b|\buvar\b|<|=<|=|==|>=|>|\bi<|\bi=<|\bi>=|\bi>|\bis\b|\br<|\br=<|\br>=|\br>|\bs<|\bs=<|\bs>=|\bs>|@|::|\[\]|`->|`:|`:=|\^|-|\+|\bi-|\bi\+|r-|r\+|/|\*|\bdiv\b|\bi\*|\bmod\b|\br\*|~|\bi~|\br~)"40    escape_re = rf"\(({constant_re}|{symbol_re})\)"41    const_sym_re = rf"({constant_re}|{symbol_re}|{escape_re})"42 43    tokens = {44        'root': [45            include('elpi')46        ],47 48        'elpi': [49            include('_elpi-comment'),50 51            (r"(:before|:after|:if|:name)(\s*)(\")",52             bygroups(Keyword.Mode, Text.Whitespace, String.Double),53             'elpi-string'),54            (r"(:index)(\s*\()", bygroups(Keyword.Mode, Text.Whitespace),55             'elpi-indexing-expr'),56            (rf"\b(external pred|pred)(\s+)({const_sym_re})",57             bygroups(Keyword.Declaration, Text.Whitespace, Name.Function),58             'elpi-pred-item'),59            (rf"\b(external type|type)(\s+)(({const_sym_re}(,\s*)?)+)",60             bygroups(Keyword.Declaration, Text.Whitespace, Name.Function),61             'elpi-type'),62            (rf"\b(kind)(\s+)(({const_sym_re}|,)+)",63             bygroups(Keyword.Declaration, Text.Whitespace, Name.Function),64             'elpi-type'),65            (rf"\b(typeabbrev)(\s+)({const_sym_re})",66             bygroups(Keyword.Declaration, Text.Whitespace, Name.Function),67             'elpi-type'),68            (r"\b(accumulate)(\s+)(\")",69             bygroups(Keyword.Declaration, Text.Whitespace, String.Double),70             'elpi-string'),71            (rf"\b(accumulate|namespace|local)(\s+)({constant_re})",72             bygroups(Keyword.Declaration, Text.Whitespace, Text)),73            (rf"\b(shorten)(\s+)({constant_re}\.)",74             bygroups(Keyword.Declaration, Text.Whitespace, Text)),75            (r"\b(pi|sigma)(\s+)([a-zA-Z][A-Za-z0-9_ ]*)(\\)",76             bygroups(Keyword.Declaration, Text.Whitespace, Name.Variable, Text)),77            (rf"\b(constraint)(\s+)(({const_sym_re}(\s+)?)+)",78             bygroups(Keyword.Declaration, Text.Whitespace, Name.Function),79             'elpi-chr-rule-start'),80 81            (rf"(?=[A-Z_]){constant_re}", Name.Variable),82            (rf"(?=[a-z_]){constant_re}\\", Name.Variable),83            (r"_", Name.Variable),84            (rf"({symbol_re}|!|=>|;)", Keyword.Declaration),85            (constant_re, Text),86            (r"\[|\]|\||=>", Keyword.Declaration),87            (r'"', String.Double, 'elpi-string'),88            (r'`', String.Double, 'elpi-btick'),89            (r'\'', String.Double, 'elpi-tick'),90            (r'\{\{', Punctuation, 'elpi-quote'),91            (r'\{[^\{]', Text, 'elpi-spill'),92            (r"\(", Text, 'elpi-in-parens'),93            (r'\d[\d_]*', Number.Integer),94            (r'-?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)', Number.Float),95            (r"[\+\*\-/\^\.]", Operator),96        ],97        '_elpi-comment': [98            (r'%[^\n]*\n', Comment),99            (r'/\*', Comment, 'elpi-multiline-comment'),100            (r"\s+", Text.Whitespace),101        ],102        'elpi-multiline-comment': [103            (r'\*/', Comment, '#pop'),104            (r'.', Comment)105        ],106        'elpi-indexing-expr':[107            (r'[0-9 _]+', Number.Integer),108            (r'\)', Text, '#pop'),109        ],110        'elpi-type': [111            (r"(ctype\s+)(\")", bygroups(Keyword.Type, String.Double), 'elpi-string'),112            (r'->', Keyword.Type),113            (constant_re, Keyword.Type),114            (r"\(|\)", Keyword.Type),115            (r"\.", Text, '#pop'),116            include('_elpi-comment'),117        ],118        'elpi-chr-rule-start': [119            (r"\{", Text, 'elpi-chr-rule'),120            include('_elpi-comment'),121        ],122        'elpi-chr-rule': [123           (r"\brule\b", Keyword.Declaration),124           (r"\\", Keyword.Declaration),125           (r"\}", Text, '#pop:2'),126           include('elpi'),127        ],128        'elpi-pred-item': [129            (r"[io]:", Keyword.Mode, 'elpi-ctype'),130            (r"\.", Text, '#pop'),131            include('_elpi-comment'),132        ],133        'elpi-ctype': [134            (r"(ctype\s+)(\")", bygroups(Keyword.Type, String.Double), 'elpi-string'),135            (r'->', Keyword.Type),136            (constant_re, Keyword.Type),137            (r"\(|\)", Keyword.Type),138            (r",", Text, '#pop'),139            (r"\.", Text, '#pop:2'),140            include('_elpi-comment'),141        ],142        'elpi-btick': [143            (r'[^` ]+', String.Double),144            (r'`', String.Double, '#pop'),145        ],146        'elpi-tick': [147            (r'[^\' ]+', String.Double),148            (r'\'', String.Double, '#pop'),149        ],150        'elpi-string': [151            (r'[^\"]+', String.Double),152            (r'"', String.Double, '#pop'),153        ],154        'elpi-quote': [155            (r'\{\{', Punctuation, '#push'),156            (r'\}\}', Punctuation, '#pop'),157            (rf"(lp:)((?=[A-Z_]){constant_re})", bygroups(Keyword, Name.Variable)),158            (r"[^l\}]+", Text),159            (r"l|\}", Text),160        ],161        'elpi-spill': [162            (r'\{[^\{]', Text, '#push'),163            (r'\}[^\}]', Text, '#pop'),164            include('elpi'),165        ],166        'elpi-in-parens': [167            (r"\(", Operator, '#push'),168            (r"\)", Operator, '#pop'),169            include('elpi'),170        ],171 172    }173 
codekingpro/portable-devtools · Team Ai