Skip to content

Commit

Permalink
Addressing #45: towards XPath parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
wendellpiez authored and david-waltermire committed Sep 17, 2020
1 parent 8c66642 commit 1e69eac
Show file tree
Hide file tree
Showing 5 changed files with 6,117 additions and 0 deletions.
55 changes: 55 additions & 0 deletions toolchains/xslt-proto-v04/make-metaschema-metatron.xpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0"
xmlns:metaschema="http://csrc.nist.gov/ns/metaschema/1.0"
type="metaschema:make-metaschema-metatron" name="make-metaschema-metatron">

<!-- &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& -->
<!-- Ports -->

<p:input port="source" primary="true"/>
<p:input port="parameters" kind="parameter"/>

<p:serialization port="a.echo-input" indent="true"/>
<p:output port="a.echo-input" primary="false">
<p:pipe port="result" step="input"/>
</p:output>

<p:serialization port="b.composed" indent="true"/>
<p:output port="b.composed" primary="false">
<p:pipe port="result" step="composed"/>
</p:output>

<p:serialization port="c.metatron" indent="true"/>
<p:output port="c.metatron" primary="false">
<p:pipe port="result" step="make-metatron"/>
</p:output>

<p:serialization port="f.final" indent="true" method="xml" omit-xml-declaration="false"/>
<p:output port="f.final" primary="true">
<p:pipe port="result" step="final"/>
</p:output>

<!-- &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& -->
<!-- Import (subpipeline) -->

<p:import href="metaschema-compose.xpl"/>

<!-- &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& &&& -->
<!-- Pipeline -->

<p:identity name="input"/>

<metaschema:metaschema-compose name="compose"/>

<p:identity name="composed"/>

<p:xslt name="make-metatron">
<p:input port="stylesheet">
<p:document href="schema_gen/make-metaschema-metatron.xsl"/>
</p:input>
</p:xslt>

<p:identity name="final"/>

