1+ //! Handles the debug logging.
2+ //!
3+ //! This is the logging that appears when activating the `debug` feature. Thanks
4+ //! to these logging, we can see a details call stack of the different functions
5+ //! of the parser.
6+
17#![ coverage( off) ]
28
39use core:: fmt;
410
11+ /// Struct that handles logging of debug messages.
12+ ///
13+ /// It implements a [`Print:custom_print`] method to display any message and
14+ /// helper messages for messages that are often used.
515pub struct Print ;
616
717impl Print {
8- pub fn push_leaf < T : fmt:: Display , U : fmt:: Display > ( leaf : & T , current : & U , kind : & str ) {
9- log_print ( & format ! ( "Pushing {leaf} as leaf in {kind} {current}" ) ) ;
18+ /// Log message with a custom message
19+ pub fn custom_print ( msg : & str ) {
20+ log_print ( msg) ;
1021 }
1122
12- pub fn push_leaf_in < T : fmt:: Display , U : fmt:: Display > (
13- leaf : & T ,
14- leaf_kind : & str ,
23+ /// Logs debug message when pushing in a node
24+ pub fn push_in_node < T : fmt:: Display , U : fmt:: Display > (
25+ pushed : & T ,
26+ pushed_kind : & str ,
1527 current : & U ,
16- current_kind : & str ,
1728 ) {
18- log_print ( & format ! ( "Pushing {leaf_kind } {leaf} as leaf in {current_kind} {current}" ) ) ;
29+ log_print ( & format ! ( "Pushing {pushed_kind } {pushed} in node {current}" ) ) ;
1930 }
2031
32+ /// Logs debug message when pushing in a vec
2133 pub fn push_in_vec < T : fmt:: Display , U : fmt:: Display > (
2234 leaf : & T ,
23- current : & Vec < U > ,
35+ current : & [ U ] ,
2436 current_kind : & str ,
2537 ) {
2638 log_print ( & format ! (
@@ -33,23 +45,34 @@ impl Print {
3345 ) ) ;
3446 }
3547
36- pub fn push_op < T : fmt:: Display , U : fmt:: Display > ( op : & T , current : & U , current_kind : & str ) {
37- log_print ( & format ! ( "Pushing op {op} in {current_kind} {current}" ) ) ;
48+ /// Logs debug message when pushing a node as leaf
49+ pub fn push_leaf < T : fmt:: Display , U : fmt:: Display > ( leaf : & T , current : & U , kind : & str ) {
50+ log_print ( & format ! ( "Pushing {leaf} as leaf in {kind} {current}" ) ) ;
3851 }
3952
40- pub fn push_in_node < T : fmt:: Display , U : fmt:: Display > (
41- pushed : & T ,
42- pushed_kind : & str ,
53+ /// Logs debug message when pushing a node as leaf, type information on the
54+ /// node to be pushed.
55+ pub fn push_leaf_in < T : fmt:: Display , U : fmt:: Display > (
56+ leaf : & T ,
57+ leaf_kind : & str ,
4358 current : & U ,
59+ current_kind : & str ,
4460 ) {
45- log_print ( & format ! ( "Pushing {pushed_kind } {pushed} in node {current}" ) ) ;
61+ log_print ( & format ! ( "Pushing {leaf_kind } {leaf} as leaf in {current_kind} {current}" ) ) ;
4662 }
4763
48- pub fn custom_print ( msg : & str ) {
49- log_print ( msg) ;
64+ /// Debug message for pushing an operator.
65+ pub fn push_op < T : fmt:: Display , U : fmt:: Display > ( op : & T , current : & U , current_kind : & str ) {
66+ log_print ( & format ! ( "Pushing op {op} in {current_kind} {current}" ) ) ;
5067 }
5168}
5269
70+ /// Main logger function to display the debug messages with the right colour and
71+ /// indentation.
72+ ///
73+ /// It is not meant to be used directly, only use a wrapper provided by the
74+ /// [`Print`] struct.
75+ #[ expect( clippy:: print_stdout, reason = "goal of lint" ) ]
5376fn log_print ( msg : & str ) {
5477 println ! ( "\t \x1b [38;5;240m{msg}\x1b [0m" ) ;
5578}
0 commit comments