Skip to content

Commit

Permalink
xquery 4 function annotations: allow boolean literals
Browse files Browse the repository at this point in the history
  • Loading branch information
benibela committed Nov 28, 2023
1 parent 982d50a commit a5699f9
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions data/xquery__parse.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2326,13 +2326,39 @@ function TXQParsingContext.parseDefineVariable: TXQTermDefineVariable;


function TXQParsingContext.parseAnnotations: TXQAnnotations;
function parseAnnotationValue(var term: TXQTerm): boolean;
begin
skipWhitespaceAndComment();
if not ( ( pos^ in ['''', '"', '.', '0'..'9'])) then begin
if parsingModel in PARSING_MODEL4 then begin
if (pos^ in ['t', 'f']) then begin
if nextTokenIs('true') then term := TXQTermConstant.create(xqvalueTrue)
else if nextTokenIs('false') then term := TXQTermConstant.create(xqvalueFalse)
else exit(false);
expect('('); expect(')');
exit(true);
end;
if pos^ = '-' then begin
term := parseValue;
result := (term is TXQTermBinaryOp)
and (TXQTermBinaryOp(term).op.name = 'unary~hack-')
and (TXQTermBinaryOp(term).children[1] is TXQTermConstant)
and (TXQTermConstant(TXQTermBinaryOp(term).children[1]).value.typeAnnotation.derivedFrom(schemaTypeDescendantsOfNumeric) );
exit;
end;
end;
exit(false);
end;
term := parseValue;
result := (term is TXQTermConstant) and (TXQTermConstant(term).value.Count = 1);
end;
var
namespaceUrl: string;
namespacePrefix: string;
local: string;
mode: TXQNamespaceMode;
begin
requireXQuery3('Annotations need XQuery 3');
requireXQuery3('Annotations need XQuery 3+');
try
result := nil;
setlength(result, 1);
Expand All @@ -2349,9 +2375,8 @@ function TXQParsingContext.parseAnnotations: TXQAnnotations;
if nextTokenIs('(') then begin
while true do begin
SetLength(params, length(params) + 1);
params[high(params)] := parseValue;
if not objInheritsFrom(params[high(params)], TXQTermConstant) or (TXQTermConstant(params[high(params)]).value.Count <> 1) then
raiseSyntaxError('Only literals allowed as annotation arguments');
if not parseAnnotationValue(params[high(params)]) then
raiseSyntaxError('Only literals allowed as annotation arguments');
if not nextTokenIs(',') then break;
end;
expect(')')
Expand Down

0 comments on commit a5699f9

Please sign in to comment.