Skip to main content

module analysis::grammars::dramb::Util

rascal-0.40.17
drambiguity-0.3.5

Usage

import analysis::grammars::dramb::Util;

Source code

http://github.com/cwi-swat/drambiguity/blob/main/src/analysis/grammars/dramb/Util.rsc

Dependencies

import ParseTree;
import Grammar;
import Node;
import lang::rascal::grammar::definition::Regular;
import lang::rascal::format::Grammar;
import util::Maybe;
import util::Math;
import String;

function delabel

Symbol delabel(label(str _, Symbol s))

Symbol delabel(conditional(Symbol s, set[Condition] _))

default Symbol delabel(Symbol s)

function cast

&T cast(type[&T] c, value x)

function symbol

Symbol symbol(appl(prod(label(str _, Symbol s), _ , _), _))

Symbol symbol(appl(regular(Symbol s), _))

Symbol symbol(amb({Tree a, *Tree _}))

Symbol symbol(char(int i))

default Symbol symbol(appl(prod(Symbol s, _ , _), _))

function reparse

Tree reparse(type[Tree] grammar, Tree t)

Tree reparse(type[Tree] grammar, str x)

Tree reparse(type[Tree] grammar, Symbol s, str x)

function saveParse

Maybe[Tree] saveParse(type[Tree] grammar, str input)

function isChar

bool isChar(char(_))

default bool isChar(Tree _)

function isLayout

bool isLayout(appl(prod(layouts(_),_,_),_))

bool isLayout(appl(prod(label(_, layouts(_)),_,_),_))

default bool isLayout(Tree _)

function isLiteral

bool isLiteral(appl(prod(lit(_),_,_),_))

default bool isLiteral(Tree _)

function completeLocs

Tree completeLocs(Tree t:amb({Tree u,*_}))

Tree completeLocs(Tree t:amb({Tree u,*_}))

default Tree completeLocs(Tree t)

tuple[Tree, int] completeLocs(Tree t, loc parent, int offset)

function sorts

set[Symbol] sorts(type[&T <: Tree] grammar)

function ambNestingDepth

Compute the depth of amb clusters as they are nested on top of each other.

int ambNestingDepth(appl(_, list[Tree] args))

int ambNestingDepth(amb(set[Tree] alts))

int ambNestingDepth(cycle(_,_))

int ambNestingDepth(char(_))

This function uses @memo to avoid exponential running times. If ambiguity clusters are nested, then the size of the forest in memory is polynomial, even if an exponential number of trees are represented. The algorithm counts on the structural equality of nested clusters as they are reached via different paths of the parent clusters. If the number of elements in each cluster is bounded to 2 then this count will be linear in the size of the cluster in memory, which means its a polynomial in the length of the represented input string. Grammars with very long productions produce (much) longer running times.

function format

str format(Symbol s)

str format(Production p)

str format(type[Tree] grammar)