/powerquery-parser

A parser for the Power Query / M formula language, written in TypeScript

Primary LanguageTypeScriptMIT LicenseMIT

powerquery-parser

Build Status

A parser for the Power Query/M language, written in TypeScript. Designed to be consumed by other projects.

How to use

A few minimal code samples can be found in example.ts.

If you're planning on parsing static documents then you should use the tryLexAndParse function located in src/jobs.ts. This function attempts to lex a document, pass the results to the parser, and then return the outcome.

If you're planning to perform repeated lexing and parses, such as being a part of a Visual Studi Code extension, then for performance reasons you should avoid the tryLexAndParse helper function. Instead you should create a Lexer instance and as your text changes update the lexer using the public APIs located in src/lexer/lexer.ts. Once you need to parse the document follow the same steps in src/jobs.ts; create a LexerSnapshot and pass the result to the parser.

Things to note

Parser

The parser is a rather naive recursive descent parser with limited backtracking. It mostly follows official specification released in October 2016. Deviations from the specification should be marked down in specification.md

Style

This project uses prettier as the primary source of style enforcement. Additional style requirements are located in style.md.

How to build

  • Install NodeJS
  • npm install
  • npm run-script build

How to run tests

  • Install NodeJS
  • npm install
  • npm test

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.