</p:declare-step>
1 change: 1 addition & 0 deletions toolchains/xslt-proto-v04/metapath/REx/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Using Gunther Rademacher's REx parser (https://www.bottlecaps.de/rex/) as an interim solution for XPath parsing.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
318 changes: 318 additions & 0 deletions toolchains/xslt-proto-v04/metapath/REx/xpath20.ebnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,318 @@
XPath ::= Expr EOF
Expr ::= ExprSingle ( ',' ExprSingle )*
ExprSingle
::= ForExpr
| QuantifiedExpr
| IfExpr
| OrExpr
ForExpr ::= SimpleForClause 'return' ExprSingle
SimpleForClause
::= 'for' '$' VarName 'in' ExprSingle ( ',' '$' VarName 'in' ExprSingle )*
QuantifiedExpr
::= ( 'some' | 'every' ) '$' VarName 'in' ExprSingle ( ',' '$' VarName 'in' ExprSingle )* 'satisfies' ExprSingle
IfExpr ::= 'if' '(' Expr ')' 'then' ExprSingle 'else' ExprSingle
OrExpr ::= AndExpr ( 'or' AndExpr )*
AndExpr ::= ComparisonExpr ( 'and' ComparisonExpr )*
ComparisonExpr
::= RangeExpr ( ( ValueComp | GeneralComp | NodeComp ) RangeExpr )?
RangeExpr
::= AdditiveExpr ( 'to' AdditiveExpr )?
AdditiveExpr
::= MultiplicativeExpr ( ( '+' | '-' ) MultiplicativeExpr )*
MultiplicativeExpr
::= UnionExpr ( ( '*' | 'div' | 'idiv' | 'mod' ) UnionExpr )*
UnionExpr
::= IntersectExceptExpr ( ( 'union' | '|' ) IntersectExceptExpr )*
IntersectExceptExpr
::= InstanceofExpr ( ( 'intersect' | 'except' ) InstanceofExpr )*
InstanceofExpr
::= TreatExpr ( 'instance' 'of' SequenceType )?
TreatExpr
::= CastableExpr ( 'treat' 'as' SequenceType )?
CastableExpr
::= CastExpr ( 'castable' 'as' SingleType )?
CastExpr ::= UnaryExpr ( 'cast' 'as' SingleType )?
UnaryExpr
::= ( '-' | '+' )* ValueExpr
ValueExpr
::= PathExpr
GeneralComp
::= '='
| '!='
| '<'
| '<='
| '>'
| '>='
ValueComp
::= 'eq'
| 'ne'
| 'lt'
| 'le'
| 'gt'
| 'ge'
NodeComp ::= 'is'
| '<<'
| '>>'
PathExpr ::= '/' ( RelativePathExpr / )
| '//' RelativePathExpr
| RelativePathExpr
RelativePathExpr
::= StepExpr ( ( '/' | '//' ) StepExpr )*
StepExpr ::= FilterExpr
| AxisStep
AxisStep ::= ( ReverseStep | ForwardStep ) PredicateList
ForwardStep
::= ForwardAxis NodeTest
| AbbrevForwardStep
ForwardAxis
::= 'child' '::'
| 'descendant' '::'
| 'attribute' '::'
| 'self' '::'
| 'descendant-or-self' '::'
| 'following-sibling' '::'
| 'following' '::'
| 'namespace' '::'
AbbrevForwardStep
::= '@'? NodeTest
ReverseStep
::= ReverseAxis NodeTest
| AbbrevReverseStep
ReverseAxis
::= 'parent' '::'
| 'ancestor' '::'
| 'preceding-sibling' '::'
| 'preceding' '::'
| 'ancestor-or-self' '::'
AbbrevReverseStep
::= '..'
NodeTest ::= KindTest
| NameTest
NameTest ::= QName
| Wildcard
FilterExpr
::= PrimaryExpr PredicateList
PredicateList
::= Predicate*
Predicate
::= '[' Expr ']'
PrimaryExpr
::= Literal
| VarRef
| ParenthesizedExpr
| ContextItemExpr
| FunctionCall
Literal ::= NumericLiteral
| StringLiteral
NumericLiteral
::= IntegerLiteral
| DecimalLiteral
| DoubleLiteral
VarRef ::= '$' VarName
VarName ::= QName
ParenthesizedExpr
::= '(' Expr? ')'
ContextItemExpr
::= '.'
FunctionCall
::= FunctionName '(' ( ExprSingle ( ',' ExprSingle )* )? ')'
SingleType
::= AtomicType '?'?
SequenceType
::= 'empty-sequence' '(' ')'
| ItemType OccurrenceIndicator?
OccurrenceIndicator
::= '?'
| '*'^OccurrenceIndicator
| '+'^OccurrenceIndicator
ItemType ::= KindTest
| 'item' '(' ')'
| AtomicType
AtomicType
::= QName
KindTest ::= DocumentTest
| ElementTest
| AttributeTest
| SchemaElementTest
| SchemaAttributeTest
| PITest
| CommentTest
| TextTest
| AnyKindTest
AnyKindTest
::= 'node' '(' ')'
DocumentTest
::= 'document-node' '(' ( ElementTest | SchemaElementTest )? ')'
TextTest ::= 'text' '(' ')'
CommentTest
::= 'comment' '(' ')'
PITest ::= 'processing-instruction' '(' ( NCName | StringLiteral )? ')'
AttributeTest
::= 'attribute' '(' ( AttribNameOrWildcard ( ',' TypeName )? )? ')'
AttribNameOrWildcard
::= AttributeName
| '*'
SchemaAttributeTest
::= 'schema-attribute' '(' AttributeDeclaration ')'
AttributeDeclaration
::= AttributeName
ElementTest
::= 'element' '(' ( ElementNameOrWildcard ( ',' TypeName '?'? )? )? ')'
ElementNameOrWildcard
::= ElementName
| '*'
SchemaElementTest
::= 'schema-element' '(' ElementDeclaration ')'
ElementDeclaration
::= ElementName
AttributeName
::= QName
ElementName
::= QName
TypeName ::= QName
QName ::= FunctionName
| 'attribute'
| 'comment'
| 'document-node'
| 'element'
| 'empty-sequence'
| 'if'
| 'item'
| 'node'
| 'processing-instruction'
| 'schema-attribute'
| 'schema-element'
| 'text'
| 'typeswitch'
FunctionName
::= QName^Token
| 'ancestor'
| 'ancestor-or-self'
| 'and'
| 'cast'
| 'castable'
| 'child'
| 'descendant'
| 'descendant-or-self'
| 'div'
| 'else'
| 'eq'
| 'every'
| 'except'
| 'following'
| 'following-sibling'
| 'for'
| 'ge'
| 'gt'
| 'idiv'
| 'instance'
| 'intersect'
| 'is'
| 'le'
| 'lt'
| 'mod'
| 'namespace'
| 'ne'
| 'or'
| 'parent'
| 'preceding'
| 'preceding-sibling'
| 'return'
| 'satisfies'
| 'self'
| 'some'
| 'to'
| 'treat'
| 'union'
WhiteSpace
::= ( S^WhiteSpace | Comment )+
/* ws: definition */
Comment ::= '(:' ( CommentContents | Comment )* ':)'
/* ws: explicit */

