Skip to content

Commit

Permalink
added support for identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Nov 29, 2023
1 parent ab24736 commit d1d5f45
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/org/rascalmpl/library/util/Explode.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,26 @@ import Node;

@synopsis{Turn an AST into a ParseTree, while preserving the name of the type.}
syntax[&T] explode(data[&T] ast) {
assert ast.src?;
assert readFile(ast.src.top) == readFile(ast.src);
assert astNodeSpecification(ast);
assert ast.src?;
assert readFile(ast.src.top) == readFile(ast.src);
assert astNodeSpecification(ast);

return explode(typeOf(ast), ast, readFile(ast.src.top), ast.src.offset, ast.src.length);
if (syntax[&T] r := explode(typeOf(ast), ast, readFile(ast.src.top), ast.src.offset, ast.src.length)) {
return r;
}

throw "unexpected problem while exploding <ast>";
}

Tree explode(data[&T] ast:str label(str identifier), str contents, int offset, int length) {
return appl(prod(lex("identifier"),[\iter-star(\char-class([range(1,1114111)])],{}),
[
appl(regular(\iter-star(\char-class([range(1,1114111)]))),
[char(ch) | ch <- chars(contents[offset..offset+length])])
]);
}

syntax[&T] explode(data[&T] ast, str contents, int offset, int length) {
default Tree explode(data[&T] ast, str contents, int offset, int length) {
children = getChildren(ast);

// here we generate a quasi syntax rule that has the structure and the types
Expand All @@ -69,13 +81,16 @@ syntax[&T] explode(data[&T] ast, str contents, int offset, int length) {
return r;
}
else {
throw "unexpected problem while exploding <ast>";

}
}

Tree separatorTree(str contents, int \start, int end)
= appl(prod(layouts("separators"),[\iter-star(\char-class([range(1,1114111)])],{}),
[char(ch) | int ch <- chars(contents[\start..end]]))
[
appl(regular(\iter-star(\char-class([range(1,1114111)]))),
[char(ch) | int ch <- chars(contents[\start..end]])
]);

Symbol \syntax(str()) = \lex("*identifiers*");
Symbol \syntax(\list(Symbol s)) = \iter-star(\syntax(s));

0 comments on commit d1d5f45

Please sign in to comment.