Skip to content

Commit

Permalink
$ -> `
Browse files Browse the repository at this point in the history
  • Loading branch information
Zef Hemel committed Mar 22, 2009
1 parent 56d9f5d commit 292c8e5
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 38 deletions.
2 changes: 1 addition & 1 deletion gelly.pil
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import gelly::rewrite
void main(Array<String> args) {
//evalInit();
String input = null;
//println(new Parser("<$bla> ha").acceptExp().toIndentedString(0));
//println(new Parser("<`bla> ha").acceptExp().toIndentedString(0));
//println(new Parser("<bla> ha").acceptExp().toIndentedString(0));
var s = new Strategy(new Map<String, StrategyDef>(), new Map<String, ClosureStrategyDef>(), new Map<String, Term>());
if(!s.evalString("import \"sugar.g\"")) {
Expand Down
2 changes: 1 addition & 1 deletion parser.pil
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class gel::Parser {

List<String> noWhitespaceOps = new List<String>(";", ",", ".");
List<Char> allOps = new List<Char>('!', '@', '#', '%', '^', '&', '*', '-', '+', '=', '|', '/', '\\', '<', '>', '.', '?');
Array<String> prefixOps = new Array<String>("+", "-", "*", "<", ">", "?", "!", ":", "$");
Array<String> prefixOps = new Array<String>("+", "-", "*", "<", ">", "?", "!", ":", "`", "$");


new(String text) {
Expand Down
20 changes: 10 additions & 10 deletions primitives.pil
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import "rewrite.pil"
import gel
import gelly::rewrite

Term gelly::rewrite::buildPattern = replaceMatchVar(new Parser("![ $t ]").acceptExp());
Term gelly::rewrite::matchPattern = replaceMatchVar(new Parser("?[ $t ]").acceptExp());
Term gelly::rewrite::importPattern = replaceMatchVar(new Parser("import $fn").acceptExp());
Term gelly::rewrite::seqPattern = replaceMatchVar(new Parser("$f1; $f2").acceptExp());
Term gelly::rewrite::leftChoicePattern = replaceMatchVar(new Parser("$f1 <+ $f2").acceptExp());
Term gelly::rewrite::strategyDefPattern = replaceMatchVar(new Parser("strategy $name ($strparam)[$valparam] { $steps }").acceptExp());
Term gelly::rewrite::strategyCallPattern = replaceMatchVar(new Parser("$name$($strparam)[$valparam]").acceptExp());
Term gelly::rewrite::strategyCallNoStrParamPattern = replaceMatchVar(new Parser("$name[$valparam]").acceptExp());
Term gelly::rewrite::strategyCallNoValParamPattern = replaceMatchVar(new Parser("$name($strparam)").acceptExp());
Term gelly::rewrite::strategyCallNoStrParamNoValParamPattern = replaceMatchVar(new Parser("$name").acceptExp());
Term gelly::rewrite::buildPattern = replaceMatchVar(new Parser("![ `t ]").acceptExp());
Term gelly::rewrite::matchPattern = replaceMatchVar(new Parser("?[ `t ]").acceptExp());
Term gelly::rewrite::importPattern = replaceMatchVar(new Parser("import `fn").acceptExp());
Term gelly::rewrite::seqPattern = replaceMatchVar(new Parser("`f1; `f2").acceptExp());
Term gelly::rewrite::leftChoicePattern = replaceMatchVar(new Parser("`f1 <+ `f2").acceptExp());
Term gelly::rewrite::strategyDefPattern = replaceMatchVar(new Parser("strategy `name (`strparam)[`valparam] { `steps }").acceptExp());
Term gelly::rewrite::strategyCallPattern = replaceMatchVar(new Parser("`name(`strparam)[`valparam]").acceptExp());
Term gelly::rewrite::strategyCallNoStrParamPattern = replaceMatchVar(new Parser("`name[`valparam]").acceptExp());
Term gelly::rewrite::strategyCallNoValParamPattern = replaceMatchVar(new Parser("`name(`strparam)").acceptExp());
Term gelly::rewrite::strategyCallNoStrParamNoValParamPattern = replaceMatchVar(new Parser("`name").acceptExp());

Array<Function2<Bool, Term, Strategy>> gelly::rewrite::primitiveConstructs = new Array<Function2<Bool, Term, Strategy>>(
Bool(Term t, Strategy i) { gelly::rewrite::prim::strategyCall(t, i) },
Expand Down
4 changes: 1 addition & 3 deletions rewrite.pil
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import gelly::utils
import gelly::rewrite

Term gelly::rewrite::replaceMatchVar(Term t) {
//if(t instanceof ConsTerm && t.as<ConsTerm>.constructor == "$" && t.as<ConsTerm>.type == 2 && t.as<ConsTerm>.children[0] instanceof ConsTerm && t.as<ConsTerm>.children[0].as<ConsTerm>.constructor == "$") {
if(t instanceof ConsTerm && t.as<ConsTerm>.constructor == "$" && t.as<ConsTerm>.type == 1) {
//return new MatchVarTerm(t.as<ConsTerm>.children[0].as<ConsTerm>.children[0].as<SymbolTerm>.symbol);
if(t instanceof ConsTerm && t.as<ConsTerm>.constructor == "`" && t.as<ConsTerm>.type == 1) {
return new MatchVarTerm(t.as<ConsTerm>.children[0].as<SymbolTerm>.symbol);
} else if(t instanceof ConsTerm) {
var t2 = t.as<ConsTerm>;
Expand Down
45 changes: 23 additions & 22 deletions sugar.g
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
import "simple.g";

// rule somerule : [ 1 * `e ] -> [ `e ]
strategy gelly-sugar-rule-def()[] {
?[ rule $name : [ $lh ] -> [ $rh ] ]
; ![ strategy $name()[] {
?[ $lh ]
; ![ $rh ]
?[ rule `name : [ `lh ] -> [ `rh ] ]
; ![ strategy `name()[] {
?[ `lh ]
; ![ `rh ]
}
]
};

strategy gelly-sugar-rule-where-def()[] {
?[ rule $name : [ $lh ] -> [ $rh ] where { $where } ]
; ![ strategy $name()[] {
?[ $lh ]
; where($where)
; ![ $rh ]
?[ rule `name : [ `lh ] -> [ `rh ] where { `where } ]
; ![ strategy `name()[] {
?[ `lh ]
; where(`where)
; ![ `rh ]
}
]
};

strategy gelly-sugar-strategy-simple()[] {
?[ strategy $name { $body } ]
; ![ strategy $name()[] { $body } ]
?[ strategy `name { `body } ]
; ![ strategy `name()[] { `body } ]
};

strategy gelly-sugar-strategy-application()[] {
?[ <$str> $t ]
; ![ $t; $str ]
?[ <`str> `t ]
; ![ `t; `str ]
};

strategy gelly-sugar-strategy-application2()[] {
?[ <($str)> $t ]
; ![ $t; $str ]
?[ <(`str)> `t ]
; ![ `t; `str ]
};

strategy gelly-sugar-binding()[] {
?[ $lhs := $rhs ]
; ![ $rhs; ?[ $lhs ] ]
?[ `lhs := `rhs ]
; ![ `rhs; ?[ `lhs ] ]
};

strategy main()[:p] {
?[ $t ]
; ![ $p ]
?[ `t ]
; ![ `p ]
; innermost(
gelly-sugar-rule-where-def
<+ gelly-sugar-rule-def
Expand All @@ -50,7 +51,7 @@ strategy main()[:p] {
<+ gelly-sugar-strategy-application
<+ gelly-sugar-strategy-application2
)
; ?[ $p2 ]
; ![ $t ]
; eval[ ![ $p2 ] ]
; ?[ `p2 ]
; ![ `t ]
; eval[ ![ `p2 ] ]
};
2 changes: 1 addition & 1 deletion test.g
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Simple test script
main[
rule bla-rule : [ 1 ] -> [ 2 ];
rule bla2rule : [ $x ] -> [ $x + 1 ] where { $y := $x };
rule bla2rule : [ `x ] -> [ `x + 1 ] where { `y := `x };
strategy whatever_id {
id; debug
};
Expand Down

0 comments on commit 292c8e5

Please sign in to comment.