Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
q.py188 linesDownload Raw Back to lexers
1"""2    pygments.lexers.q3    ~~~~~~~~~~~~~~~~~4 5    Lexer for the Q 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, words, include, bygroups, inherit12from pygments.token import Comment, Name, Number, Operator, Punctuation, \13    String, Whitespace, Literal, Generic14 15__all__ = ["KLexer", "QLexer"]16 17 18class KLexer(RegexLexer):19    """20    For K source code.21    """22 23    name = "K"24    aliases = ["k"]25    filenames = ["*.k"]26    url = "https://code.kx.com"27    version_added = '2.12'28 29    tokens = {30        "whitespace": [31            # hashbang script32            (r"^#!.*", Comment.Hashbang),33            # Comments34            (r"^/\s*\n", Comment.Multiline, "comments"),35            (r"(?<!\S)/.*", Comment.Single),36            # Whitespace37            (r"\s+", Whitespace),38            # Strings39            (r"\"", String.Double, "strings"),40        ],41        "root": [42            include("whitespace"),43            include("keywords"),44            include("declarations"),45        ],46        "keywords": [47            (words(("abs", "acos", "asin", "atan", "avg", "bin",48                    "binr", "by", "cor", "cos", "cov", "dev",49                    "delete", "div", "do", "enlist", "exec", "exit",50                    "exp", "from", "getenv", "hopen", "if", "in",51                    "insert", "last", "like", "log", "max", "min",52                    "prd", "select", "setenv", "sin", "sqrt", "ss",53                    "sum", "tan", "update", "var", "wavg", "while",54                    "within", "wsum", "xexp"),55                   suffix=r"\b"), Operator.Word),56        ],57        "declarations": [58            # Timing59            (r"^\\ts?", Comment.Preproc),60            (r"^(\\\w\s+[^/\n]*?)(/.*)",61             bygroups(Comment.Preproc, Comment.Single)),62            # Generic System Commands63            (r"^\\\w.*", Comment.Preproc),64            # Prompt65            (r"^[a-zA-Z]\)", Generic.Prompt),66            # Function Names67            (r"([.]?[a-zA-Z][\w.]*)(\s*)([-.~=!@#$%^&*_+|,<>?/\\:']?:)(\s*)(\{)",68             bygroups(Name.Function, Whitespace, Operator, Whitespace, Punctuation),69             "functions"),70            # Variable Names71            (r"([.]?[a-zA-Z][\w.]*)(\s*)([-.~=!@#$%^&*_+|,<>?/\\:']?:)",72             bygroups(Name.Variable, Whitespace, Operator)),73            # Functions74            (r"\{", Punctuation, "functions"),75            # Parentheses76            (r"\(", Punctuation, "parentheses"),77            # Brackets78            (r"\[", Punctuation, "brackets"),79            # Errors80            (r"'`([a-zA-Z][\w.]*)?", Name.Exception),81            # File Symbols82            (r"`:([a-zA-Z/][\w./]*)?", String.Symbol),83            # Symbols84            (r"`([a-zA-Z][\w.]*)?", String.Symbol),85            # Numbers86            include("numbers"),87            # Variable Names88            (r"[a-zA-Z][\w.]*", Name),89            # Operators90            (r"[-=+*#$%@!~^&:.,<>'\\|/?_]", Operator),91            # Punctuation92            (r";", Punctuation),93        ],94        "functions": [95            include("root"),96            (r"\}", Punctuation, "#pop"),97        ],98        "parentheses": [99            include("root"),100            (r"\)", Punctuation, "#pop"),101        ],102        "brackets": [103            include("root"),104            (r"\]", Punctuation, "#pop"),105        ],106        "numbers": [107            # Binary Values108            (r"[01]+b", Number.Bin),109            # Nulls/Infinities110            (r"0[nNwW][cefghijmndzuvtp]?", Number),111            # Timestamps112            ((r"(?:[0-9]{4}[.][0-9]{2}[.][0-9]{2}|[0-9]+)"113              "D(?:[0-9](?:[0-9](?::[0-9]{2}"114              "(?::[0-9]{2}(?:[.][0-9]*)?)?)?)?)?"), Literal.Date),115            # Datetimes116            ((r"[0-9]{4}[.][0-9]{2}"117              "(?:m|[.][0-9]{2}(?:T(?:[0-9]{2}:[0-9]{2}"118              "(?::[0-9]{2}(?:[.][0-9]*)?)?)?)?)"), Literal.Date),119            # Times120            (r"[0-9]{2}:[0-9]{2}(?::[0-9]{2}(?:[.][0-9]{1,3})?)?",121             Literal.Date),122            # GUIDs123            (r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",124             Number.Hex),125            # Byte Vectors126            (r"0x[0-9a-fA-F]+", Number.Hex),127            # Floats128            (r"([0-9]*[.]?[0-9]+|[0-9]+[.]?[0-9]*)[eE][+-]?[0-9]+[ef]?",129             Number.Float),130            (r"([0-9]*[.][0-9]+|[0-9]+[.][0-9]*)[ef]?", Number.Float),131            (r"[0-9]+[ef]", Number.Float),132            # Characters133            (r"[0-9]+c", Number),134            # Integers135            (r"[0-9]+[ihtuv]", Number.Integer),136            # Long Integers137            (r"[0-9]+[jnp]?", Number.Integer.Long),138        ],139        "comments": [140            (r"[^\\]+", Comment.Multiline),141            (r"^\\", Comment.Multiline, "#pop"),142            (r"\\", Comment.Multiline),143        ],144        "strings": [145            (r'[^"\\]+', String.Double),146            (r"\\.", String.Escape),147            (r'"', String.Double, "#pop"),148        ],149    }150 151 152class QLexer(KLexer):153    """154    For `Q <https://code.kx.com/>`_ source code.155    """156 157    name = "Q"158    aliases = ["q"]159    filenames = ["*.q"]160    version_added = '2.12'161 162    tokens = {163        "root": [164            (words(("aj", "aj0", "ajf", "ajf0", "all", "and", "any", "asc",165                    "asof", "attr", "avgs", "ceiling", "cols", "count", "cross",166                    "csv", "cut", "deltas", "desc", "differ", "distinct", "dsave",167                    "each", "ej", "ema", "eval", "except", "fby", "fills", "first",168                    "fkeys", "flip", "floor", "get", "group", "gtime", "hclose",169                    "hcount", "hdel", "hsym", "iasc", "idesc", "ij", "ijf",170                    "inter", "inv", "key", "keys", "lj", "ljf", "load", "lower",171                    "lsq", "ltime", "ltrim", "mavg", "maxs", "mcount", "md5",172                    "mdev", "med", "meta", "mins", "mmax", "mmin", "mmu", "mod",173                    "msum", "neg", "next", "not", "null", "or", "over", "parse",174                    "peach", "pj", "prds", "prior", "prev", "rand", "rank", "ratios",175                    "raze", "read0", "read1", "reciprocal", "reval", "reverse",176                    "rload", "rotate", "rsave", "rtrim", "save", "scan", "scov",177                    "sdev", "set", "show", "signum", "ssr", "string", "sublist",178                    "sums", "sv", "svar", "system", "tables", "til", "trim", "txf",179                    "type", "uj", "ujf", "ungroup", "union", "upper", "upsert",180                    "value", "view", "views", "vs", "where", "wj", "wj1", "ww",181                    "xasc", "xbar", "xcol", "xcols", "xdesc", "xgroup", "xkey",182                    "xlog", "xprev", "xrank"),183                    suffix=r"\b"), Name.Builtin,184            ),185            inherit,186        ],187    }188 
codekingpro/portable-devtools · Team Ai