Skip to content

Commit

Permalink
remove more obsolete code
Browse files Browse the repository at this point in the history
  • Loading branch information
GuntherRademacher committed Dec 26, 2024
1 parent f6e7643 commit e368de2
Showing 1 changed file with 1 addition and 120 deletions.
121 changes: 1 addition & 120 deletions src/main/resources/de/bottlecaps/convert/xq/to-w3c.xq
Original file line number Diff line number Diff line change
Expand Up @@ -229,123 +229,4 @@ declare function x:split-string($todo as xs:string, $done as element()*) as elem
declare function x:split-string($todo as xs:string) as element()*
{
x:split-string($todo, ())
};

(:~
: Get the sequence of parser productions from a grammar.
:
: @param $grammar the grammar.
: @return the sequence of parser productions.
:)
declare function x:parser-productions($grammar as element(g:grammar)) as element(g:production)*
{
let $end := n:syntax-end($grammar)
let $parser-rules := n:children($grammar)[not(. is $end or . >> $end)]
return $parser-rules/self::g:production
};

(:~
: Get the whitepace definition from a grammar.
:
: @param $grammar the grammar.
: @return the whitespace definition production, if the grammar contains one.
:)
declare function x:whitespace($grammar as element(g:grammar)) as element(g:production)?
{
x:parser-productions($grammar)[@whitespace-spec eq "definition"]
};

(:~
: Get the start symbols from a grammar.
:
: @param $grammar the grammar.
: @return the set of start symbols. Empty, if none could be identified.
:)
declare function x:start-symbols($grammar as element(g:grammar)) as element(g:production)*
{
let $parser-productions := x:parser-productions($grammar)
for $s in $parser-productions[not(@whitespace-spec eq "definition")]
where empty($parser-productions//g:ref[@name eq $s/@name and empty(@context)])
return $s
};

(:~
: Check whether a grammar fragment is in BNF, as opposed to
: EBNF.
:
: @param $nodes the grammar fragment as a sequence of nodes.
: @return true, if it does not contain non-BNF constructs.
:)
declare function x:is-bnf($nodes as node()*) as xs:boolean
{
every $node in $nodes
satisfies
typeswitch ($node)
case element(g:grammar) return
every $p in x:parser-productions($node) satisfies x:is-bnf($p)
case element(g:production) return
let $children := n:children($node)
return
if ($node/g:choice and count($children) eq 1) then
every $c in $children/*/n:unwrap-sequence(.) satisfies(x:is-bnf($c))
else
x:is-bnf($children)
case element(g:ref) return
true()
case element(g:string) return
true()
case processing-instruction() return
true()
default return
false()
};

(:~
: Rewrite a grammar fragment, while inlining some nonterminal references. Drop
: the inlined productions from the result.
:
: @param $nodes the grammar fragment.
: @param $inline-nonterminals the set of nonterminal productions
: that will be inlined to their reference context.
: @return the rewritten grammar fragment.
:)
declare function x:inline($nodes as node()*,
$inline-nonterminals as element(g:production)*) as node()*
{
for $node in $nodes
return
typeswitch ($node)
case element(g:production) return
if ($node/@name = $inline-nonterminals/@name) then
()
else
element g:production
{
$node/@*,
x:inline($node/node(), $inline-nonterminals)
}
case element(g:ref) return
if ($node/@context or not($node/@name = $inline-nonterminals/@name)) then
$node
else
let $definition := $inline-nonterminals[@name eq $node/@name]
return x:inline(n:children($definition), $inline-nonterminals)
case element() return
element {node-name($node)}
{
$node/@*,
let $children := n:children($node)
return
if (empty($children)) then
$node/node()
else
for $c in n:children($node)
return
if (n:is-sequence-item($c)) then
x:inline($c, $inline-nonterminals)
else
n:wrap-sequence(x:inline(n:unwrap-sequence($c), $inline-nonterminals))
}
default return
$node
};
};

0 comments on commit e368de2

Please sign in to comment.