Permalink
Browse files

Added parser support for vectors.

  • Loading branch information...
Troy Varney
Troy Varney committed Nov 27, 2012
1 parent 5288f83 commit abcc9b0109f9968151efee62c1d37fe4dd8e3547
Showing with 18 additions and 1 deletion.
  1. +18 −1 crono/src/crono/Parser.jj
View
@@ -19,6 +19,7 @@ import crono.type.CronoInteger;
import crono.type.CronoString;
import crono.type.CronoType;
import crono.type.CronoTypeId;
+import crono.type.CronoVector;
import crono.type.Nil;
import crono.type.Quote;
import crono.type.Symbol;
@@ -52,12 +53,14 @@ TOKEN:
{
< LPAR : "(" >
| < RPAR : ")" >
+ | < RBRACKET : "]" >
+ | < LBRACKET : "[" >
| < INTEGER : ("-")? (["0"-"9"])+ >
| < FLOAT : ("-")? (["0"-"9"])+ "." (["0"-"9"])+ >
| < CHAR : "'" ([" "-"~"] | ("\\" ~["\n", "\r", "\t"])) "'" >
| < STRING : "\"" ("\\" ~["\n"] | ~["\"", "\n"])* "\"" >
| < TYPEID : ":" (["a"-"z","A"-"Z"] (["a"-"z","A"-"Z","-"])?)+ >
- | < SYMBOL : ["!"-"&", "*"-"/", ";"-"~"] (["!"-"'", "*"-"~"])* >
+ | < SYMBOL : ["!"-"&", "*"-"/", ";"-"Z", "\\", "^"-"~"] (["!"-"'", "*"-"/", ";"-"Z", "\\", "^"-"~"])* >
| < QUOTE : "'" >
}
@@ -70,6 +73,8 @@ Atom atom():
{
Token n;
Atom a;
+ CronoType node;
+ ArrayList<CronoType> types = new ArrayList<CronoType>();
}
{
n = <INTEGER> {
@@ -90,6 +95,18 @@ Atom atom():
}
return new CronoCharacter(n.image);
}
+ | <LBRACKET>
+ (
+ node = node() {
+ types.add(node);
+ }
+ )* <RBRACKET> {
+ if(types.size() > 0) {
+ return new CronoVector(types.toArray(new CronoType[types.size()]));
+ }else {
+ return new CronoVector(1);
+ }
+ }
| n = <TYPEID> {
if(debug) {
System.out.println("Parser: Saw <TYPEID>");

0 comments on commit abcc9b0

Please sign in to comment.