Skip to content

Commit 98cbf98

Browse files
Add ParseBehavior to parser settings (#393)
* initial commit * incrementing version * adjusting name to be explicit * Update src/powerquery-parser/parser/parser/parserUtils.ts Co-authored-by: Copilot <[email protected]> * ran 'npm audit fix' * fixing lint issue from copilot * removing ':' * about to work on IdentifierUtilsOptions * perhaps complete * Revert "perhaps complete" This reverts commit aef0085. * Revert "about to work on IdentifierUtilsOptions" This reverts commit 6fdbe2f. * removing unneeded try/catch * added tryParseHelper * simplified further --------- Co-authored-by: Copilot <[email protected]>
1 parent 3f1f066 commit 98cbf98

File tree

15 files changed

+722
-510
lines changed

15 files changed

+722
-510
lines changed

package-lock.json

Lines changed: 16 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@microsoft/powerquery-parser",
3-
"version": "0.16.1",
3+
"version": "0.17.0",
44
"description": "A parser for the Power Query/M formula language.",
55
"author": "Microsoft",
66
"license": "MIT",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
export enum ParseBehavior {
5+
ParseEitherExpressionOrSection = "ParseEitherExpressionOrSection",
6+
ParseExpression = "ParseExpression",
7+
ParseSection = "ParseSection",
8+
}

src/powerquery-parser/parser/parseSettings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import { Ast } from "../language";
55
import { CommonSettings } from "../common";
66
import { LexerSnapshot } from "../lexer";
7+
import { ParseBehavior } from "./parseBehavior";
78
import { Parser } from "./parser";
89
import { ParseState } from "./parseState";
910

1011
export interface ParseSettings extends CommonSettings {
12+
readonly parseBehavior: ParseBehavior;
1113
readonly parser: Parser;
12-
readonly newParseState: (lexerSnapshot: LexerSnapshot, overrides: Partial<ParseState> | undefined) => ParseState;
14+
readonly newParseState: (lexerSnapshot: LexerSnapshot, overrides?: Partial<ParseState>) => ParseState;
1315
readonly parserEntryPoint:
1416
| ((state: ParseState, parser: Parser, correlationId: number | undefined) => Promise<Ast.TNode>)
1517
| undefined;

src/powerquery-parser/parser/parseState/parseState.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { Disambiguation } from "../disambiguation";
55
import { ICancellationToken } from "../../common";
66
import { LexerSnapshot } from "../../lexer";
7+
import { ParseBehavior } from "../parseBehavior";
78
import { ParseContext } from "..";
89
import { Token } from "../../language";
910
import { TraceManager } from "../../common/trace";
@@ -13,6 +14,7 @@ export interface ParseState {
1314
readonly disambiguationBehavior: Disambiguation.DismabiguationBehavior;
1415
readonly lexerSnapshot: LexerSnapshot;
1516
readonly locale: string;
17+
readonly parseBehavior: ParseBehavior;
1618
readonly traceManager: TraceManager;
1719
contextState: ParseContext.State;
1820
currentContextNode: ParseContext.TNode | undefined;

src/powerquery-parser/parser/parseState/parseStateUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import { NoOpTraceManagerInstance, Trace } from "../../common/trace";
88
import { DefaultLocale } from "../../localization";
99
import { Disambiguation } from "../disambiguation";
1010
import { LexerSnapshot } from "../../lexer";
11+
import { ParseBehavior } from "../parseBehavior";
1112
import { ParseState } from "./parseState";
1213
import { SequenceKind } from "../error";
1314

14-
export function newState(lexerSnapshot: LexerSnapshot, overrides: Partial<ParseState> | undefined): ParseState {
15+
export function newState(lexerSnapshot: LexerSnapshot, overrides?: Partial<ParseState>): ParseState {
1516
const tokenIndex: number = overrides?.tokenIndex ?? 0;
1617
const currentToken: Token.Token | undefined = lexerSnapshot.tokens[tokenIndex];
1718
const currentTokenKind: Token.TokenKind | undefined = currentToken?.kind;
@@ -30,6 +31,7 @@ export function newState(lexerSnapshot: LexerSnapshot, overrides: Partial<ParseS
3031

3132
return {
3233
...overrides,
34+
parseBehavior: overrides?.parseBehavior ?? ParseBehavior.ParseEitherExpressionOrSection,
3335
disambiguationBehavior: overrides?.disambiguationBehavior ?? Disambiguation.DismabiguationBehavior.Thorough,
3436
lexerSnapshot,
3537
locale: overrides?.locale ?? DefaultLocale,

src/powerquery-parser/parser/parser/parser.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ export interface Parser {
5050
correlationId: number | undefined,
5151
) => Ast.IdentifierExpression;
5252

53-
// 12.2.1 Documents
54-
readonly readDocument: (
55-
state: ParseState,
56-
parser: Parser,
57-
correlationId: number | undefined,
58-
) => Promise<Ast.TDocument>;
59-
6053
// 12.2.2 Section Documents
6154
readonly readSectionDocument: (
6255
state: ParseState,

0 commit comments

Comments
 (0)