[vala/switch-to-gir: 25/34] girparser: Support regex in name argument
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/switch-to-gir: 25/34] girparser: Support regex in name argument
- Date: Sun, 29 Aug 2010 22:24:56 +0000 (UTC)
commit 0a5682c97a245a839130a70a69f8a461fa20c8cc
Author: Luca Bruno <lucabru src gnome org>
Date: Sun Aug 29 15:18:50 2010 +0200
girparser: Support regex in name argument
vala/valagirparser.vala | 32 ++++++++++++++++++++++++++++----
1 files changed, 28 insertions(+), 4 deletions(-)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 47c1014..1973e8b 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -1103,6 +1103,30 @@ public class Vala.GirParser : CodeVisitor {
return type;
}
+ string? element_get_name (string attribute_name = "name", ArgumentType arg_type = ArgumentType.NAME) {
+ var name = reader.get_attribute (attribute_name);
+ var pattern = metadata.get_string (arg_type);
+ if (pattern != null) {
+ try {
+ var regex = new Regex (pattern, RegexCompileFlags.ANCHORED, RegexMatchFlags.ANCHORED);
+ GLib.MatchInfo match;
+ if (!regex.match (name, 0, out match)) {
+ name = pattern;
+ } else {
+ var matched = match.fetch (1);
+ if (matched != null && matched.length > 0) {
+ name = matched;
+ } else {
+ name = pattern;
+ }
+ }
+ } catch (Error e) {
+ name = pattern;
+ }
+ }
+ return name;
+ }
+
void parse_repository () {
start_element ("repository");
next ();
@@ -1761,7 +1785,7 @@ public class Vala.GirParser : CodeVisitor {
Interface parse_interface () {
start_element ("interface");
- var iface = new Interface (reader.get_attribute ("name"), get_current_src ());
+ var iface = new Interface (element_get_name (), get_current_src ());
iface.access = SymbolAccessibility.PUBLIC;
iface.external = true;
@@ -1935,7 +1959,7 @@ public class Vala.GirParser : CodeVisitor {
Method parse_constructor (string? parent_ctype = null) {
start_element ("constructor");
- string name = reader.get_attribute ("name");
+ string name = element_get_name ();
string throws_string = reader.get_attribute ("throws");
next ();
@@ -1996,7 +2020,7 @@ public class Vala.GirParser : CodeVisitor {
Symbol parse_function (string element_name) {
start_element (element_name);
- string name = reader.get_attribute ("name");
+ string name = element_get_name ();
string cname = reader.get_attribute ("c:identifier");
string throws_string = reader.get_attribute ("throws");
string invoker = reader.get_attribute ("invoker");
@@ -2296,7 +2320,7 @@ public class Vala.GirParser : CodeVisitor {
Constant parse_constant () {
start_element ("constant");
- string name = reader.get_attribute ("name");
+ string name = element_get_name ();
next ();
var type = parse_type ();
var c = new Constant (name, type, null, get_current_src ());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]