dax.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. """
  2. pygments.lexers.dax
  3. ~~~~~~~~~~~~~~~~~~~
  4. Lexer for LilyPond.
  5. :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. from pygments.lexer import RegexLexer, words
  9. from pygments.token import Comment, Punctuation, Whitespace,\
  10. Name, Operator, String, Number, Text
  11. __all__ = ['DaxLexer']
  12. class DaxLexer(RegexLexer):
  13. """
  14. Lexer for Power BI DAX
  15. Referenced from: https://github.com/sql-bi/SyntaxHighlighterBrushDax
  16. .. versionadded:: 2.15
  17. """
  18. name = 'Dax'
  19. aliases = ['dax']
  20. filenames = ['*.dax']
  21. url = 'https://learn.microsoft.com/en-us/dax/dax-function-reference'
  22. mimetypes = []
  23. tokens = {
  24. 'root': [
  25. (r'\s+', Whitespace),
  26. (r"--.*\n?", Comment.Single), # Comment: Double dash comment
  27. (r"//.*\n?", Comment.Single), # Comment: Double backslash comment
  28. (r'/\*', Comment.Multiline, 'multiline-comments'),
  29. (words(('abs', 'accrint', 'accrintm', 'acos', 'acosh', 'acot', 'acoth',
  30. 'addcolumns', 'addmissingitems', 'all', 'allcrossfiltered',
  31. 'allexcept', 'allnoblankrow', 'allselected', 'amordegrc', 'amorlinc',
  32. 'and','approximatedistinctcount', 'asin', 'asinh', 'atan', 'atanh',
  33. 'average', 'averagea', 'averagex', 'beta.dist', 'beta.inv',
  34. 'bitand', 'bitlshift', 'bitor', 'bitrshift', 'bitxor', 'blank',
  35. 'calculate', 'calculatetable', 'calendar', 'calendarauto', 'ceiling',
  36. 'chisq.dist', 'chisq.dist.rt', 'chisq.inv', 'chisq.inv.rt',
  37. 'closingbalancemonth', 'closingbalancequarter', 'closingbalanceyear',
  38. 'coalesce', 'columnstatistics', 'combin', 'combina', 'combinevalues',
  39. 'concatenate', 'concatenatex', 'confidence.norm', 'confidence.t',
  40. 'contains', 'containsrow', 'containsstring', 'containsstringexact',
  41. 'convert', 'cos', 'cosh', 'cot', 'coth', 'count', 'counta', 'countax',
  42. 'countblank', 'countrows', 'countx', 'coupdaybs', 'coupdays',
  43. 'coupdaysnc', 'coupncd', 'coupnum', 'couppcd', 'crossfilter',
  44. 'crossjoin', 'cumipmt', 'cumprinc', 'currency', 'currentgroup',
  45. 'customdata', 'datatable', 'date', 'dateadd', 'datediff',
  46. 'datesbetween', 'datesinperiod', 'datesmtd', 'datesqtd',
  47. 'datesytd', 'datevalue', 'day', 'db', 'ddb', 'degrees', 'detailrows',
  48. 'disc', 'distinct', 'distinctcount', 'distinctcountnoblank',
  49. 'divide', 'dollarde', 'dollarfr', 'duration', 'earlier', 'earliest',
  50. 'edate', 'effect', 'endofmonth', 'endofquarter', 'endofyear',
  51. 'eomonth', 'error', 'evaluateandlog', 'even', 'exact', 'except',
  52. 'exp', 'expon.dist', 'fact', 'false', 'filter', 'filters', 'find',
  53. 'firstdate', 'firstnonblank', 'firstnonblankvalue', 'fixed', 'floor',
  54. 'format', 'fv', 'gcd', 'generate', 'generateall', 'generateseries',
  55. 'geomean', 'geomeanx', 'groupby', 'hash', 'hasonefilter',
  56. 'hasonevalue', 'hour', 'if', 'if.eager', 'iferror', 'ignore', 'index',
  57. 'int', 'intersect', 'intrate', 'ipmt', 'isafter', 'isblank',
  58. 'iscrossfiltered', 'isempty', 'iserror', 'iseven', 'isfiltered',
  59. 'isinscope', 'islogical', 'isnontext', 'isnumber', 'iso.ceiling',
  60. 'isodd', 'isonorafter', 'ispmt', 'isselectedmeasure', 'issubtotal',
  61. 'istext', 'keepfilters', 'keywordmatch', 'lastdate', 'lastnonblank',
  62. 'lastnonblankvalue', 'lcm', 'left', 'len', 'linest', 'linestx', 'ln',
  63. 'log', 'log10', 'lookupvalue', 'lower', 'max', 'maxa', 'maxx',
  64. 'mduration', 'median', 'medianx', 'mid', 'min', 'mina', 'minute',
  65. 'minx', 'mod', 'month', 'mround', 'nameof', 'naturalinnerjoin',
  66. 'naturalleftouterjoin', 'networkdays', 'nextday', 'nextmonth',
  67. 'nextquarter', 'nextyear', 'nominal', 'nonvisual', 'norm.dist',
  68. 'norm.inv', 'norm.s.dist', 'norm.s.inv', 'not', 'now', 'nper', 'odd',
  69. 'oddfprice', 'oddfyield', 'oddlprice', 'oddlyield', 'offset',
  70. 'openingbalancemonth', 'openingbalancequarter', 'openingbalanceyear',
  71. 'or', 'orderby', 'parallelperiod', 'partitionby', 'path',
  72. 'pathcontains', 'pathitem', 'pathitemreverse', 'pathlength',
  73. 'pduration', 'percentile.exc', 'percentile.inc', 'percentilex.exc',
  74. 'percentilex.inc', 'permut', 'pi', 'pmt', 'poisson.dist', 'power',
  75. 'ppmt', 'previousday', 'previousmonth', 'previousquarter',
  76. 'previousyear', 'price', 'pricedisc', 'pricemat', 'product',
  77. 'productx', 'pv', 'quarter', 'quotient', 'radians', 'rand',
  78. 'randbetween', 'rank.eq', 'rankx', 'rate', 'received', 'related',
  79. 'relatedtable', 'removefilters', 'replace', 'rept', 'right',
  80. 'rollup', 'rollupaddissubtotal', 'rollupgroup', 'rollupissubtotal',
  81. 'round', 'rounddown', 'roundup', 'row', 'rri', 'sameperiodlastyear',
  82. 'sample', 'sampleaxiswithlocalminmax', 'search', 'second',
  83. 'selectcolumns', 'selectedmeasure', 'selectedmeasureformatstring',
  84. 'selectedmeasurename', 'selectedvalue', 'sign', 'sin', 'sinh', 'sln',
  85. 'sqrt', 'sqrtpi', 'startofmonth', 'startofquarter', 'startofyear',
  86. 'stdev.p', 'stdev.s', 'stdevx.p', 'stdevx.s', 'substitute',
  87. 'substitutewithindex', 'sum', 'summarize', 'summarizecolumns', 'sumx',
  88. 'switch', 'syd', 't.dist', 't.dist.2t', 't.dist.rt', 't.inv',
  89. 't.inv.2t', 'tan', 'tanh', 'tbilleq', 'tbillprice', 'tbillyield',
  90. 'time', 'timevalue', 'tocsv', 'today', 'tojson', 'topn',
  91. 'topnperlevel', 'topnskip', 'totalmtd', 'totalqtd', 'totalytd',
  92. 'treatas', 'trim', 'true', 'trunc', 'unichar', 'unicode', 'union',
  93. 'upper', 'userculture', 'userelationship', 'username', 'userobjectid',
  94. 'userprincipalname', 'utcnow', 'utctoday', 'value', 'values', 'var.p',
  95. 'var.s', 'varx.p', 'varx.s', 'vdb', 'weekday', 'weeknum', 'window',
  96. 'xirr', 'xnpv', 'year', 'yearfrac', 'yield', 'yielddisc', 'yieldmat'),
  97. prefix=r'(?i)', suffix=r'\b'), Name.Function), #Functions
  98. (words(('at','asc','boolean','both','by','create','currency',
  99. 'datetime','day','define','desc','double',
  100. 'evaluate','false','integer','measure',
  101. 'month','none','order','return','single','start','string',
  102. 'table','true','var','year'),
  103. prefix=r'(?i)', suffix=r'\b'), Name.Builtin), # Keyword
  104. (r':=|[-+*\/=^]', Operator),
  105. (r'\b(IN|NOT)\b', Operator.Word),
  106. (r'"', String, 'string'), #StringLiteral
  107. (r"'(?:[^']|'')*'(?!')(?:\[[ \w]+\])?|\w+\[[ \w]+\]",
  108. Name.Attribute), # Column reference
  109. (r"\[[ \w]+\]", Name.Attribute), #Measure reference
  110. (r'(?<!\w)(\d+\.?\d*|\.\d+\b)', Number),# Number
  111. (r'[\[\](){}`,.]', Punctuation), #Parenthesis
  112. (r'.*\n', Text),
  113. ],
  114. 'multiline-comments': [
  115. (r'/\*', Comment.Multiline, 'multiline-comments'),
  116. (r'\*/', Comment.Multiline, '#pop'),
  117. (r'[^/*]+', Comment.Multiline),
  118. (r'[/*]', Comment.Multiline)
  119. ],
  120. 'string': [
  121. (r'""', String.Escape),
  122. (r'"', String, '#pop'),
  123. (r'[^"]+', String),
  124. ]
  125. }