FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rstudio/src/cpp/session/SessionRUtil.cpp at master · aakashdoiphode/rstudio · GitHub
aakashdoiphode
/
rstudio
Public
forked from
rstudio/rstudio
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
rstudio
/
src
/
cpp
/
session
/
SessionRUtil.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
181 lines (141 loc) · 4.52 KB
Breadcrumbs
rstudio
/
src
/
cpp
/
session
/
SessionRUtil.cpp
Copy path
File metadata and controls
181 lines (141 loc) · 4.52 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
/*
* SessionRUtil.cpp
*
* Copyright (C) 2009-2015 by RStudio, Inc.
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
#
include
<
session/SessionRUtil.hpp
>
#
include
<
core/Error.hpp
>
#
include
<
core/Log.hpp
>
#
include
<
core/Exec.hpp
>
#
include
<
core/Macros.hpp
>
#
include
<
core/FileSerializer.hpp
>
#
include
<
r/RExec.hpp
>
#
include
<
r/RRoutines.hpp
>
#
include
<
session/SessionModuleContext.hpp
>
#
include
<
boost/regex.hpp
>
#
include
"
modules/shiny/SessionShiny.hpp
"
namespace
rstudio
{
using
namespace
core
;
namespace
session
{
namespace
r_utils
{
namespace
{
boost::regex&
reYaml
()
{
static
boost::regex
instance
(
"
^[
\\
s
\\
n]*---
\\
s*(.*?)---
\\
s*(?:$|
\\
n)
"
);
return
instance;
}
}
//
anonymous namespace
bool
hasYamlHeader
(
const
FilePath& filePath)
{
std::string contents;
Error error =
readStringFromFile
(filePath, &contents);
if
(error)
LOG_ERROR
(error);
return
hasYamlHeader
(contents);
}
bool
hasYamlHeader
(
const
std::string& content)
{
return
boost::regex_search
(content.
begin
(), content.
end
(),
reYaml
());
}
std::string
extractYamlHeader
(
const
FilePath& filePath)
{
std::string contents;
Error error =
readStringFromFile
(filePath, &contents);
if
(error)
LOG_ERROR
(error);
return
extractYamlHeader
(contents);
}
std::string
extractYamlHeader
(
const
std::string& content)
{
std::string result;
boost::smatch match;
if
(
boost::regex_search
(content.
begin
(), content.
end
(), match,
reYaml
()))
if
(match.
size
() >=
1
)
result = match[
1
];
return
result;
}
namespace
{
Error
extractRCode
(
const
std::string& contents,
const
std::string& reOpen,
const
std::string& reClose,
std::string* pContent)
{
using
namespace
r
::exec
;
RFunction
extract
(
"
.rs.extractRCode
"
);
extract.
addParam
(contents);
extract.
addParam
(reOpen);
extract.
addParam
(reClose);
Error error = extract.
call
(pContent);
return
error;
}
}
//
anonymous namespace
Error
extractRCode
(
const
std::string& fileContents,
const
std::string& documentType,
std::string* pCode)
{
using
namespace
source_database
;
Error error =
Success
();
if
(documentType == SourceDocument::SourceDocumentTypeRSource)
*pCode = fileContents;
else
if
(documentType == SourceDocument::SourceDocumentTypeRMarkdown)
error =
extractRCode
(fileContents,
"
^
\\
s*[`]{3}{
\\
s*[Rr](?:}|[
\\
s,].*})
\\
s*$
"
,
"
^
\\
s*[`]{3}
\\
s*$
"
,
pCode);
else
if
(documentType == SourceDocument::SourceDocumentTypeSweave)
error =
extractRCode
(fileContents,
"
^
\\
s*<<.*>>=
\\
s*$
"
,
"
^
\\
s*@
\\
s*$
"
,
pCode);
else
if
(documentType == SourceDocument::SourceDocumentTypeCpp)
error =
extractRCode
(fileContents,
"
^
\\
s*/[*]{3,}
\\
s*[rR]
\\
s*$
"
,
"
^
\\
s*[*]+/
"
,
pCode);
return
error;
}
std::set<std::string>
implicitlyAvailablePackages
(
const
FilePath& filePath,
const
std::string& contents)
{
std::set<std::string> dependencies;
if
(
modules::shiny::getShinyFileType
(filePath, contents) !=
modules::shiny::ShinyNone)
dependencies.
insert
(
"
shiny
"
);
return
dependencies;
}
std::set<std::string>
implicitlyAvailablePackages
(
const
FilePath& filePath)
{
std::string contents;
Error error =
readStringFromFile
(filePath, &contents);
if
(error)
LOG_ERROR
(error);
return
implicitlyAvailablePackages
(filePath, contents);
}
namespace
{
SEXP
rs_fromJSON
(
SEXP
objectSEXP)
{
std::string contents =
r::sexp::asString
(objectSEXP);
json::Value jsonValue;
if
(!
json::parse
(contents, &jsonValue))
return
R_NilValue;
r::sexp::Protect protect;
return
r::sexp::create
(jsonValue, &protect);
}
}
//
anonymous namespace
Error
initialize
()
{
RS_REGISTER_CALL_METHOD
(rs_fromJSON,
1
);
return
Success
();
}
}
//
namespace r_utils
}
//
namespace session
}
//
namespace rstudio
Back
|
FazBrowse Home
|
New Git URL