FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
note/src/runtime/ReplyCellRunner.cpp at dev · vixcpp/note · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
vixcpp
/
note
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
note
/
src
/
runtime
/
ReplyCellRunner.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
190 lines (157 loc) · 4.12 KB
Breadcrumbs
note
/
src
/
runtime
/
ReplyCellRunner.cpp
Copy path
File metadata and controls
190 lines (157 loc) · 4.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
*
*
* @file ReplyCellRunner.cpp
* @author Gaspard Kirira
*
* Copyright 2026, Gaspard Kirira.
* All rights reserved.
* https://github.com/vixcpp/note
*
* Use of this source code is governed by a MIT license
* that can be found in the LICENSE file.
*
* Vix Note
*
*/
#
include
<
vix/note/runtime/ReplyCellRunner.hpp
>
#
include
<
string
>
#
include
<
utility
>
namespace
vix
::note
{
namespace
{
std::string
strip_reply_line_comments
(
const
std::string &source)
{
std::string normalized;
normalized.
reserve
(source.
size
());
bool
inString =
false
;
bool
escaped =
false
;
for
(std::
size_t
index =
0
; index < source.
size
(); ++index)
{
const
char
current = source[index];
if
(inString)
{
normalized += current;
if
(escaped)
{
escaped =
false
;
}
else
if
(current ==
'
\\
'
)
{
escaped =
true
;
}
else
if
(current ==
'
"
'
)
{
inString =
false
;
}
continue
;
}
if
(current ==
'
"
'
)
{
inString =
true
;
normalized += current;
continue
;
}
if
(current ==
'
/
'
&& index +
1
< source.
size
() && source[index +
1
] ==
'
/
'
)
{
while
(index < source.
size
() && source[index] !=
'
\n
'
)
{
++index;
}
if
(index < source.
size
())
{
normalized +=
'
\n
'
;
}
continue
;
}
normalized += current;
}
return
normalized;
}
void
add_reply_outputs
(
NoteResult &result,
const
ReplyCellRunnerOptions &options,
const
vix::reply::ReplyRunResult &replyResult)
{
if
(!replyResult.
stdoutText
.
empty
())
{
result.
add_stdout
(replyResult.
stdoutText
);
}
if
(!replyResult.
stderrText
.
empty
())
{
result.
add_stderr
(replyResult.
stderrText
);
}
if
(!replyResult.
errorText
.
empty
())
{
result.
add_error
(replyResult.
errorText
);
}
if
(options.
debugMode
)
{
result.
add_debug
(
"
duration_ms=
"
+
std::to_string
(replyResult.
elapsedMs
));
result.
add_debug
(
"
exit_code=
"
+
std::to_string
(replyResult.
exitCode
));
}
}
}
ReplyCellRunner::ReplyCellRunner
()
: runtime_(options_.runtimeOptions)
{
runtime_.
set_args
(options_.
args
);
}
ReplyCellRunner::ReplyCellRunner
(ReplyCellRunnerOptions options)
: options_(std::move(options)),
runtime_
(options_.runtimeOptions)
{
runtime_.
set_args
(options_.
args
);
}
const
ReplyCellRunnerOptions &
ReplyCellRunner::options
()
const
noexcept
{
return
options_;
}
void
ReplyCellRunner::set_options
(ReplyCellRunnerOptions options)
{
options_ =
std::move
(options);
reset_runtime
();
}
NoteResult
ReplyCellRunner::run_source
(
const
std::string &source)
{
if
(source.
empty
())
{
return
NoteResult::failure
(
"
empty Reply cell
"
,
1
)
.
add_error
(
"
empty Reply cell
"
);
}
vix::reply::ReplyRunResult replyResult =
runtime_.
run_cell
(
strip_reply_line_comments
(source));
NoteResult result =
replyResult.
ok
?
NoteResult::success
(
"
Reply cell executed
"
)
:
NoteResult::failure
(
"
Reply cell failed
"
, replyResult.
exitCode
==
0
?
1
: replyResult.
exitCode
);
add_reply_outputs
(result, options_, replyResult);
return
result;
}
NoteResult
ReplyCellRunner::run_cell
(
const
NoteCell &cell)
{
if
(cell.
kind
() != NoteCellKind::Reply)
{
return
NoteResult::failure
(
"
cell is not a Reply cell
"
,
1
)
.
add_error
(
"
cell is not a Reply cell
"
);
}
return
run_source
(cell.
source
());
}
void
ReplyCellRunner::clear
()
{
runtime_.
clear
();
}
void
ReplyCellRunner::reset_runtime
()
{
runtime_ =
vix::reply::ReplyRuntime
(options_.
runtimeOptions
);
runtime_.
set_args
(options_.
args
);
}
NoteResult
run_reply_source
(
const
std::string &source)
{
return
ReplyCellRunner
().
run_source
(source);
}
NoteResult
run_reply_cell
(
const
NoteCell &cell)
{
return
ReplyCellRunner
().
run_cell
(cell);
}
}
Back
|
FazBrowse Home
|
New Git URL