Skip to content

Commit

Permalink
xquery 4: switch case .. without any parens
Browse files Browse the repository at this point in the history
  • Loading branch information
benibela committed Nov 29, 2023
1 parent d6ced24 commit 4959f7e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions data/xquery.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3389,6 +3389,7 @@ type TXQTerm_VisitorTrackKnownVariables = class(TXQTerm_Visitor)
PARSING_MODEL_XPATHXQUERY = [xqpmXPath2, xqpmXPath3_0, xqpmXPath3_1, xqpmXPath4_0, xqpmXQuery1, xqpmXQuery3_0, xqpmXQuery3_1, xqpmXQuery4_0];
PARSING_MODEL_XQUERY = [xqpmXQuery1, xqpmXQuery3_0, xqpmXQuery3_1, xqpmXQuery4_0];
PARSING_MODEL_XQUERY3 = [xqpmXQuery3_0, xqpmXQuery3_1, xqpmXQuery4_0];
PARSING_MODEL_XQUERY4 = [xqpmXQuery4_0];

var XMLNamespace_XPathFunctions, XMLnamespace_XPathFunctionsArray, XMLnamespace_XPathFunctionsMap, XMLNamespace_MyExtensionsNew, XMLNamespace_MyExtensionsMerged, XMLNamespace_MyExtensionOperators, XMLNamespace_XMLSchema: TNamespace;

Expand Down
10 changes: 7 additions & 3 deletions data/xquery__parse.pas
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ TXQParsingContext = class(TXQAbstractParsingContext)
procedure expect(c: char);
procedure expect(s: string);
function nextToken(lookahead: boolean=false): string;
function nextTokenIs(const s: string): boolean; //checks the next token and skips it if it matches
function nextTokenIs(const s: string; lookahead: boolean=false): boolean; //checks the next token and skips it if it matches
function nextTokenNCName(): string; inline; //returns a NCName

function expectTerm(const a: string; const bt: TParseTermFunction; c: string = ''): TXQTerm;
Expand Down Expand Up @@ -1060,7 +1060,7 @@ function TXQParsingContext.nextToken(lookahead: boolean=false): string;
else lastTokenStart := start;
end;

function TXQParsingContext.nextTokenIs(const s: string): boolean;
function TXQParsingContext.nextTokenIs(const s: string; lookahead: boolean=false): boolean;
var
temppos: pchar;
i: SizeInt;
Expand All @@ -1076,7 +1076,7 @@ function TXQParsingContext.nextTokenIs(const s: string): boolean;
if not (temppos^ in WHITE_SPACE + SYMBOLS + [#0]) then
exit(false);
result := true;
pos := temppos;
if not lookahead then pos := temppos;
end;

function TXQParsingContext.nextTokenNCName(): string;
Expand Down Expand Up @@ -3207,6 +3207,8 @@ function TXQParsingContext.parseValue: TXQTerm;
end;
'function', 'fn': if parsingModel in PARSING_MODEL4 then
exit(parseFunctionDeclarationWithoutArgs(nil));
'switch': if parsingModel in PARSING_MODEL_XQUERY4 then
exit(parseSwitch);
end;
'#': begin
require3('Named Function Reference');
Expand Down Expand Up @@ -3243,6 +3245,8 @@ function TXQParsingContext.parseValue: TXQTerm;
raiseParsingError('XQST0075', 'Schema validation is not supported');
end;
end;
'switch': if (nextTokenIs('case', true)) and (parsingModel in PARSING_MODEL_XQUERY4) then
exit(parseSwitch);
end;

if (word = '') or (word[1] in [',', ';', ':', ')', ']', '}']) then //todo: check if valid xml node name
Expand Down

0 comments on commit 4959f7e

Please sign in to comment.