<?TOKENS?>

EOF ::= $
IntegerLiteral
::= Digits
DecimalLiteral
::= '.' Digits
| Digits '.' [0-9]*
/* ws: explicit */
DoubleLiteral
::= ( '.' Digits | Digits ( '.' [0-9]* )? ) [eE] [+#x2D]? Digits
/* ws: explicit */
StringLiteral
::= '"' ( EscapeQuot | [^"] )* '"'
| "'" ( EscapeApos | [^'] )* "'"
/* ws: explicit */
EscapeQuot
::= '""'
EscapeApos
::= "''"
Wildcard ::= '*'
| NCName ':' '*'
| '*' ':' NCName
/* ws: explicit */
NameStartChar
::= ':'
| [A-Z]
| '_'
| [a-z]
| [#x00C0-#x00D6]
| [#x00D8-#x00F6]
| [#x00F8-#x02FF]
| [#x0370-#x037D]
| [#x037F-#x1FFF]
| [#x200C-#x200D]
| [#x2070-#x218F]
| [#x2C00-#x2FEF]
| [#x3001-#xD7FF]
| [#xF900-#xFDCF]
| [#xFDF0-#xFFFD]
| [#x10000-#xEFFFF]
NameChar ::= NameStartChar
| '-'
| '.'
| [0-9]
| #x00B7
| [#x0300-#x036F]
| [#x203F-#x2040]
Name ::= NameStartChar NameChar*
NCName ::= Name - ( Char* ':' Char* )
QName ::= PrefixedName
| UnprefixedName
PrefixedName
::= Prefix ':' LocalPart
UnprefixedName
::= LocalPart
Prefix ::= NCName
LocalPart
::= NCName
Char ::= #x0009
| #x000A
| #x000D
| [#x0020-#xD7FF]
| [#xE000-#xFFFD]
| [#x10000-#x10FFFF]
Digits ::= [0-9]+
S ::= ( #x0020 | #x0009 | #x000D | #x000A )+
CommentContents
::= ( ( Char+ - ( Char* ( '(:' | ':)' ) Char* ) ) - ( Char* '(' ) ) &':'
| ( Char+ - ( Char* ( '(:' | ':)' ) Char* ) ) &'('
'+' << '+'^OccurrenceIndicator
'*' << Wildcard '*'^OccurrenceIndicator
QName^Token
<< 'ancestor' 'ancestor-or-self' 'and' 'attribute' 'cast' 'castable' 'child' 'comment' 'descendant' 'descendant-or-self' 'div' 'document-node' 'element' 'else' 'empty-sequence' 'eq' 'every' 'except' 'following' 'following-sibling' 'for' 'ge' 'gt' 'idiv' 'if' 'instance' 'intersect' 'is' 'item' 'le' 'lt' 'mod' 'namespace' 'ne' 'node' 'or' 'parent' 'preceding' 'preceding-sibling' 'processing-instruction' 'return' 'satisfies' 'schema-attribute' 'schema-element' 'self' 'some' 'text' 'to' 'treat' 'typeswitch' 'union'
NonNCNameChar
::= $
| ':'
| Char - NameChar
DelimitingChar
::= NonNCNameChar
| '-'
| '.'
DelimitingChar
\\ DecimalLiteral DoubleLiteral IntegerLiteral
NonNCNameChar
\\ NCName QName^Token 'ancestor' 'ancestor-or-self' 'and' 'as' 'attribute' 'cast' 'castable' 'child' 'comment' 'descendant' 'descendant-or-self' 'div' 'document-node' 'element' 'else' 'empty-sequence' 'eq' 'every' 'except' 'following' 'following-sibling' 'for' 'ge' 'gt' 'idiv' 'if' 'in' 'instance' 'intersect' 'is' 'item' 'le' 'lt' 'mod' 'namespace' 'ne' 'node' 'of' 'or' 'parent' 'preceding' 'preceding-sibling' 'processing-instruction' 'return' 'satisfies' 'schema-attribute' 'schema-element' 'self' 'some' 'text' 'then' 'to' 'treat' 'typeswitch' 'union'
Loading

0 comments on commit 1e69eac

Please sign in to comment.