Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Proof Assistant with Solver
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
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Zhang, Jenny
Proof Assistant with Solver
Commits
741f5afb
Commit
741f5afb
authored
9 months ago
by
Jenny Zhang
Browse files
Options
Downloads
Patches
Plain Diff
finished astsToString function with tests
parent
0b43b9b0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/utils/ast.js
+16
-0
16 additions, 0 deletions
src/utils/ast.js
tests/unit/ast.test.js
+16
-1
16 additions, 1 deletion
tests/unit/ast.test.js
with
32 additions
and
1 deletion
src/utils/ast.js
+
16
−
0
View file @
741f5afb
...
@@ -20,6 +20,21 @@ const precedence = {
...
@@ -20,6 +20,21 @@ const precedence = {
'
false
'
:
5
'
false
'
:
5
};
};
function
astsToString
(
nodes
){
const
leftList
=
nodes
[
0
];
const
rightList
=
nodes
[
1
];
if
(
leftList
.
length
>
0
)
{
const
leftFormulas
=
leftList
.
map
(
ast
=>
astToString
(
ast
)).
join
(
"
,
"
);
const
rightFormulas
=
rightList
.
map
(
ast
=>
astToString
(
ast
)).
join
(
"
,
"
);
return
`
${
leftFormulas
}
|-
${
rightFormulas
}
`
;
}
const
rightFormulas
=
rightList
.
map
(
ast
=>
astToString
(
ast
)).
join
(
"
,
"
);
return
`|-
${
rightFormulas
}
`
;
}
function
astToString
(
node
,
parentPrecedence
=
0
)
{
function
astToString
(
node
,
parentPrecedence
=
0
)
{
if
(
!
node
)
return
""
;
if
(
!
node
)
return
""
;
...
@@ -134,5 +149,6 @@ ast.False = Node.bind(null, 'false');
...
@@ -134,5 +149,6 @@ ast.False = Node.bind(null, 'false');
ast
.
astToString
=
astToString
;
ast
.
astToString
=
astToString
;
ast
.
astToLaTeX
=
astToLaTeX
;
ast
.
astToLaTeX
=
astToLaTeX
;
ast
.
astsToLateX
=
astsToLateX
;
ast
.
astsToLateX
=
astsToLateX
;
ast
.
astsToString
=
astsToString
;
module
.
exports
=
ast
;
// Export the AST module
module
.
exports
=
ast
;
// Export the AST module
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests/unit/ast.test.js
+
16
−
1
View file @
741f5afb
...
@@ -106,6 +106,21 @@ test('astToString could work correctly for complex expression', () => {
...
@@ -106,6 +106,21 @@ test('astToString could work correctly for complex expression', () => {
expect
(
output
).
toEqual
(
inputString
);
expect
(
output
).
toEqual
(
inputString
);
});
});
// astsToString test for sequent
test
(
'
astsToLateX could work correctly for complex expression
'
,
()
=>
{
const
inputString
=
"
|-!(A->B||C&D)
"
;
const
input
=
parse
(
inputString
);
const
output
=
ast
.
astsToString
(
input
);
expect
(
output
).
toEqual
(
inputString
);
});
test
(
'
astsToLateX could work correctly for complex expression
'
,
()
=>
{
const
inputString
=
"
A,B|-X&(Y->Z),C
"
;
const
input
=
parse
(
inputString
);
const
output
=
ast
.
astsToString
(
input
);
expect
(
output
).
toEqual
(
inputString
);
});
// astToLaTeX test for expression
// astToLaTeX test for expression
test
(
'
astToLaTeX could work correctly for and expression
'
,
()
=>
{
test
(
'
astToLaTeX could work correctly for and expression
'
,
()
=>
{
const
inputString
=
"
A & B
"
;
const
inputString
=
"
A & B
"
;
...
@@ -156,7 +171,7 @@ test('astToLaTeX could work correctly for complex expression', () => {
...
@@ -156,7 +171,7 @@ test('astToLaTeX could work correctly for complex expression', () => {
expect
(
output
).
toEqual
(
"
\\
mathit{X}
\\
land (
\\
mathit{Y}
\\
rightarrow
\\
mathit{Z})
"
);
expect
(
output
).
toEqual
(
"
\\
mathit{X}
\\
land (
\\
mathit{Y}
\\
rightarrow
\\
mathit{Z})
"
);
});
});
// astsToLateX test
// astsToLateX test
for sequent
test
(
'
astsToLateX could work correctly for complex expression
'
,
()
=>
{
test
(
'
astsToLateX could work correctly for complex expression
'
,
()
=>
{
const
inputString
=
"
|- X & (Y -> Z)
"
;
const
inputString
=
"
|- X & (Y -> Z)
"
;
const
input
=
parse
(
inputString
);
const
input
=
parse
(
inputString
);
...
...
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