Anarion Dunedain | e74ec3f | 2025-04-03 21:08:25 +0200 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: Power Query M |
| 3 | " Maintainer: Anarion Dunedain <anarion80@gmail.com> |
| 4 | " Last Change: |
| 5 | " 2025 Apr 03 First version |
| 6 | |
| 7 | " quit when a syntax file was already loaded |
| 8 | if exists("b:current_syntax") |
| 9 | finish |
| 10 | endif |
| 11 | |
| 12 | let s:keepcpo = &cpo |
| 13 | set cpo&vim |
| 14 | |
| 15 | " There are Power Query functions with dot or hash in the name |
| 16 | setlocal iskeyword+=. |
| 17 | setlocal iskeyword+=# |
| 18 | |
| 19 | setlocal foldmethod=syntax |
| 20 | setlocal foldtext=getline(v:foldstart) |
| 21 | |
| 22 | " DAX is case sensitive |
| 23 | syn case match |
| 24 | |
| 25 | " Any Power Query identifier |
| 26 | syn match pqIdentifier "\<[a-zA-Z0-9$_#]*\>" |
| 27 | |
| 28 | " Fold on parenthesis |
| 29 | syn region pqParenthesisFold start="(" end=")" transparent fold |
| 30 | |
| 31 | " Power Query keywords |
| 32 | syn keyword pqKeyword section sections shared |
| 33 | syn region pqKeyword start="\<let\>\c" end="\<in\>\c\%(\_s*$\)"me=s-2 transparent fold keepend containedin=ALLBUT,pqString,pqComment |
| 34 | |
| 35 | " Power Query types |
| 36 | syn keyword pqType null logical number time date datetime datetimezone duration text binary type list record table function anynonnull none |
| 37 | |
| 38 | " Power Query conditionals |
| 39 | syn keyword pqConditional if then else each |
| 40 | |
| 41 | " Power Query constants |
| 42 | syn keyword pqConstant |
| 43 | \ Number.E Number.Epsilon Number.NaN |
| 44 | \ Number.NegativeInfinity Number.PI Number.PositiveInfinity |
| 45 | |
| 46 | " TODO |
| 47 | syn keyword pqTodo FIXME NOTE TODO OPTIMIZE XXX HACK contained |
| 48 | |
| 49 | " Numbers |
| 50 | " integer number, or floating point number without a dot. |
| 51 | syn match pqNumber "\<\d\+\>" |
| 52 | " floating point number, with dot |
| 53 | syn match pqNumber "\<\d\+\.\d*\>" |
| 54 | |
| 55 | syn match pqFloat "[-+]\=\<\d\+[eE][\-+]\=\d\+" |
| 56 | syn match pqFloat "[-+]\=\<\d\+\.\d*\([eE][\-+]\=\d\+\)\=" |
| 57 | syn match pqFloat "[-+]\=\<\.\d\+\([eE][\-+]\=\d\+\)\=" |
| 58 | |
| 59 | " String and Character constants |
| 60 | syn region pqString start=+"+ end=+"+ |
| 61 | |
| 62 | " Power Query Record |
| 63 | syn region pqRecord matchgroup=pqParen start=/\[/ end=/\]/ contains=ALLBUT,pqIdentifier |
| 64 | |
| 65 | " Power Query List |
| 66 | syn region pqList matchgroup=pqParen start=/{/ end=/}/ contains=ALLBUT,pqIdentifier |
| 67 | |
| 68 | " Operators |
| 69 | syn match pqOperator "+" |
| 70 | syn match pqOperator "-" |
| 71 | syn match pqOperator "*" |
| 72 | syn match pqOperator "/" |
| 73 | syn match pqOperator "\<\(NOT\|AND\|OR\|AS\|IS\|META\)\>\c" |
| 74 | syn match pqOperator "??" |
| 75 | syn match pqOperator "&&" |
| 76 | syn match pqOperator "&" |
| 77 | syn match pqOperator "[<>]=\=" |
| 78 | syn match pqOperator "<>" |
| 79 | syn match pqOperator "=" |
| 80 | syn match pqOperator ">" |
| 81 | syn match pqOperator "<" |
| 82 | |
| 83 | " Comments |
| 84 | syn region pqComment start="\(^\|\s\)\//" end="$" contains=pqTodo |
| 85 | syn region pqComment start="/\*" end="\*/" contains=pqTodo |
| 86 | |
| 87 | " Power Query functions |
| 88 | syn keyword pqFunction |
| 89 | \ #binary #date #datetime #datetimezone #duration #table #time |
| 90 | \ Access.Database AccessControlEntry.ConditionToIdentities Action.WithErrorContext |
| 91 | \ ActiveDirectory.Domains AdoDotNet.DataSource AdoDotNet.Query AdobeAnalytics.Cubes |
| 92 | \ AnalysisServices.Database AnalysisServices.Databases AzureStorage.BlobContents |
| 93 | \ AzureStorage.Blobs AzureStorage.DataLake AzureStorage.DataLakeContents |
| 94 | \ AzureStorage.Tables Binary.ApproximateLength Binary.Buffer |
| 95 | \ Binary.Combine Binary.Compress Binary.Decompress |
| 96 | \ Binary.From Binary.FromList Binary.FromText |
| 97 | \ Binary.InferContentType Binary.Length Binary.Range |
| 98 | \ Binary.Split Binary.ToList Binary.ToText |
| 99 | \ Binary.View Binary.ViewError Binary.ViewFunction |
| 100 | \ BinaryFormat.7BitEncodedSignedInteger BinaryFormat.7BitEncodedUnsignedInteger BinaryFormat.Binary |
| 101 | \ BinaryFormat.Byte BinaryFormat.ByteOrder BinaryFormat.Choice |
| 102 | \ BinaryFormat.Decimal BinaryFormat.Double BinaryFormat.Group |
| 103 | \ BinaryFormat.Length BinaryFormat.List BinaryFormat.Null |
| 104 | \ BinaryFormat.Record BinaryFormat.SignedInteger16 BinaryFormat.SignedInteger32 |
| 105 | \ BinaryFormat.SignedInteger64 BinaryFormat.Single BinaryFormat.Text |
| 106 | \ BinaryFormat.Transform BinaryFormat.UnsignedInteger16 BinaryFormat.UnsignedInteger32 |
| 107 | \ BinaryFormat.UnsignedInteger64 Byte.From Byte.Type Cdm.Contents |
| 108 | \ Character.FromNumber Character.ToNumber Combiner.CombineTextByDelimiter |
| 109 | \ Combiner.CombineTextByEachDelimiter Combiner.CombineTextByLengths Combiner.CombineTextByPositions |
| 110 | \ Combiner.CombineTextByRanges Comparer.Equals Comparer.FromCulture |
| 111 | \ Comparer.Ordinal Comparer.OrdinalIgnoreCase Csv.Document |
| 112 | \ Cube.AddAndExpandDimensionColumn Cube.AddMeasureColumn Cube.ApplyParameter |
| 113 | \ Cube.AttributeMemberId Cube.AttributeMemberProperty Cube.CollapseAndRemoveColumns |
| 114 | \ Cube.Dimensions Cube.DisplayFolders Cube.MeasureProperties |
| 115 | \ Cube.MeasureProperty Cube.Measures Cube.Parameters |
| 116 | \ Cube.Properties Cube.PropertyKey Cube.ReplaceDimensions |
| 117 | \ Cube.Transform Currency.From Currency.Type DB2.Database |
| 118 | \ Date.AddDays Date.AddMonths Date.AddQuarters |
| 119 | \ Date.AddWeeks Date.AddYears Date.Day |
| 120 | \ Date.DayOfWeek Date.DayOfWeekName Date.DayOfYear |
| 121 | \ Date.DaysInMonth Date.EndOfDay Date.EndOfMonth |
| 122 | \ Date.EndOfQuarter Date.EndOfWeek Date.EndOfYear |
| 123 | \ Date.From Date.FromText Date.IsInCurrentDay |
| 124 | \ Date.IsInCurrentMonth Date.IsInCurrentQuarter Date.IsInCurrentWeek |
| 125 | \ Date.IsInCurrentYear Date.IsInNextDay Date.IsInNextMonth |
| 126 | \ Date.IsInNextNDays Date.IsInNextNMonths Date.IsInNextNQuarters |
| 127 | \ Date.IsInNextNWeeks Date.IsInNextNYears Date.IsInNextQuarter |
| 128 | \ Date.IsInNextWeek Date.IsInNextYear Date.IsInPreviousDay |
| 129 | \ Date.IsInPreviousMonth Date.IsInPreviousNDays Date.IsInPreviousNMonths |
| 130 | \ Date.IsInPreviousNQuarters Date.IsInPreviousNWeeks Date.IsInPreviousNYears |
| 131 | \ Date.IsInPreviousQuarter Date.IsInPreviousWeek Date.IsInPreviousYear |
| 132 | \ Date.IsInYearToDate Date.IsLeapYear Date.Month |
| 133 | \ Date.MonthName Date.QuarterOfYear Date.StartOfDay |
| 134 | \ Date.StartOfMonth Date.StartOfQuarter Date.StartOfWeek |
| 135 | \ Date.StartOfYear Date.ToRecord Date.ToText |
| 136 | \ Date.WeekOfMonth Date.WeekOfYear Date.Year |
| 137 | \ DateTime.AddZone DateTime.Date DateTime.FixedLocalNow |
| 138 | \ DateTime.From DateTime.FromFileTime DateTime.FromText |
| 139 | \ DateTime.IsInCurrentHour DateTime.IsInCurrentMinute DateTime.IsInCurrentSecond |
| 140 | \ DateTime.IsInNextHour DateTime.IsInNextMinute DateTime.IsInNextNHours |
| 141 | \ DateTime.IsInNextNMinutes DateTime.IsInNextNSeconds DateTime.IsInNextSecond |
| 142 | \ DateTime.IsInPreviousHour DateTime.IsInPreviousMinute DateTime.IsInPreviousNHours |
| 143 | \ DateTime.IsInPreviousNMinutes DateTime.IsInPreviousNSeconds DateTime.IsInPreviousSecond |
| 144 | \ DateTime.LocalNow DateTime.Time DateTime.ToRecord |
| 145 | \ DateTime.ToText DateTimeZone.FixedLocalNow DateTimeZone.FixedUtcNow |
| 146 | \ DateTimeZone.From DateTimeZone.FromFileTime DateTimeZone.FromText |
| 147 | \ DateTimeZone.LocalNow DateTimeZone.RemoveZone DateTimeZone.SwitchZone |
| 148 | \ DateTimeZone.ToLocal DateTimeZone.ToRecord DateTimeZone.ToText |
| 149 | \ DateTimeZone.ToUtc DateTimeZone.UtcNow DateTimeZone.ZoneHours |
| 150 | \ DateTimeZone.ZoneMinutes Decimal.From Decimal.Type DeltaLake.Metadata |
| 151 | \ DeltaLake.Table Diagnostics.ActivityId Diagnostics.CorrelationId |
| 152 | \ Diagnostics.Trace DirectQueryCapabilities.From Double.From Double.Type |
| 153 | \ Duration.Days Duration.From Duration.FromText |
| 154 | \ Duration.Hours Duration.Minutes Duration.Seconds |
| 155 | \ Duration.ToRecord Duration.ToText Duration.TotalDays |
| 156 | \ Duration.TotalHours Duration.TotalMinutes Duration.TotalSeconds |
| 157 | \ Embedded.Value Error.Record Essbase.Cubes |
| 158 | \ Excel.CurrentWorkbook Excel.ShapeTable Excel.Workbook |
| 159 | \ Exchange.Contents Expression.Constant Expression.Evaluate |
| 160 | \ Expression.Identifier File.Contents Folder.Contents |
| 161 | \ Folder.Files Function.From Function.Invoke |
| 162 | \ Function.InvokeAfter Function.InvokeWithErrorContext Function.IsDataSource |
| 163 | \ Function.ScalarVector Geography.FromWellKnownText Geography.ToWellKnownText |
| 164 | \ GeographyPoint.From Geometry.FromWellKnownText Geometry.ToWellKnownText |
| 165 | \ GeometryPoint.From GoogleAnalytics.Accounts Graph.Nodes |
| 166 | \ Guid.From Guid.Type HdInsight.Containers HdInsight.Contents |
| 167 | \ HdInsight.Files Hdfs.Contents Hdfs.Files |
| 168 | \ Html.Table Identity.From Identity.IsMemberOf |
| 169 | \ IdentityProvider.Default Informix.Database Int16.From Int16.Type |
| 170 | \ Int32.From Int32.Type Int64.From Int64.Type Int8.From Int8.Type |
| 171 | \ ItemExpression.From ItemExpression.Item Json.Document |
| 172 | \ Json.FromValue Json.FromValue Lines.FromBinary |
| 173 | \ Lines.FromText Lines.ToBinary Lines.ToText |
| 174 | \ List.Accumulate List.AllTrue List.Alternate |
| 175 | \ List.AnyTrue List.Average List.Buffer |
| 176 | \ List.Combine List.ConformToPageReader List.Contains |
| 177 | \ List.ContainsAll List.ContainsAny List.Count |
| 178 | \ List.Covariance List.DateTimeZones List.DateTimes |
| 179 | \ List.Dates List.Difference List.Distinct |
| 180 | \ List.Durations List.FindText List.First |
| 181 | \ List.FirstN List.Generate List.InsertRange |
| 182 | \ List.Intersect List.IsDistinct List.IsEmpty |
| 183 | \ List.Last List.LastN List.MatchesAll |
| 184 | \ List.MatchesAny List.Max List.MaxN |
| 185 | \ List.Median List.Min List.MinN |
| 186 | \ List.Mode List.Modes List.NonNullCount |
| 187 | \ List.Numbers List.Percentile List.PositionOf |
| 188 | \ List.PositionOfAny List.Positions List.Product |
| 189 | \ List.Random List.Range List.RemoveFirstN |
| 190 | \ List.RemoveItems List.RemoveLastN List.RemoveMatchingItems |
| 191 | \ List.RemoveNulls List.RemoveRange List.Repeat |
| 192 | \ List.ReplaceMatchingItems List.ReplaceRange List.ReplaceValue |
| 193 | \ List.Reverse List.Select List.Single |
| 194 | \ List.SingleOrDefault List.Skip List.Sort |
| 195 | \ List.Split List.StandardDeviation List.Sum |
| 196 | \ List.Times List.Transform List.TransformMany |
| 197 | \ List.Union List.Zip Logical.From |
| 198 | \ Logical.FromText Logical.ToText Module.Versions |
| 199 | \ MySQL.Database Number.Abs Number.Acos |
| 200 | \ Number.Asin Number.Atan Number.Atan2 |
| 201 | \ Number.BitwiseAnd Number.BitwiseNot Number.BitwiseOr |
| 202 | \ Number.BitwiseShiftLeft Number.BitwiseShiftRight Number.BitwiseXor |
| 203 | \ Number.Combinations Number.Cos Number.Cosh |
| 204 | \ Number.Exp Number.Factorial Number.From |
| 205 | \ Number.FromText Number.IntegerDivide Number.IsEven |
| 206 | \ Number.IsNaN Number.IsOdd Number.Ln |
| 207 | \ Number.Log Number.Log10 Number.Mod |
| 208 | \ Number.Permutations Number.Power Number.Random |
| 209 | \ Number.RandomBetween Number.Round Number.RoundAwayFromZero |
| 210 | \ Number.RoundDown Number.RoundTowardZero Number.RoundUp |
| 211 | \ Number.Sign Number.Sin Number.Sinh |
| 212 | \ Number.Sqrt Number.Tan Number.Tanh |
| 213 | \ Number.ToText Number.Type OData.Feed Odbc.DataSource |
| 214 | \ Odbc.InferOptions Odbc.Query OleDb.DataSource |
| 215 | \ OleDb.Query Oracle.Database Pdf.Tables |
| 216 | \ Percentage.From Percentage.Type PostgreSQL.Database Progress.DataSourceProgress |
| 217 | \ RData.FromBinary Record.AddField Record.Combine |
| 218 | \ Record.Field Record.FieldCount Record.FieldNames |
| 219 | \ Record.FieldOrDefault Record.FieldValues Record.FromList |
| 220 | \ Record.FromTable Record.HasFields Record.RemoveFields |
| 221 | \ Record.RenameFields Record.ReorderFields Record.SelectFields |
| 222 | \ Record.ToList Record.ToTable Record.TransformFields Record.Type |
| 223 | \ Replacer.ReplaceText Replacer.ReplaceValue RowExpression.Column |
| 224 | \ RowExpression.From RowExpression.Row Salesforce.Data |
| 225 | \ Salesforce.Reports SapBusinessWarehouse.Cubes SapHana.Database |
| 226 | \ SharePoint.Contents SharePoint.Files SharePoint.Tables |
| 227 | \ Single.From Single.Type Soda.Feed Splitter.SplitByNothing |
| 228 | \ Splitter.SplitTextByAnyDelimiter Splitter.SplitTextByCharacterTransition Splitter.SplitTextByDelimiter |
| 229 | \ Splitter.SplitTextByEachDelimiter Splitter.SplitTextByLengths Splitter.SplitTextByPositions |
| 230 | \ Splitter.SplitTextByRanges Splitter.SplitTextByRepeatedLengths Splitter.SplitTextByWhitespace |
| 231 | \ Sql.Database Sql.Databases SqlExpression.SchemaFrom |
| 232 | \ SqlExpression.ToExpression Sybase.Database Table.AddColumn |
| 233 | \ Table.AddFuzzyClusterColumn Table.AddIndexColumn Table.AddJoinColumn |
| 234 | \ Table.AddKey Table.AddRankColumn Table.AggregateTableColumn |
| 235 | \ Table.AlternateRows Table.ApproximateRowCount Table.Buffer |
| 236 | \ Table.Column Table.ColumnCount Table.ColumnNames |
| 237 | \ Table.ColumnsOfType Table.Combine Table.CombineColumns |
| 238 | \ Table.CombineColumnsToRecord Table.ConformToPageReader Table.Contains |
| 239 | \ Table.ContainsAll Table.ContainsAny Table.DemoteHeaders |
| 240 | \ Table.Distinct Table.DuplicateColumn Table.ExpandListColumn |
| 241 | \ Table.ExpandRecordColumn Table.ExpandTableColumn Table.FillDown |
| 242 | \ Table.FillUp Table.FilterWithDataTable Table.FindText |
| 243 | \ Table.First Table.FirstN Table.FirstValue |
| 244 | \ Table.FromColumns Table.FromList Table.FromPartitions |
| 245 | \ Table.FromRecords Table.FromRows Table.FromValue |
| 246 | \ Table.FuzzyGroup Table.FuzzyJoin Table.FuzzyNestedJoin |
| 247 | \ Table.Group Table.HasColumns Table.InsertRows |
| 248 | \ Table.IsDistinct Table.IsEmpty Table.Join |
| 249 | \ Table.Keys Table.Last Table.LastN |
| 250 | \ Table.MatchesAllRows Table.MatchesAnyRows Table.Max |
| 251 | \ Table.MaxN Table.Min Table.MinN |
| 252 | \ Table.NestedJoin Table.Partition Table.PartitionValues |
| 253 | \ Table.PartitionValues Table.Pivot Table.PositionOf |
| 254 | \ Table.PositionOfAny Table.PrefixColumns Table.Profile |
| 255 | \ Table.PromoteHeaders Table.Range Table.RemoveColumns |
| 256 | \ Table.RemoveFirstN Table.RemoveLastN Table.RemoveMatchingRows |
| 257 | \ Table.RemoveRows Table.RemoveRowsWithErrors Table.RenameColumns |
| 258 | \ Table.ReorderColumns Table.Repeat Table.ReplaceErrorValues |
| 259 | \ Table.ReplaceKeys Table.ReplaceMatchingRows Table.ReplaceRelationshipIdentity |
| 260 | \ Table.ReplaceRows Table.ReplaceValue Table.ReverseRows |
| 261 | \ Table.RowCount Table.Schema Table.SelectColumns |
| 262 | \ Table.SelectRows Table.SelectRowsWithErrors Table.SingleRow |
| 263 | \ Table.Skip Table.Sort Table.Split |
| 264 | \ Table.SplitAt Table.SplitColumn Table.StopFolding |
| 265 | \ Table.ToColumns Table.ToList Table.ToRecords |
| 266 | \ Table.ToRows Table.TransformColumnNames Table.TransformColumnTypes |
| 267 | \ Table.TransformColumns Table.TransformRows Table.Transpose |
| 268 | \ Table.Unpivot Table.UnpivotOtherColumns Table.View |
| 269 | \ Table.ViewError Table.ViewFunction Table.WithErrorContext |
| 270 | \ Tables.GetRelationships Teradata.Database Text.AfterDelimiter |
| 271 | \ Text.At Text.BeforeDelimiter Text.BetweenDelimiters |
| 272 | \ Text.Clean Text.Combine Text.Contains |
| 273 | \ Text.End Text.EndsWith Text.From |
| 274 | \ Text.FromBinary Text.InferNumberType Text.Insert |
| 275 | \ Text.Length Text.Lower Text.Middle |
| 276 | \ Text.NewGuid Text.PadEnd Text.PadStart |
| 277 | \ Text.PositionOf Text.PositionOfAny Text.Proper |
| 278 | \ Text.Range Text.Remove Text.RemoveRange |
| 279 | \ Text.Repeat Text.Replace Text.ReplaceRange |
| 280 | \ Text.Reverse Text.Select Text.Split |
| 281 | \ Text.SplitAny Text.Start Text.StartsWith |
| 282 | \ Text.ToBinary Text.ToList Text.Trim |
| 283 | \ Text.TrimEnd Text.TrimStart Text.Upper |
| 284 | \ Time.EndOfHour Time.From Time.FromText |
| 285 | \ Time.Hour Time.Minute Time.Second |
| 286 | \ Time.StartOfHour Time.ToRecord Time.ToText |
| 287 | \ Type.AddTableKey Type.ClosedRecord Type.Facets |
| 288 | \ Type.ForFunction Type.ForRecord Type.FunctionParameters |
| 289 | \ Type.FunctionRequiredParameters Type.FunctionReturn Type.Is |
| 290 | \ Type.IsNullable Type.IsOpenRecord Type.ListItem |
| 291 | \ Type.NonNullable Type.OpenRecord Type.RecordFields |
| 292 | \ Type.ReplaceFacets Type.ReplaceTableKeys Type.TableColumn |
| 293 | \ Type.TableKeys Type.TableRow Type.TableSchema |
| 294 | \ Type.Union Uri.BuildQueryString Uri.Combine |
| 295 | \ Uri.EscapeDataString Uri.Parts Value.Add |
| 296 | \ Value.Alternates Value.As Value.Compare |
| 297 | \ Value.Divide Value.Equals Value.Expression |
| 298 | \ Value.Firewall Value.FromText Value.Is |
| 299 | \ Value.Lineage Value.Metadata Value.Multiply |
| 300 | \ Value.NativeQuery Value.NullableEquals Value.Optimize |
| 301 | \ Value.RemoveMetadata Value.ReplaceMetadata Value.ReplaceType |
| 302 | \ Value.Subtract Value.Traits Value.Type |
| 303 | \ Value.VersionIdentity Value.Versions Value.ViewError |
| 304 | \ Value.ViewFunction Variable.Value Web.BrowserContents |
| 305 | \ Web.Contents Web.Headers Web.Page |
| 306 | \ WebAction.Request Xml.Document Xml.Tables |
| 307 | |
| 308 | |
| 309 | " Fold on let/in |
| 310 | " syn region pqLetFold start="\<let\>\c" end="\<in\>\c" transparent fold |
| 311 | |
| 312 | " Define highlighting |
| 313 | hi def link pqComment Comment |
| 314 | hi def link pqNumber Number |
| 315 | hi def link pqFloat Float |
| 316 | hi def link pqString String |
| 317 | hi def link pqKeyword Keyword |
| 318 | hi def link pqOperator Operator |
| 319 | hi def link pqFunction Delimiter |
| 320 | hi def link pqTable Number |
| 321 | hi def link pqRecord Statement |
| 322 | hi def link pqList Delimiter |
| 323 | hi def link pqParen Delimiter |
| 324 | hi def link pqTodo Todo |
| 325 | hi def link pqConditional Conditional |
| 326 | hi def link pqNull Const |
| 327 | hi def link pqType Type |
| 328 | hi def link pqIdentifier Number |
| 329 | hi def link pqConstant Constant |
| 330 | hi def link pqLetFold Constant |
| 331 | |
| 332 | let b:current_syntax = "pq" |
| 333 | |
| 334 | let &cpo = s:keepcpo |
| 335 | unlet! s:keepcpo |
| 336 | |
| 337 | " vim: ts=8 |