Re: [xsl] Are XPath expressions parsed using compiler parsingtechniques?2022-05-10 00:59:28
Hi Roger,
The second version of Fleur, my own XQuery engine written in _javascript_, is also including its own handwritten parser. This one is a _javascript_ port from the XSLT stylesheet of old XSLTForms versions which parsed XPath expressions into _javascript_ instructions. It can be tricky for a homemade parser to consider, first, "if" as an element name, then, "if(a eq b)" as a function call, then "if(a eq b) then" as the beginning of an If-then-else statement, because "if" is not a keyword.
About errors detection, it is quite helpful for developers to locate each error within the corresponding source text. This location collect has to be implemented within the parser.
Static errors are to be detected at parser/compiler step. Some are grammatical errors and parsing will detect them. Others are due to type errors: after parsing, some kind of evaluation has to be performed not with values but with types (sequence types, actually), and sometimes union of types, to avoid most type checks at runtime. It is also surely possible to evaluate static expressions, such as 3 + 5, and to normalize values, such as 7.00. For optimising the compiler output, it is interesting to consider that atomization is useless on atoms. For runtime, considering position predicates, such as [1], is a common optimisation.
Dynamic errors handling requires links to source within the result of the parser/compiler. It is also required for a step debugger.
--Alain
|
|