diff --git a/src/vala/Pluie/Yaml.Event.vala b/src/vala/Pluie/Yaml.Event.vala index df9d2de..69045cd 100644 --- a/src/vala/Pluie/Yaml.Event.vala +++ b/src/vala/Pluie/Yaml.Event.vala @@ -3,8 +3,7 @@ using Gee; using Pluie; /** - * a class to read file line by line with convenient methods to rewind to specific lines - * using {@link Io.StreamLineMark} + * Yaml Event class */ public class Pluie.Yaml.Event { diff --git a/src/vala/Pluie/Yaml.Loader.vala b/src/vala/Pluie/Yaml.Loader.vala index b7e55cd..35b50ab 100644 --- a/src/vala/Pluie/Yaml.Loader.vala +++ b/src/vala/Pluie/Yaml.Loader.vala @@ -3,8 +3,7 @@ using Gee; using Pluie; /** - * a tiny Yaml Parser whose purpose is not to comply with all yaml specifications but to parse yaml configuration files - * todo improve description of what is expected + * a Yaml Loader class */ public class Pluie.Yaml.Loader { @@ -12,7 +11,10 @@ public class Pluie.Yaml.Loader * Scanner */ Yaml.Scanner scanner { public get; internal set; } - + + /** + * indicate if file has been sucessfully loaded + */ public bool done { get; internal set; } /** @@ -22,6 +24,8 @@ public class Pluie.Yaml.Loader /** * @param path the path of file to parse + * @param displayFile display original file + * @param displayNode display corresponding Yaml Node Graph */ public Loader (string path, bool displayFile = false, bool displayNode = false ) { @@ -37,7 +41,7 @@ public class Pluie.Yaml.Loader } /** - * + * return resulting Yaml root node */ public Yaml.NodeRoot get_nodes () { @@ -45,7 +49,7 @@ public class Pluie.Yaml.Loader } /** - * + * display original file */ public void displayFile () { diff --git a/src/vala/Pluie/Yaml.Processor.vala b/src/vala/Pluie/Yaml.Processor.vala index 099a0c7..9032f7c 100644 --- a/src/vala/Pluie/Yaml.Processor.vala +++ b/src/vala/Pluie/Yaml.Processor.vala @@ -3,23 +3,22 @@ using Gee; using Pluie; /** - * a tiny Yaml Parser whose purpose is not to comply with all yaml specifications but to parse yaml configuration files - * todo improve description of what is expected + * a class dealing with a sequence of yaml events and composing the Yaml Node Graph */ public class Pluie.Yaml.Processor { /** - * indicate if file has been sucessfully parsed + * indicates if processing is sucess */ public bool done; /** * Events list */ - public Gee.LinkedList events { get; internal set; } + public Gee.ArrayList events { get; internal set; } /** - *Anchor map + * Anchor map */ Gee.HashMap anchors { get; internal set; } @@ -53,12 +52,12 @@ public class Pluie.Yaml.Processor */ public Processor () { - this.events = new Gee.LinkedList(); + this.events = new Gee.ArrayList(); this.anchors = new Gee.HashMap(); } /** - * + * display the list of events generated via yaml.c */ public void read () { @@ -66,7 +65,7 @@ public class Pluie.Yaml.Processor EVT? prevEvent = null; foreach (Yaml.Event event in this.events) { int len = 24 - event.evtype.infos ().length; - stdout.printf(" [ %s"+@" %$(len)s "+", %d, %s", event.evtype.infos (), " ", event.line, event.style != null ? event.style.to_string () : "0"); + stdout.printf (" [ %s"+@" %$(len)s "+", %d, %s", event.evtype.infos (), " ", event.line, event.style != null ? event.style.to_string () : "0"); if (event.data != null && event.data.size > 0) { stdout.printf (", {"); var it = event.data.map_iterator (); @@ -77,13 +76,14 @@ public class Pluie.Yaml.Processor } stdout.printf (" }"); } - stdout.printf("]\n"); + of.echo ("]\n"); } } /** - * + * retriew the next Yaml Event + * @param the iterator */ private Yaml.Event? next_event (Iterator it) { @@ -95,7 +95,8 @@ public class Pluie.Yaml.Processor } /** - * + * retriew the next Yaml Value Event closest to Key Event + * @param the iterator */ private Yaml.Event? get_value_key_event (Iterator it) { @@ -108,7 +109,8 @@ public class Pluie.Yaml.Processor } /** - * + * retriew the next Yaml Value Event + * @param the iterator */ private Yaml.Event? get_value_event (Iterator it) { @@ -121,7 +123,7 @@ public class Pluie.Yaml.Processor } /** - * + * processing the events list and generate the corresponding Yaml Nodes */ public bool run () { diff --git a/src/vala/Pluie/Yaml.Scanner.vala b/src/vala/Pluie/Yaml.Scanner.vala index 91b2886..4ea98ee 100644 --- a/src/vala/Pluie/Yaml.Scanner.vala +++ b/src/vala/Pluie/Yaml.Scanner.vala @@ -4,17 +4,37 @@ using Pluie; extern void yaml_parse_file(string srcPath, string destPath); /** - * a tiny Yaml Parser whose purpose is not to comply with all yaml specifications but to parse yaml configuration files - * todo improve description of what is expected + * a Yaml scanner class dealing with libyaml to generate a list of Yaml.Event */ public class Pluie.Yaml.Scanner { + /** + * Regex pattern use to find EVENT + */ const string REG_EVENT = "^([0-9]+), ([0-9]+)(.*)$"; + /** + * Regex pattern use to find EVENT VERSION + */ const string REG_VERSION = "^, ([0-9]+), ([0-9]+)$"; + /** + * Regex pattern use to find EVENT TAG + */ const string REG_TAG = "^, \"([^\"]*)\", \"([^\"]*)\"$"; + /** + * Regex pattern use to find EVENT ERROR + */ const string REG_ERROR = "^, \"([^\"]*)\"$"; + /** + * Regex pattern use to find EVENT SCALAR + */ const string REG_SCALAR = "^, ([0-9]+), \"(.*)\"$"; + /** + * Regex pattern use to find EVENT ANCHOR + */ const string REG_ANCHOR = "^, \"([^\"]*)\"$"; + /** + * Regex pattern use to find EVENT ALIAS + */ const string REG_ALIAS = "^, \"([^\"]*)\"$"; /** @@ -43,27 +63,22 @@ public class Pluie.Yaml.Scanner enum MIEVT_ERROR { NONE, DATA } /** - * indicate if file has been sucessfully parsed + * indicate if file has been sucessfully scanned */ public bool done { get; internal set; } - /** - * the mark use to rewind line throught Io.Reader - */ - Io.StreamLineMark? mark; - /** * Reader used to load content yaml file */ Io.Reader reader; /** - * Yaml Processor + * Yaml Processor used to process events */ - Yaml.Processor processor { get; internal set; } + Yaml.Processor processor { get; internal set; } /** - * @param path the path of file to parse + * @param path the path of file to scan */ public Scanner (string path) { @@ -73,7 +88,7 @@ public class Pluie.Yaml.Scanner } /** - * + * return resulting Yaml root node */ public Yaml.NodeRoot get_nodes () { @@ -81,13 +96,13 @@ public class Pluie.Yaml.Scanner } /** - * parse a file related to specifiyed path - * @param path the path to parse + * scan specifiyed file generated throught yaml.c + * @param optional file path to scan */ public bool run (string? path = null) { Dbg.in (Log.METHOD, "path:'%s'".printf (path), Log.LINE, Log.FILE); - if (path != null) { + if (path != null && this.reader.path != path) { this.reader.load (path); } else { @@ -123,10 +138,9 @@ public class Pluie.Yaml.Scanner data.set("major", mi.fetch (MIEVT_VERSION.MAJOR)); data.set("minor", mi.fetch (MIEVT_VERSION.MINOR)); } - this.processor.events.offer(new Yaml.Event(EVT.VERSION_DIRECTIVE, line, null, data)); + this.processor.events.add(new Yaml.Event(EVT.VERSION_DIRECTIVE, line, null, data)); } - /** * register event tag * @param evtdata the current data event @@ -143,7 +157,7 @@ public class Pluie.Yaml.Scanner data.set("handle", mi.fetch (MIEVT_TAG.HANDLE)); data.set("suffix", mi.fetch (MIEVT_TAG.SUFFIX)); } - this.processor.events.offer(new Yaml.Event(EVT.TAG, line, null, data)); + this.processor.events.add(new Yaml.Event(EVT.TAG, line, null, data)); } /** @@ -161,7 +175,7 @@ public class Pluie.Yaml.Scanner data = new HashMap(); data.set("error", mi.fetch (MIEVT_ERROR.DATA)); } - this.processor.events.offer(new Yaml.Event(EVT.NONE, line, null, data)); + this.processor.events.add(new Yaml.Event(EVT.NONE, line, null, data)); } /** @@ -181,7 +195,7 @@ public class Pluie.Yaml.Scanner data = new HashMap(); data.set("data", mi.fetch (MIEVT_SCALAR.DATA)); } - this.processor.events.offer(new Yaml.Event(EVT.SCALAR, line, style, data)); + this.processor.events.add(new Yaml.Event(EVT.SCALAR, line, style, data)); } /** @@ -199,7 +213,7 @@ public class Pluie.Yaml.Scanner data = new HashMap(); data.set("id", mi.fetch (MIEVT_ANCHOR.ID)); } - this.processor.events.offer(new Yaml.Event(EVT.ANCHOR, line, null, data)); + this.processor.events.add(new Yaml.Event(EVT.ANCHOR, line, null, data)); } /** @@ -217,11 +231,11 @@ public class Pluie.Yaml.Scanner data = new HashMap(); data.set("id", mi.fetch (MIEVT_ANCHOR.ID)); } - this.processor.events.offer(new Yaml.Event(EVT.ALIAS, line, null, data)); + this.processor.events.add(new Yaml.Event(EVT.ALIAS, line, null, data)); } /** - * parse specifiyed line + * scan specifiyed line * @param data the current line */ private void scan_event (string? data = null) @@ -257,7 +271,7 @@ public class Pluie.Yaml.Scanner this.register_event_error(evtdata, line); break; default : - this.processor.events.offer(new Yaml.Event((Yaml.EVT)type, line, null, null)); + this.processor.events.add(new Yaml.Event((Yaml.EVT)type, line, null, null)); break; } } diff --git a/src/vala/Pluie/Yaml.global.vala b/src/vala/Pluie/Yaml.global.vala index f81313a..409ae65 100644 --- a/src/vala/Pluie/Yaml.global.vala +++ b/src/vala/Pluie/Yaml.global.vala @@ -156,23 +156,12 @@ namespace Pluie /** * enum MatchInfo keys of Yaml.Mode.find method related to mode FIND_MODE.SQUARE_BRACKETS of Yaml.Node */ - internal enum FIND_COLLECTION - { - PATH, - OPEN, - KEY, - CLOSE; - } + internal enum FIND_COLLECTION { PATH, OPEN, KEY, CLOSE; } /** * enum MatchInfo keys of Yaml.Node.find method related to mode FIND_MODE.DOT of Yaml.Node */ - internal enum FIND_DOT - { - PATH, - KEY, - SEQUENCE; - } + internal enum FIND_DOT { PATH, KEY, SEQUENCE; } /** * enum possible type of Yaml.Node