Skip to content

Commit

Permalink
remove obsolete code for recursion removal that prevented current sol…
Browse files Browse the repository at this point in the history
…ution (rex-parser-generator#7)
  • Loading branch information
GuntherRademacher committed Dec 24, 2024
1 parent 769404b commit 7a2101f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1,155 deletions.
28 changes: 11 additions & 17 deletions src/main/resources/de/bottlecaps/convert/xq/bison/bison-to-w3c.xq
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,17 @@ declare function x:rewrite($alternatives as element(rhs)+) as element()*

declare function x:bison-to-w3c($parse-tree as element(input)) as element(g:grammar)
{
t:remove-right-recursion
(
t:remove-left-recursion
(
element g:grammar
element g:grammar
{
let $rules := $parse-tree//rules
for $id in distinct-values($rules/id/ID)
let $rule := $rules[id/ID = $id]
order by min($rule/index-of($rules, .))
return
element g:production
{
let $rules := $parse-tree//rules
for $id in distinct-values($rules/id/ID)
let $rule := $rules[id/ID = $id]
order by min($rule/index-of($rules, .))
return
element g:production
{
attribute name {$id},
x:rewrite($rule/rhs)
}
attribute name {$id},
x:rewrite($rule/rhs)
}
)
)
}
};
20 changes: 7 additions & 13 deletions src/main/resources/de/bottlecaps/convert/xq/gold/gold-to-w3c.xq
Original file line number Diff line number Diff line change
Expand Up @@ -676,19 +676,13 @@ declare function p:gold-to-w3c($parse-tree as element(Grammar)) as element(g:gra
:)
()
return
t:remove-right-recursion
p:case-insensitive-refs
(
t:remove-left-recursion
(
p:case-insensitive-refs
(
<g:grammar>
{$syntax-productions, $ignore-production[@whitespace-spec]}
{processing-instruction TOKENS{}}
{$tokens-productions, $ignore-production[empty(@whitespace-spec)], $eof-production}
{$preferences}
</g:grammar>
)
)
<g:grammar>
{$syntax-productions, $ignore-production[@whitespace-spec]}
{processing-instruction TOKENS{}}
{$tokens-productions, $ignore-production[empty(@whitespace-spec)], $eof-production}
{$preferences}
</g:grammar>
)
};
70 changes: 32 additions & 38 deletions src/main/resources/de/bottlecaps/convert/xq/jison/jison-to-w3c.xq
Original file line number Diff line number Diff line change
Expand Up @@ -49,47 +49,41 @@ declare function x:tokenize($string as xs:string*) as xs:string*

declare function x:jison-to-w3c($parse-tree as element(jison)) as element(g:grammar)
{
t:remove-right-recursion
(
t:remove-left-recursion
(
element g:grammar
{
for $p in $parse-tree/spec/grammar/production_list/production
return element g:production {attribute name {$p/id/ID}, x:rewrite($p/handle_list/handle_action)},
element g:grammar
{
for $p in $parse-tree/spec/grammar/production_list/production
return element g:production {attribute name {$p/id/ID}, x:rewrite($p/handle_list/handle_action)},

for $p in $parse-tree/json/bnf-pair/rule-pair
let $id := $p/string
for $p in $parse-tree/json/bnf-pair/rule-pair
let $id := $p/string
return
element g:production
{
attribute name {substring($id, 2, string-length($id) - 2)},
x:rewrite
(
for $s in $p/alternative/string
let $symbols := x:tokenize(substring($s, 2, string-length($s) - 2))
return
element g:production
{
attribute name {substring($id, 2, string-length($id) - 2)},
x:rewrite
(
for $s in $p/alternative/string
let $symbols := x:tokenize(substring($s, 2, string-length($s) - 2))
return
if (empty($symbols)) then
<handle_action/>
else
element handle_action
if (empty($symbols)) then
<handle_action/>
else
element handle_action
{
for $t in $symbols
return
element handle
{
for $t in $symbols
return
element handle
{
element symbol
{
if (matches($t, "^\p{Lu}") or $parse-tree/json/bnf-pair/rule-pair/string = concat("""", $t, """")) then
element id {element ID {$t}}
else
element STRING {concat('"', $t, '"')}
}
}
element symbol
{
if (matches($t, "^\p{Lu}") or $parse-tree/json/bnf-pair/rule-pair/string = concat("""", $t, """")) then
element id {element ID {$t}}
else
element STRING {concat('"', $t, '"')}
}
}
)
}
}
)
}
)
)
}
};
Loading

0 comments on commit 7a2101f

Please sign in to comment.