Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Separate Core::Creator

  • Loading branch information...
commit ab0b02568dd5f30639fbd4bc9d526ab086f51aad 1 parent 76321b8
Vasily Chekalkin authored December 09, 2008
6  Makefile
... ...
@@ -1,10 +1,12 @@
1 1
 PARROT_DIR=/home/bacek/src/parrot
2 2
 RAKUDO=$(PARROT_DIR)/parrot $(PARROT_DIR)/languages/perl6/perl6.pbc
  3
+PERL6=$(PARROT_DIR)/languages/perl6/perl6
3 4
 
4 5
 SOURCES= \
5 6
 		 XQuery/Parser/Grammar.pm \
6 7
 		 XQuery/Parser.pm \
7 8
 		 XQuery/Core/Nodes.pm \
  9
+		 XQuery/Core/Creator.pm \
8 10
 		 XQuery/Core.pm \
9 11
 		 XQuery.pm \
10 12
 		 TestUtil.pm
@@ -13,12 +15,12 @@ PIRS=$(SOURCES:.pm=.pir)
13 15
 
14 16
 all: $(PIRS)
15 17
 
16  
-%.pir: %.pm
  18
+%.pir: %.pm $(PERL6)
17 19
 	$(PARROT_DIR)/parrot $(PARROT_DIR)/languages/perl6/perl6.pbc --target=pir $<  > $@
18 20
 
19 21
 clean:
20 22
 	rm -f $(PIRS)
21 23
 
22 24
 test: all
23  
-	prove -e $(PARROT_DIR)/languages/perl6/perl6 -r --timer t/
  25
+	prove -e $(PERL6) -r --timer t/
24 26
 	
61  XQuery/Core.pm
... ...
@@ -1,69 +1,12 @@
1 1
 use v6;
2  
-use XQuery::Core::Nodes;
  2
+use XQuery::Core::Creator;
3 3
 
4 4
 package XQuery::Core;
5 5
 
6  
-=begin pod
7  
-
8  
-Classical Visitor to create Core from AST
9  
-
10  
-=end pod
11  
-
12 6
 sub create($ast) {
13  
-    create_module($ast<Module>);
14  
-};
15  
-
16  
-sub create_module($module) {
17  
-    create_expr($module<MainModule><QueryBody><Expr>);
  7
+    XQuery::Core::Creator.new().create_module($ast<Module>);
18 8
 };
19 9
 
20  
-sub create_expr($expr, $pos = 0) {
21  
-    return unless $expr<ExprSingle>[$pos];
22  
-
23  
-    my $expr_single = $expr<ExprSingle>[$pos];
24  
-
25  
-    # recursivly process ExprSingle.
26  
-    create_expr_single($expr_single, create_expr($expr, ++$pos));
27  
-};
28 10
 
29  
-sub create_expr_single($ast, $left) {
30  
-=begin cut
31  
-# it doesn't work in Rakudo.
32  
-    given $ast {
33  
-        when .<FLWORExpr>      { create_flwor_expr($_, $left) }
34  
-        when .<QuantifiedExpr> { create_quantified_expr($_, $left) }
35  
-        when .<TypeswitchExpr> { create_typeswitch_expr($_, $left) }
36  
-        when .<IfExpr>         { create_if_expr($_, $left) }
37  
-        when .<OrExpr>         { create_or_expr($_, $left) }
38  
-    }
39  
-=end cut
40  
-    my &sub;
41  
-    if ($ast<FLWORExpr>) {
42  
-        return create_flwor_expr($ast<FLWORExpr>, $left);
43  
-    }
44  
-    elsif ( $ast<QuantifiedExpr>) {
45  
-        return create_quantified_expr($ast<QuantifiedExpr>, $left);
46  
-    }
47  
-    elsif ( $ast<TypeswitchExpr>) {
48  
-        return create_typeswitch_expr($ast<TypeswitchExpr>, $left);
49  
-    }
50  
-    elsif ( $ast<IfExpr>) {
51  
-        return create_if_expr($ast<IfExpr>, $left);
52  
-    }
53  
-    elsif ( $ast<OrExpr> ) {
54  
-        return create_or_expr($ast<OrExpr>, $left);
55  
-    }
56  
-
57  
-    die('holy shit');
58  
-};
59  
-
60  
-
61  
-
62  
-
63  
-sub create_or_expr($or, $left) {
64  
-    XQuery::Core::Literal.new(
65  
-        value => ~$or
66  
-    );
67  
-};
68 11
 
69 12
 # vim: ft=perl6
68  XQuery/Core/Creator.pm
... ...
@@ -0,0 +1,68 @@
  1
+use v6;
  2
+use XQuery::Core::Nodes;
  3
+
  4
+=begin pod
  5
+
  6
+Classical Visitor to create Core from AST
  7
+
  8
+=end pod
  9
+
  10
+
  11
+class XQuery::Core::Creator {
  12
+
  13
+    method create_module($module) {
  14
+        self.create_expr($module<MainModule><QueryBody><Expr>);
  15
+    };
  16
+
  17
+    method create_expr($expr, $pos = 0) {
  18
+        return unless $expr<ExprSingle>[$pos];
  19
+
  20
+        my $expr_single = $expr<ExprSingle>[$pos];
  21
+
  22
+        # recursivly process ExprSingle.
  23
+        self.create_expr_single($expr_single, self.create_expr($expr, ++$pos));
  24
+    };
  25
+
  26
+    method create_expr_single($ast, $left) {
  27
+=begin cut
  28
+    # it doesn't work in Rakudo.
  29
+        given $ast {
  30
+            when .<FLWORExpr>      { create_flwor_expr($_, $left) }
  31
+            when .<QuantifiedExpr> { create_quantified_expr($_, $left) }
  32
+            when .<TypeswitchExpr> { create_typeswitch_expr($_, $left) }
  33
+            when .<IfExpr>         { create_if_expr($_, $left) }
  34
+            when .<OrExpr>         { create_or_expr($_, $left) }
  35
+        }
  36
+=end cut
  37
+        my &sub;
  38
+        if ($ast<FLWORExpr>) {
  39
+            return self.create_flwor_expr($ast<FLWORExpr>, $left);
  40
+        }
  41
+        elsif ( $ast<QuantifiedExpr>) {
  42
+            return self.create_quantified_expr($ast<QuantifiedExpr>, $left);
  43
+        }
  44
+        elsif ( $ast<TypeswitchExpr>) {
  45
+            return self.create_typeswitch_expr($ast<TypeswitchExpr>, $left);
  46
+        }
  47
+        elsif ( $ast<IfExpr>) {
  48
+            return self.create_if_expr($ast<IfExpr>, $left);
  49
+        }
  50
+        elsif ( $ast<OrExpr> ) {
  51
+            return self.create_or_expr($ast<OrExpr>, $left);
  52
+        }
  53
+
  54
+        die('holy shit');
  55
+    };
  56
+
  57
+
  58
+
  59
+
  60
+    method create_or_expr($or, $left) {
  61
+        XQuery::Core::Literal.new(
  62
+            value => ~$or
  63
+        );
  64
+    };
  65
+
  66
+}
  67
+
  68
+# vim: ft=perl6

0 notes on commit ab0b025

Please sign in to comment.
Something went wrong with that request. Please try again.