better traces & debug
This commit is contained in:
parent
019a875d79
commit
52db4f70a6
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
build/
|
||||
main
|
||||
|
|
|
@ -10,7 +10,7 @@ int main (string[] args)
|
|||
var done = false;
|
||||
|
||||
of.title ("Pluie Yaml Parser", Pluie.Yaml.VERSION, "a-sansara");
|
||||
|
||||
Pluie.Yaml.Scanner.DEBUG = true;
|
||||
var loader = new Yaml.Loader (path, true, true);
|
||||
if ((done = loader.done)) {
|
||||
Yaml.NodeRoot root = loader.get_nodes ();
|
||||
|
|
|
@ -188,20 +188,28 @@ public class Pluie.Yaml.BaseNode : Object, Pluie.Yaml.Node
|
|||
/**
|
||||
* get a presentation string of current Yaml.Node
|
||||
*/
|
||||
public string to_string (bool withIndent = true)
|
||||
public string to_string (bool indentFormat = true, bool withParent = false, bool withUuid = false, bool withIndent = false, bool withRefCount = false)
|
||||
{
|
||||
|
||||
return "%s%s%s%s%s%s%s".printf (
|
||||
this.node_type.is_root () ? "" : of.s_indent ((int8) (withIndent ? this.indent : 0)),
|
||||
of.c (ECHO.OPTION).s ("<"),
|
||||
return "%s%s%s%s%s%s%s%s".printf (
|
||||
this.node_type.is_root () ? "" : of.s_indent ((int8) (indentFormat ? this.indent : 0)),
|
||||
of.c (ECHO.OPTION).s ("["),
|
||||
of.c (ECHO.OPTION_SEP).s (this.node_type.infos ()),
|
||||
this.name != null ? " %s".printf (this.name)
|
||||
: (this.node_type.is_scalar () ? " %s".printf (this.data) : ""),
|
||||
"[%x]".printf (this.ref_count),
|
||||
this.parent == null ? "" : this.parent.name+"|"+this.indent.to_string(),
|
||||
//~ " (%d) ".printf (this.indent),
|
||||
of.c (ECHO.OPTION).s (">")/*,
|
||||
of.c (ECHO.DATE).s (" %s".printf(this.uuid))*/
|
||||
this.name != null && !this.node_type.is_scalar ()
|
||||
? of.c (ECHO.TIME).s (" %s".printf (this.name))
|
||||
: (
|
||||
this.node_type.is_scalar ()
|
||||
? of.c(ECHO.DATE).s (" %s".printf (this.data))
|
||||
: ""
|
||||
),
|
||||
withRefCount ? of.c (ECHO.COMMAND).s ("[%x]".printf (this.ref_count)) : "",
|
||||
!withParent || this.parent == null
|
||||
? ""
|
||||
: of.c (ECHO.SECTION).s (" "+this.parent.name)+(
|
||||
withIndent ? of.c (ECHO.NUM).s (" "+this.indent.to_string()) : ""
|
||||
),
|
||||
withUuid ? of.c (ECHO.COMMENT).s (" %s".printf(this.uuid[0:8]+"...")) : "",
|
||||
of.c (ECHO.OPTION).s ("]")
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,11 @@ public class Pluie.Yaml.Loader
|
|||
this.get_nodes ().display_childs ();
|
||||
of.state(true);
|
||||
}
|
||||
if (!this.done) {
|
||||
var evt = this.scanner.get_error_event ();
|
||||
of.error ("line %d (%s)".printf (evt.line, evt.data["error"]));
|
||||
this.displayFile (evt.line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,17 +56,43 @@ public class Pluie.Yaml.Loader
|
|||
/**
|
||||
* display original file
|
||||
*/
|
||||
public void displayFile ()
|
||||
public void displayFile (int errorLine = 0)
|
||||
{
|
||||
of.action ("Reading file", this.reader.path);
|
||||
of.action (errorLine == 0 ? "Reading file" : "Invalid Yaml File", this.reader.path);
|
||||
of.echo ();
|
||||
this.reader.rewind(new Io.StreamLineMark(0, 0));
|
||||
int line = 0;
|
||||
string? data = null;;
|
||||
while (this.reader.readable) {
|
||||
of.echo ("%s %s".printf (
|
||||
of.c (ECHO.DATE ).s ("%03d |".printf (this.reader.line)),
|
||||
of.c (ECHO.OPTION_SEP).s (this.reader.read ()))
|
||||
);
|
||||
line = this.reader.line + 1;
|
||||
data = this.reader.read ();
|
||||
if (errorLine > 0 && line > 0) {
|
||||
if (line < errorLine - 7) continue;
|
||||
else if (line == errorLine - 7) {
|
||||
of.echo ("%s%s%s".printf (
|
||||
of.c (ECHO.MICROTIME ).s (" %03d ".printf (line-1)),
|
||||
of.c (ECHO.DATE).s ("| "),
|
||||
of.c (ECHO.COMMAND).s ("... ")
|
||||
));
|
||||
}
|
||||
}
|
||||
of.echo ("%s%s%s".printf (
|
||||
of.c (ECHO.MICROTIME ).s (" %03d ".printf (line)),
|
||||
of.c (ECHO.DATE).s ("| "),
|
||||
errorLine > 0 && line == errorLine
|
||||
? of.c (ECHO.FAIL).s (data)
|
||||
: of.c (ECHO.COMMAND).s (data)
|
||||
), errorLine == 0 || line < errorLine);
|
||||
if (errorLine > 0 && line == errorLine) {
|
||||
int len = of.term_width - data.length - 13;
|
||||
stdout.printf (of.c (ECHO.FAIL).s (@" %$(len)s ".printf (" ")));
|
||||
of.echo (Color.off (), true);
|
||||
}
|
||||
if (errorLine > 0 && line > errorLine) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
of.echo ("EOF");
|
||||
of.state (true);
|
||||
of.echo (errorLine == 0 ? "EOF" : "");
|
||||
of.state (errorLine == 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,6 +77,6 @@ public interface Pluie.Yaml.Node : Object
|
|||
/**
|
||||
* get a presentation string of current Yaml.Node
|
||||
*/
|
||||
public abstract string to_string (bool withIndent = true);
|
||||
public abstract string to_string (bool indentFormat = true, bool withParent = false, bool withUuid = true, bool withIndent = false, bool withRefCount = true);
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ public class Pluie.Yaml.Processor
|
|||
/**
|
||||
* indicates if processing is sucess
|
||||
*/
|
||||
public bool done;
|
||||
public bool done;
|
||||
|
||||
/**
|
||||
* Events list
|
||||
|
@ -20,32 +20,37 @@ public class Pluie.Yaml.Processor
|
|||
/**
|
||||
* Anchor map
|
||||
*/
|
||||
Gee.HashMap<string, Yaml.Node> anchors { get; internal set; }
|
||||
Gee.HashMap<string, Yaml.Node> anchors { get; internal set; }
|
||||
|
||||
/**
|
||||
* Error event
|
||||
*/
|
||||
public Yaml.Event? error_event { get; internal set; }
|
||||
|
||||
/**
|
||||
* the root Yaml.Node
|
||||
*/
|
||||
public Yaml.Node root;
|
||||
public Yaml.Node root;
|
||||
|
||||
/**
|
||||
* current previous Yaml.Node
|
||||
*/
|
||||
Yaml.Node? prev_node;
|
||||
Yaml.Node? prev_node;
|
||||
|
||||
/**
|
||||
* current parent Yaml.Node
|
||||
*/
|
||||
Yaml.Node? parent_node;
|
||||
Yaml.Node? parent_node;
|
||||
|
||||
/**
|
||||
* current Yaml.Node
|
||||
*/
|
||||
Yaml.Node node;
|
||||
Yaml.Node node;
|
||||
|
||||
/**
|
||||
* previous indent
|
||||
*/
|
||||
int prev_indent;
|
||||
int prev_indent;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -138,9 +143,13 @@ public class Pluie.Yaml.Processor
|
|||
string? key = null;
|
||||
string? id = null;
|
||||
Yaml.Event? evt;
|
||||
of.action ("Processing events");
|
||||
if (Pluie.Yaml.Scanner.DEBUG) of.action ("Processing events");
|
||||
for (var has_next = it.next (); has_next; has_next = it.next ()) {
|
||||
evt = it.get ();
|
||||
if (evt.evtype.is_error ()) {
|
||||
error_event = evt;
|
||||
break;
|
||||
}
|
||||
if (evt.evtype.is_mapping_end () || evt.evtype.is_sequence_end ()) {
|
||||
indent -= 4;
|
||||
this.parent_node = this.prev_node.parent != this.root ? this.prev_node.parent.parent : this.root;
|
||||
|
@ -211,7 +220,7 @@ public class Pluie.Yaml.Processor
|
|||
change = false;
|
||||
}
|
||||
}
|
||||
this.done = this.root != null;
|
||||
this.done = error_event == null && this.root != null;
|
||||
return done;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ extern void yaml_parse_file(string srcPath, string destPath);
|
|||
*/
|
||||
public class Pluie.Yaml.Scanner
|
||||
{
|
||||
public static bool DEBUG = false;
|
||||
/**
|
||||
* Regex pattern use to find EVENT
|
||||
*/
|
||||
|
@ -95,6 +96,14 @@ public class Pluie.Yaml.Scanner
|
|||
return (this.processor.root as Yaml.NodeRoot);
|
||||
}
|
||||
|
||||
/**
|
||||
* return error Yaml Event
|
||||
*/
|
||||
public Yaml.Event? get_error_event ()
|
||||
{
|
||||
return this.processor.error_event;
|
||||
}
|
||||
|
||||
/**
|
||||
* scan specifiyed file generated throught yaml.c
|
||||
* @param optional file path to scan
|
||||
|
@ -110,14 +119,14 @@ public class Pluie.Yaml.Scanner
|
|||
}
|
||||
this.processor = new Yaml.Processor ();
|
||||
this.done = false;
|
||||
of.action ("Scanning events", path);
|
||||
if (Pluie.Yaml.Scanner.DEBUG) of.action ("Scanning events", path);
|
||||
while (this.reader.readable) {
|
||||
this.scan_event (this.reader.read ());
|
||||
}
|
||||
this.done = true;
|
||||
of.state (this.done);
|
||||
if (Pluie.Yaml.Scanner.DEBUG) of.state (this.done);
|
||||
this.done = this.done && this.processor.run ();
|
||||
of.state (this.done);
|
||||
if (Pluie.Yaml.Scanner.DEBUG) of.state (this.done);
|
||||
Dbg.out (Log.METHOD, "done:%d".printf ((int)done), Log.LINE, Log.FILE);
|
||||
return this.done;
|
||||
}
|
||||
|
|
|
@ -134,6 +134,14 @@ namespace Pluie
|
|||
return this == EVT.BLOCK_END;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return event is error event
|
||||
*/
|
||||
public bool is_error ()
|
||||
{
|
||||
return this == EVT.NONE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user