Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
145e2d9e
Commit
145e2d9e
authored
Jul 2, 2019
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Improve output of AST
now one can select some details (useful for unit tests)
parent
840ec759
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!37
Feature/language
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/language/ASTPrinter.cpp
+36
-16
36 additions, 16 deletions
src/language/ASTPrinter.cpp
src/language/ASTPrinter.hpp
+15
-1
15 additions, 1 deletion
src/language/ASTPrinter.hpp
src/language/PugsParser.cpp
+1
-1
1 addition, 1 deletion
src/language/PugsParser.cpp
with
52 additions
and
18 deletions
src/language/ASTPrinter.cpp
+
36
−
16
View file @
145e2d9e
#include
<ASTPrinter.hpp>
#include
<ASTPrinter.hpp>
#include
<EscapedString.hpp>
#include
<EscapedString.hpp>
#include
<PEGGrammar.hpp>
namespace
language
namespace
language
{
{
void
void
...
@@ -12,9 +14,20 @@ ASTPrinter::_print(std::ostream& os, const Node& node) const
...
@@ -12,9 +14,20 @@ ASTPrinter::_print(std::ostream& os, const Node& node) const
}
else
{
}
else
{
os
<<
node
.
name
();
os
<<
node
.
name
();
}
}
os
<<
rang
::
fg
::
reset
<<
':'
;
os
<<
rang
::
fg
::
reset
;
os
<<
dataTypeName
(
node
.
m_data_type
)
<<
':'
;
if
(
node
.
is
<
language
::
name
>
()
or
node
.
is
<
language
::
literal
>
()
or
node
.
is
<
language
::
integer
>
()
or
node
.
is
<
language
::
real
>
())
{
os
<<
':'
<<
rang
::
fgB
::
green
<<
node
.
string
()
<<
rang
::
fg
::
reset
;
}
if
(
m_info
&
static_cast
<
InfoBaseType
>
(
Info
::
data_type
))
{
os
<<
':'
;
os
<<
dataTypeName
(
node
.
m_data_type
)
<<
rang
::
fg
::
reset
;
}
if
(
m_info
&
static_cast
<
InfoBaseType
>
(
Info
::
data_value
))
{
os
<<
':'
;
os
<<
rang
::
fgB
::
cyan
;
os
<<
rang
::
fgB
::
cyan
;
std
::
visit
(
std
::
visit
(
[
&
](
const
auto
&
value
)
{
[
&
](
const
auto
&
value
)
{
...
@@ -28,6 +41,7 @@ ASTPrinter::_print(std::ostream& os, const Node& node) const
...
@@ -28,6 +41,7 @@ ASTPrinter::_print(std::ostream& os, const Node& node) const
}
}
},
},
node
.
m_value
);
node
.
m_value
);
}
os
<<
rang
::
fg
::
reset
<<
")
\n
"
;
os
<<
rang
::
fg
::
reset
<<
")
\n
"
;
if
(
not
node
.
children
.
empty
())
{
if
(
not
node
.
children
.
empty
())
{
...
@@ -71,7 +85,8 @@ operator<<(std::ostream& os, const ASTPrinter& ast_printer)
...
@@ -71,7 +85,8 @@ operator<<(std::ostream& os, const ASTPrinter& ast_printer)
return
os
;
return
os
;
}
}
ASTPrinter
::
ASTPrinter
(
const
language
::
Node
&
node
,
Format
format
)
:
m_node
{
node
}
ASTPrinter
::
ASTPrinter
(
const
language
::
Node
&
node
,
Format
format
,
std
::
initializer_list
<
Info
>
initializer_list
)
:
m_node
{
node
}
{
{
if
(
format
==
Format
::
pretty
)
{
if
(
format
==
Format
::
pretty
)
{
T_junction
=
" \u251c\u2500\u2500"
;
T_junction
=
" \u251c\u2500\u2500"
;
...
@@ -85,5 +100,10 @@ ASTPrinter::ASTPrinter(const language::Node& node, Format format) : m_node{node}
...
@@ -85,5 +100,10 @@ ASTPrinter::ASTPrinter(const language::Node& node, Format format) : m_node{node}
pipe_space
=
" | "
;
pipe_space
=
" | "
;
space_space
=
" "
;
space_space
=
" "
;
}
}
m_info
=
0
;
for
(
auto
i
:
initializer_list
)
{
m_info
|=
static_cast
<
InfoBaseType
>
(
i
);
}
}
}
}
// namespace language
}
// namespace language
This diff is collapsed.
Click to expand it.
src/language/ASTPrinter.hpp
+
15
−
1
View file @
145e2d9e
...
@@ -14,9 +14,21 @@ class ASTPrinter
...
@@ -14,9 +14,21 @@ class ASTPrinter
pretty
pretty
};
};
using
InfoBaseType
=
uint32_t
;
enum
class
Info
:
InfoBaseType
{
none
=
0
,
data_type
=
1
<<
0
,
data_value
=
1
<<
1
,
all
=
std
::
numeric_limits
<
InfoBaseType
>::
max
()
};
private
:
private
:
const
Node
&
m_node
;
const
Node
&
m_node
;
InfoBaseType
m_info
;
mutable
std
::
string
prefix
;
mutable
std
::
string
prefix
;
mutable
std
::
vector
<
int
>
last_prefix_size
;
mutable
std
::
vector
<
int
>
last_prefix_size
;
...
@@ -34,7 +46,9 @@ class ASTPrinter
...
@@ -34,7 +46,9 @@ class ASTPrinter
public
:
public
:
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
ASTPrinter
&
ast_printer
);
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
ASTPrinter
&
ast_printer
);
ASTPrinter
(
const
Node
&
node
,
Format
format
=
Format
::
pretty
);
ASTPrinter
(
const
Node
&
node
,
Format
format
=
Format
::
pretty
,
std
::
initializer_list
<
Info
>
initializer_list
=
{
Info
::
all
});
ASTPrinter
(
const
ASTPrinter
&
)
=
delete
;
ASTPrinter
(
const
ASTPrinter
&
)
=
delete
;
...
...
This diff is collapsed.
Click to expand it.
src/language/PugsParser.cpp
+
1
−
1
View file @
145e2d9e
...
@@ -484,7 +484,7 @@ parser(const std::string& filename)
...
@@ -484,7 +484,7 @@ parser(const std::string& filename)
language
::
build_node_type
(
*
root_node
);
language
::
build_node_type
(
*
root_node
);
std
::
cout
<<
language
::
ASTPrinter
{
*
root_node
,
language
::
ASTPrinter
::
Format
::
raw
}
<<
'\n'
;
std
::
cout
<<
language
::
ASTPrinter
{
*
root_node
}
<<
'\n'
;
language
::
ExecUntilBreakOrContinue
exec_all
;
language
::
ExecUntilBreakOrContinue
exec_all
;
root_node
->
execute
(
exec_all
);
root_node
->
execute
(
exec_all
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment