summaryrefslogtreecommitdiffstats
path: root/src/Parse.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/Parse.vala')
-rw-r--r--src/Parse.vala58
1 files changed, 45 insertions, 13 deletions
diff --git a/src/Parse.vala b/src/Parse.vala
index 7cadd35..18741cc 100644
--- a/src/Parse.vala
+++ b/src/Parse.vala
@@ -1,11 +1,11 @@
namespace Eva {
- internal static Term? parse(string str) {
+ internal static Term? parse(string str, ref va_list va) {
string s = str.chomp();
if(s.length == 0)
return null;
- Term? ret = parse_term(ref s);
+ Term? ret = parse_term(ref s, ref va);
if(s.length != 0)
return null;
@@ -13,7 +13,7 @@ namespace Eva {
return ret;
}
- private static Term? parse_term(ref string str) {
+ private static Term? parse_term(ref string str, ref va_list va) {
str = str.chug();
unichar c = str.get_char();
@@ -33,10 +33,13 @@ namespace Eva {
return parse_binary(ref str);
}
else if(c == '{') {
- return parse_tuple(ref str);
+ return parse_tuple(ref str, ref va);
}
else if(c == '[') {
- return parse_list(ref str);
+ return parse_list(ref str, ref va);
+ }
+ else if(c == '~') {
+ return get_va(ref str, ref va);
}
else {
return null;
@@ -216,7 +219,7 @@ namespace Eva {
return ret;
}
- private static Term? parse_tuple(ref string str) {
+ private static Term? parse_tuple(ref string str, ref va_list va) {
Gee.ArrayList<Term> list = new Gee.ArrayList<Term>();
if(str.get_char() != '{')
@@ -243,7 +246,7 @@ namespace Eva {
}
str = s;
- Term t = parse_term(ref str);
+ Term t = parse_term(ref str, ref va);
if(t == null)
return null;
list.add(t);
@@ -271,15 +274,15 @@ namespace Eva {
return null;
}
- private static Term? parse_list(ref string str) {
+ private static Term? parse_list(ref string str, ref va_list va) {
if(str.get_char() != '[')
return null;
str = str.next_char();
- return parse_list_tail(ref str);
+ return parse_list_tail(ref str, ref va);
}
- private static Term? parse_list_tail(ref string str) {
+ private static Term? parse_list_tail(ref string str, ref va_list va) {
str = str.chug();
if(str.length == 0)
@@ -290,7 +293,7 @@ namespace Eva {
return List.empty;
}
- Term head = parse_term(ref str);
+ Term head = parse_term(ref str, ref va);
if(head == null)
return null;
@@ -304,9 +307,9 @@ namespace Eva {
case ']':
return new List(head);
case ',':
- return new List(head, parse_list_tail(ref str));
+ return new List(head, parse_list_tail(ref str, ref va));
case '|':
- Term ret = new List(head, parse_term(ref str));
+ Term ret = new List(head, parse_term(ref str, ref va));
str = str.chug();
if(str.length == 0 || str.get_char() != ']')
@@ -389,4 +392,33 @@ namespace Eva {
return null;
}
}
+
+ private static Term? get_va(ref string str, ref va_list va) {
+ if(str.get_char() != '~')
+ return null;
+
+ if(str.length < 2)
+ return null;
+
+ unichar c = str[1];
+ str = str.offset(2);
+
+ switch(c) {
+ case 'a':
+ return new Atom(va.arg<string>());
+ case 's':
+ return new String(va.arg<string>());
+ case 'i':
+ return new Int(va.arg<int>());
+ case 'l':
+ return new Int(va.arg<long>());
+ case 'u':
+ return new UInt(va.arg<ulong>());
+ case 'f':
+ case 'd':
+ return new Double(va.arg<double>());
+ default:
+ return null;
+ }
+ }
}