update doc comment and code formatting

This commit is contained in:
a-Sansara 2018-07-31 22:06:14 +02:00
parent 62419bf3f7
commit 019a875d79
5 changed files with 65 additions and 57 deletions

View File

@ -3,8 +3,7 @@ using Gee;
using Pluie; using Pluie;
/** /**
* a class to read file line by line with convenient methods to rewind to specific lines * Yaml Event class
* using {@link Io.StreamLineMark}
*/ */
public class Pluie.Yaml.Event public class Pluie.Yaml.Event
{ {

View File

@ -3,8 +3,7 @@ using Gee;
using Pluie; using Pluie;
/** /**
* a tiny Yaml Parser whose purpose is not to comply with all yaml specifications but to parse yaml configuration files * a Yaml Loader class
* todo improve description of what is expected
*/ */
public class Pluie.Yaml.Loader public class Pluie.Yaml.Loader
{ {
@ -13,6 +12,9 @@ public class Pluie.Yaml.Loader
*/ */
Yaml.Scanner scanner { public get; internal set; } Yaml.Scanner scanner { public get; internal set; }
/**
* indicate if file has been sucessfully loaded
*/
public bool done { get; internal set; } public bool done { get; internal set; }
/** /**
@ -22,6 +24,8 @@ public class Pluie.Yaml.Loader
/** /**
* @param path the path of file to parse * @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 ) 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 () public Yaml.NodeRoot get_nodes ()
{ {
@ -45,7 +49,7 @@ public class Pluie.Yaml.Loader
} }
/** /**
* * display original file
*/ */
public void displayFile () public void displayFile ()
{ {

View File

@ -3,20 +3,19 @@ using Gee;
using Pluie; using Pluie;
/** /**
* a tiny Yaml Parser whose purpose is not to comply with all yaml specifications but to parse yaml configuration files * a class dealing with a sequence of yaml events and composing the Yaml Node Graph
* todo improve description of what is expected
*/ */
public class Pluie.Yaml.Processor public class Pluie.Yaml.Processor
{ {
/** /**
* indicate if file has been sucessfully parsed * indicates if processing is sucess
*/ */
public bool done; public bool done;
/** /**
* Events list * Events list
*/ */
public Gee.LinkedList<Yaml.Event> events { get; internal set; } public Gee.ArrayList<Yaml.Event> events { get; internal set; }
/** /**
* Anchor map * Anchor map
@ -53,12 +52,12 @@ public class Pluie.Yaml.Processor
*/ */
public Processor () public Processor ()
{ {
this.events = new Gee.LinkedList<Yaml.Event>(); this.events = new Gee.ArrayList<Yaml.Event>();
this.anchors = new Gee.HashMap<string, Yaml.Node>(); this.anchors = new Gee.HashMap<string, Yaml.Node>();
} }
/** /**
* * display the list of events generated via yaml.c
*/ */
public void read () public void read ()
{ {
@ -77,13 +76,14 @@ public class Pluie.Yaml.Processor
} }
stdout.printf (" }"); stdout.printf (" }");
} }
stdout.printf("]\n"); of.echo ("]\n");
} }
} }
/** /**
* * retriew the next Yaml Event
* @param the iterator
*/ */
private Yaml.Event? next_event (Iterator<Yaml.Event> it) private Yaml.Event? next_event (Iterator<Yaml.Event> 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<Yaml.Event> it) private Yaml.Event? get_value_key_event (Iterator<Yaml.Event> 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<Yaml.Event> it) private Yaml.Event? get_value_event (Iterator<Yaml.Event> it)
{ {
@ -121,7 +123,7 @@ public class Pluie.Yaml.Processor
} }
/** /**
* * processing the events list and generate the corresponding Yaml Nodes
*/ */
public bool run () public bool run ()
{ {

View File

@ -4,17 +4,37 @@ using Pluie;
extern void yaml_parse_file(string srcPath, string destPath); 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 * a Yaml scanner class dealing with libyaml to generate a list of Yaml.Event
* todo improve description of what is expected
*/ */
public class Pluie.Yaml.Scanner public class Pluie.Yaml.Scanner
{ {
/**
* Regex pattern use to find EVENT
*/
const string REG_EVENT = "^([0-9]+), ([0-9]+)(.*)$"; const string REG_EVENT = "^([0-9]+), ([0-9]+)(.*)$";
/**
* Regex pattern use to find EVENT VERSION
*/
const string REG_VERSION = "^, ([0-9]+), ([0-9]+)$"; const string REG_VERSION = "^, ([0-9]+), ([0-9]+)$";
/**
* Regex pattern use to find EVENT TAG
*/
const string REG_TAG = "^, \"([^\"]*)\", \"([^\"]*)\"$"; const string REG_TAG = "^, \"([^\"]*)\", \"([^\"]*)\"$";
/**
* Regex pattern use to find EVENT ERROR
*/
const string REG_ERROR = "^, \"([^\"]*)\"$"; const string REG_ERROR = "^, \"([^\"]*)\"$";
/**
* Regex pattern use to find EVENT SCALAR
*/
const string REG_SCALAR = "^, ([0-9]+), \"(.*)\"$"; const string REG_SCALAR = "^, ([0-9]+), \"(.*)\"$";
/**
* Regex pattern use to find EVENT ANCHOR
*/
const string REG_ANCHOR = "^, \"([^\"]*)\"$"; const string REG_ANCHOR = "^, \"([^\"]*)\"$";
/**
* Regex pattern use to find EVENT ALIAS
*/
const string REG_ALIAS = "^, \"([^\"]*)\"$"; const string REG_ALIAS = "^, \"([^\"]*)\"$";
/** /**
@ -43,27 +63,22 @@ public class Pluie.Yaml.Scanner
enum MIEVT_ERROR { NONE, DATA } 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; } 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 * Reader used to load content yaml file
*/ */
Io.Reader reader; 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) public Scanner (string path)
{ {
@ -73,7 +88,7 @@ public class Pluie.Yaml.Scanner
} }
/** /**
* * return resulting Yaml root node
*/ */
public Yaml.NodeRoot get_nodes () public Yaml.NodeRoot get_nodes ()
{ {
@ -81,13 +96,13 @@ public class Pluie.Yaml.Scanner
} }
/** /**
* parse a file related to specifiyed path * scan specifiyed file generated throught yaml.c
* @param path the path to parse * @param optional file path to scan
*/ */
public bool run (string? path = null) public bool run (string? path = null)
{ {
Dbg.in (Log.METHOD, "path:'%s'".printf (path), Log.LINE, Log.FILE); 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); this.reader.load (path);
} }
else { else {
@ -123,10 +138,9 @@ public class Pluie.Yaml.Scanner
data.set("major", mi.fetch (MIEVT_VERSION.MAJOR)); data.set("major", mi.fetch (MIEVT_VERSION.MAJOR));
data.set("minor", mi.fetch (MIEVT_VERSION.MINOR)); 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 * register event tag
* @param evtdata the current data event * @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("handle", mi.fetch (MIEVT_TAG.HANDLE));
data.set("suffix", mi.fetch (MIEVT_TAG.SUFFIX)); 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<string, string>(); data = new HashMap<string, string>();
data.set("error", mi.fetch (MIEVT_ERROR.DATA)); 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<string, string>(); data = new HashMap<string, string>();
data.set("data", mi.fetch (MIEVT_SCALAR.DATA)); 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<string, string>(); data = new HashMap<string, string>();
data.set("id", mi.fetch (MIEVT_ANCHOR.ID)); 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<string, string>(); data = new HashMap<string, string>();
data.set("id", mi.fetch (MIEVT_ANCHOR.ID)); 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 * @param data the current line
*/ */
private void scan_event (string? data = null) private void scan_event (string? data = null)
@ -257,7 +271,7 @@ public class Pluie.Yaml.Scanner
this.register_event_error(evtdata, line); this.register_event_error(evtdata, line);
break; break;
default : 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; break;
} }
} }

View File

@ -156,23 +156,12 @@ namespace Pluie
/** /**
* enum MatchInfo keys of Yaml.Mode.find method related to mode FIND_MODE.SQUARE_BRACKETS of Yaml.Node * enum MatchInfo keys of Yaml.Mode.find method related to mode FIND_MODE.SQUARE_BRACKETS of Yaml.Node
*/ */
internal enum FIND_COLLECTION internal enum FIND_COLLECTION { PATH, OPEN, KEY, CLOSE; }
{
PATH,
OPEN,
KEY,
CLOSE;
}
/** /**
* enum MatchInfo keys of Yaml.Node.find method related to mode FIND_MODE.DOT of Yaml.Node * enum MatchInfo keys of Yaml.Node.find method related to mode FIND_MODE.DOT of Yaml.Node
*/ */
internal enum FIND_DOT internal enum FIND_DOT { PATH, KEY, SEQUENCE; }
{
PATH,
KEY,
SEQUENCE;
}
/** /**
* enum possible type of Yaml.Node * enum possible type of Yaml.Node