summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2010-07-11 09:23:21 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2010-07-11 09:23:21 +0200
commit21dd3cb9a40b6bef5dbea8534557c3d6c0eebed8 (patch)
treeb9e99adb277f406974986c1aa706ae0e49ab8936 /src
parent94de356834be40b1e14c85a016a2e0a9f1768053 (diff)
downloadeva-21dd3cb9a40b6bef5dbea8534557c3d6c0eebed8.tar
eva-21dd3cb9a40b6bef5dbea8534557c3d6c0eebed8.zip
Added format support to string parsing
Also worked around some Vala bugs...
Diffstat (limited to 'src')
-rw-r--r--src/Parse.vala58
-rw-r--r--src/Term.vala5
-rw-r--r--src/Tuple.vala2
3 files changed, 49 insertions, 16 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;
+ }
+ }
}
diff --git a/src/Term.vala b/src/Term.vala
index 273cfa2..9490af5 100644
--- a/src/Term.vala
+++ b/src/Term.vala
@@ -130,8 +130,9 @@ namespace Eva {
return new List(head, tail);
}
- public Term? parse(string str) {
- return Eva.parse(str);
+ public static Term? parse(string str, ...) {
+ va_list va = va_list();
+ return Eva.parse(str, ref va);
}
}
}
diff --git a/src/Tuple.vala b/src/Tuple.vala
index 097973f..7423bce 100644
--- a/src/Tuple.vala
+++ b/src/Tuple.vala
@@ -1,6 +1,6 @@
namespace Eva {
public class Tuple : Object, Term {
- private Term[] elements {get; set;}
+ private Term[] elements;
public Tuple(Term[] terms) {
elements = terms;