Skip to content
This repository
Browse code

Added parser support for vectors.

  • Loading branch information...
commit abcc9b0109f9968151efee62c1d37fe4dd8e3547 1 parent 5288f83
Troy Varney authored November 26, 2012

Showing 1 changed file with 18 additions and 1 deletion. Show diff stats Hide diff stats

  1. 19  crono/src/crono/Parser.jj
19  crono/src/crono/Parser.jj
@@ -19,6 +19,7 @@ import crono.type.CronoInteger;
19 19
 import crono.type.CronoString;
20 20
 import crono.type.CronoType;
21 21
 import crono.type.CronoTypeId;
  22
+import crono.type.CronoVector;
22 23
 import crono.type.Nil;
23 24
 import crono.type.Quote;
24 25
 import crono.type.Symbol;
@@ -52,12 +53,14 @@ TOKEN:
52 53
 {
53 54
     < LPAR : "(" >
54 55
   | < RPAR : ")" >
  56
+  | < RBRACKET : "]" >
  57
+  | < LBRACKET : "[" >
55 58
   | < INTEGER : ("-")? (["0"-"9"])+ >
56 59
   | < FLOAT : ("-")? (["0"-"9"])+ "." (["0"-"9"])+ >
57 60
   | < CHAR : "'" ([" "-"~"] | ("\\" ~["\n", "\r", "\t"])) "'" >
58 61
   | < STRING : "\"" ("\\" ~["\n"] | ~["\"", "\n"])* "\"" >
59 62
   | < TYPEID : ":" (["a"-"z","A"-"Z"] (["a"-"z","A"-"Z","-"])?)+ >
60  
-  | < SYMBOL : ["!"-"&", "*"-"/", ";"-"~"] (["!"-"'", "*"-"~"])* >
  63
+  | < SYMBOL : ["!"-"&", "*"-"/", ";"-"Z", "\\", "^"-"~"] (["!"-"'", "*"-"/", ";"-"Z", "\\", "^"-"~"])* >
61 64
   | < QUOTE : "'" >
62 65
 }
63 66
 
@@ -70,6 +73,8 @@ Atom atom():
70 73
 {
71 74
   Token n;
72 75
   Atom a;
  76
+  CronoType node;
  77
+  ArrayList<CronoType> types = new ArrayList<CronoType>();
73 78
 }
74 79
 {
75 80
     n = <INTEGER> {
@@ -90,6 +95,18 @@ Atom atom():
90 95
       }
91 96
       return new CronoCharacter(n.image);
92 97
     }
  98
+  | <LBRACKET> 
  99
+    (
  100
+      node = node() {
  101
+        types.add(node);
  102
+      }
  103
+    )* <RBRACKET> {
  104
+      if(types.size() > 0) {
  105
+        return new CronoVector(types.toArray(new CronoType[types.size()]));
  106
+      }else {
  107
+        return new CronoVector(1);
  108
+      }
  109
+    }
93 110
   | n = <TYPEID> {
94 111
       if(debug) {
95 112
         System.out.println("Parser: Saw <TYPEID>");

0 notes on commit abcc9b0

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