Skip to content

Commit

Permalink
Fixed asType for string and non-string case
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKlint committed Mar 14, 2024
1 parent 8703b41 commit 4a14564
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,15 @@ void collect(current: (Pattern) `type ( <Pattern symbol>, <Pattern definitions>
// ---- asType
void collect(current: (Pattern) `[ <Type tp> ] <Pattern p>`, Collector c){
c.fact(current, tp);
// TODO: explore why this gives undesired erors, e..g in lang::rascal::grammar::definition::Literals
//c.requireSubType(p, tp, error(p, "Pattern should be subtype of %t, found %t", tp, p));

// TODO: missing semantics [Type] <Pattern> where pattern is of a string type. The str will be parsed with the non-terminal.
// if it is another type, then it must be comparable and the [Type] is used to see if a downcast is possible using isSubTypeOf
// If pattern is of type string, the string will be parsed using the non-terminal tp.
// If the pattern has another type, then it must be a subtype of tp

c.require("asType", current, [tp, p], void(Solver s){
if(!isStrAType(s.getType(p))){
s.requireSubType(p, tp, error(p, "Pattern should be subtype of %t, found %t", tp, p));
}
});
collect(tp, c);
c.push(patternContainer, "asType");
collect(p, c);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
module lang::rascalcore::compile::Examples::Tst5


syntax Expr = "e";

syntax Expr =
right
( right postIncr: Expr "++"
| right postDecr: Expr "--"
)
> left
( left div: Expr "/" !>> [/] Expr
| left remain: Expr "%" Expr
)
;

syntax Expr =
castPrim: "(" "PrimType" ")" Expr
> left
( left div: Expr "/" !>> [/] Expr
| left remain: Expr "%" Expr
)
;


//import List;
//
Expand Down

0 comments on commit 4a14564

Please sign in to comment.