Hi
I'm trying to implement an XQuery editor. I'm most of the way there, but the embedded XML is causing me problems.
The language allows XML to be placed within it. The rules basically mean an XML section has to have paired element markers.
so you can haveas an added complication you can jump back into XQuery scope using {} brackets
I've been trying to use the standard XML langauge as a merge langauge, but this doesn't track the count of open elements. Is there an easy way to make this work?
Another issue is that the '<' token is somewhat ambiguous in the lexer scope as it can 'mean less' than or 'element start' token. I can resolve this 99% of the time using a lookahead on for the XML token ie "{QName}", but its not ideal.
I have code to produce my own lexer and grammar parser which produces an AST, although the lexer really needs the interaction with the grammar parser to work properly.
I was looking at the PerformLexicalParse & PerformSemanticParse methods and wondering if I could use my AST to implement these methods, but it looks like this will take a fair bit of coding, and I don't want to start down that route without knowing theres light at the end of the tunnel.
Any advice would be very welcome
Regards
Simon
An Example of the XQuery Syntax.
I'm trying to implement an XQuery editor. I'm most of the way there, but the embedded XML is causing me problems.
The language allows XML to be placed within it. The rules basically mean an XML section has to have paired element markers.
so you can have
let $row := 8 | XQuery Scope
<a> | Change to XML Scope
<b>
</b>
</a> | Return to Previous Scope
let $row := 8
let $row := 8 | XQuery Scope
<a> | Change to XML Scope
{ | Change to XQuery Scope
} | Return to Previous Scope
<b xx="{some XQuery Expression}>
</b>
</a> | Return to Previous Scope
let $row := 8 |
Another issue is that the '<' token is somewhat ambiguous in the lexer scope as it can 'mean less' than or 'element start' token. I can resolve this 99% of the time using a lookahead on for the XML token ie "{QName}", but its not ideal.
I have code to produce my own lexer and grammar parser which produces an AST, although the lexer really needs the interaction with the grammar parser to work properly.
I was looking at the PerformLexicalParse & PerformSemanticParse methods and wondering if I could use my AST to implement these methods, but it looks like this will take a fair bit of coding, and I don't want to start down that route without knowing theres light at the end of the tunnel.
Any advice would be very welcome
Regards
Simon
An Example of the XQuery Syntax.
declare function tour:list-possible-moves (
$board as xs:integer*,
$square as xs:integer )
as xs:integer*
{
let $row as xs:integer := $square idiv 8
let $column as xs:integer := $square mod 8
return
if ($row < 1)
then $square - 17 else ()
};
declare function tour:print-board (
$board as xs:integer* )
as element()
{
(: Output the board in HTML format :)
<html>
<head>
<title>Knight's tour</title>
</head>
<body>
<div align="center">
<h1>Knight's tour starting at {$start}</h1>
<table border="1" cellpadding="4">
{for $row in 0 to 7 return
<tr>
{for $column in 0 to 7
let $color :=
if ((($row + $column) mod 2)=1)
then 'xffff44'
else 'white' return
<td align="center" bgcolor="{$color}" width="22">{
let $n := $board[$row * 8 + $column + 1]
return
if ($endd != 64 and $n = $endd)
then <b>{$n}</b>
else if ($n = 0)
then " "
else $n
}</td>
}
</tr>
}
</table>
<p>{
if ($endd != 64)
then
<a href="Tour?start={$start}&end={$endd+1}">Step</a>
else ()
}</p>
</div>
</body>
</html>
};