Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
preprocessor
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
Container registry
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dynare
preprocessor
Commits
3927862d
Verified
Commit
3927862d
authored
2 years ago
by
Sébastien Villemot
Browse files
Options
Downloads
Patches
Plain Diff
EquationTags: misc implementation improvements
parent
9658d82c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#7959
passed
2 years ago
Stage: build
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/EquationTags.cc
+21
-25
21 additions, 25 deletions
src/EquationTags.cc
src/EquationTags.hh
+7
-6
7 additions, 6 deletions
src/EquationTags.hh
with
28 additions
and
31 deletions
src/EquationTags.cc
+
21
−
25
View file @
3927862d
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
#include
<regex>
#include
<regex>
#include
<ostream>
#include
<ostream>
#include
<utility>
set
<
int
>
set
<
int
>
EquationTags
::
getEqnsByKey
(
const
string
&
key
)
const
EquationTags
::
getEqnsByKey
(
const
string
&
key
)
const
...
@@ -93,51 +94,46 @@ EquationTags::writeLatexOutput(ostream &output, int eqn) const
...
@@ -93,51 +94,46 @@ EquationTags::writeLatexOutput(ostream &output, int eqn) const
if
(
!
exists
(
eqn
))
if
(
!
exists
(
eqn
))
return
;
return
;
auto
escape_special_latex_symbols
auto
escape_special_latex_symbols
=
[](
string
str
)
=
[](
string
str
)
{
{
const
regex
special_latex_chars
(
R"([&%$#_{}])"
);
const
regex
special_latex_chars
(
R"([&%$#_{}])"
);
const
regex
backslash
(
R"(\\)"
);
const
regex
backslash
(
R"(\\)"
);
const
regex
tilde
(
R"(~)"
);
const
regex
tilde
(
R"(~)"
);
const
regex
carrot
(
R"(\^)"
);
const
regex
carrot
(
R"(\^)"
);
const
regex
textbackslash
(
R"(\\textbackslash)"
);
const
regex
textbackslash
(
R"(\\textbackslash)"
);
str
=
regex_replace
(
str
,
backslash
,
R"(\textbackslash)"
);
str
=
regex_replace
(
str
,
backslash
,
R"(\textbackslash)"
);
str
=
regex_replace
(
str
,
special_latex_chars
,
R"(\$&)"
);
str
=
regex_replace
(
str
,
special_latex_chars
,
R"(\$&)"
);
str
=
regex_replace
(
str
,
carrot
,
R"(\^{})"
);
str
=
regex_replace
(
str
,
carrot
,
R"(\^{})"
);
str
=
regex_replace
(
str
,
tilde
,
R"(\textasciitilde{})"
);
str
=
regex_replace
(
str
,
tilde
,
R"(\textasciitilde{})"
);
return
regex_replace
(
str
,
textbackslash
,
R"(\textbackslash{})"
);
return
regex_replace
(
str
,
textbackslash
,
R"(\textbackslash{})"
);
};
};
bool
wrote_eq_tag
=
false
;
output
<<
R"(\noindent[)"
;
output
<<
R"(\noindent[)"
;
for
(
const
auto
&
[
key
,
value
]
:
eqn_tags
.
at
(
eqn
))
for
(
bool
wrote_eq_tag
{
false
};
const
auto
&
[
key
,
value
]
:
eqn_tags
.
at
(
eqn
))
{
{
if
(
wrote_eq_tag
)
if
(
exchange
(
wrote_eq_tag
,
true
)
)
output
<<
", "
;
output
<<
", "
;
output
<<
escape_special_latex_symbols
(
key
);
output
<<
escape_special_latex_symbols
(
key
);
if
(
!
value
.
empty
())
if
(
!
value
.
empty
())
output
<<
"= `"
<<
escape_special_latex_symbols
(
value
)
<<
"'"
;
output
<<
"= `"
<<
escape_special_latex_symbols
(
value
)
<<
"'"
;
wrote_eq_tag
=
true
;
}
}
output
<<
"]"
<<
endl
;
output
<<
"]"
<<
endl
;
}
}
void
void
EquationTags
::
writeJsonAST
(
ostream
&
output
,
const
int
eqn
)
const
EquationTags
::
writeJsonAST
(
ostream
&
output
,
int
eqn
)
const
{
{
if
(
!
exists
(
eqn
))
if
(
!
exists
(
eqn
))
return
;
return
;
output
<<
R"(, "tags": {)"
;
output
<<
R"(, "tags": {)"
;
bool
wroteFirst
=
false
;
for
(
bool
wroteFirst
{
false
}
;
for
(
const
auto
&
[
key
,
value
]
:
eqn_tags
.
at
(
eqn
))
const
auto
&
[
key
,
value
]
:
eqn_tags
.
at
(
eqn
))
{
{
if
(
wroteFirst
)
if
(
exchange
(
wroteFirst
,
true
)
)
output
<<
", "
;
output
<<
", "
;
else
wroteFirst
=
true
;
output
<<
R"(")"
<<
key
<<
R"(": ")"
<<
value
<<
R"(")"
;
output
<<
R"(")"
<<
key
<<
R"(": ")"
<<
value
<<
R"(")"
;
}
}
output
<<
"}"
;
output
<<
"}"
;
...
...
This diff is collapsed.
Click to expand it.
src/EquationTags.hh
+
7
−
6
View file @
3927862d
...
@@ -63,11 +63,11 @@ public:
...
@@ -63,11 +63,11 @@ public:
//! Various functions to get info from equation tags
//! Various functions to get info from equation tags
//! Get equation tags for a given equation
//! Get equation tags for a given equation
map
<
string
,
string
>
map
<
string
,
string
>
getTagsByEqn
(
const
int
eqn
)
const
getTagsByEqn
(
int
eqn
)
const
{
{
if
(
auto
it
=
eqn_tags
.
find
(
eqn
);
it
!=
eqn_tags
.
end
())
if
(
auto
it
=
eqn_tags
.
find
(
eqn
);
it
!=
eqn_tags
.
end
())
return
it
->
second
;
return
it
->
second
;
return
map
<
string
,
string
>
{};
return
{};
}
}
//! Get equations that have the given key
//! Get equations that have the given key
...
@@ -104,23 +104,24 @@ public:
...
@@ -104,23 +104,24 @@ public:
}
}
bool
bool
exists
(
const
int
eqn
)
const
exists
(
int
eqn
)
const
{
{
return
eqn_tags
.
contains
(
eqn
);
return
eqn_tags
.
contains
(
eqn
);
}
}
//! Returns true if equation tag with key exists for a given equation
//! Returns true if equation tag with key exists for a given equation
bool
bool
exists
(
const
int
eqn
,
const
string
&
key
)
const
exists
(
int
eqn
,
const
string
&
key
)
const
{
{
return
exists
(
eqn
)
&&
eqn_tags
.
at
(
eqn
).
contains
(
key
);
auto
it
=
eqn_tags
.
find
(
eqn
);
return
it
!=
eqn_tags
.
end
()
&&
it
->
second
.
contains
(
key
);
}
}
//! Various functions to write equation tags
//! Various functions to write equation tags
void
writeCheckSumInfo
(
ostream
&
output
)
const
;
void
writeCheckSumInfo
(
ostream
&
output
)
const
;
void
writeOutput
(
ostream
&
output
)
const
;
void
writeOutput
(
ostream
&
output
)
const
;
void
writeLatexOutput
(
ostream
&
output
,
int
eqn
)
const
;
void
writeLatexOutput
(
ostream
&
output
,
int
eqn
)
const
;
void
writeJsonAST
(
ostream
&
output
,
const
int
eq
)
const
;
void
writeJsonAST
(
ostream
&
output
,
int
eq
)
const
;
};
};
#endif
#endif
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