21#include "../utils/tools.hpp"
22#include "../../kernel.hpp"
43 size_t lastpos = std::string::npos;
45 for (
size_t i = 0; i < sLine.length(); i++)
59 if (lastpos == std::string::npos)
60 return {sLine,
"", 0, sLine.length()};
64 _cTip.
sDefinition = sLine.substr(0, sLine.find(
"- "));
67 if (sLine.find(
"- ") != std::string::npos)
74 size_t firstpos = _cTip.
sDefinition.find_first_not_of(
' ', lastpos);
76 if (firstpos == std::string::npos)
82 _cTip.
sDefinition.replace(lastpos, firstpos - lastpos,
" -> ");
83 else if (firstpos - lastpos > 2)
84 _cTip.
sDefinition.erase(lastpos, firstpos - lastpos - 1);
105 static bool bBeginEnd =
false;
107 if (sNewDocLine.find_first_not_of(
" \t") == std::string::npos)
116 if (sNewDocLine.find(
"\\begin{") != std::string::npos && sNewDocLine.find(
"\\end{") == std::string::npos)
123 else if (sNewDocLine.find(
"\\begin{") == std::string::npos && sNewDocLine.find(
"\\end{") != std::string::npos)
130 else if ((sNewDocLine.length()
131 && (sNewDocLine.substr(sNewDocLine.find_first_not_of(
" \t"), 2) ==
"- "
132 || sNewDocLine.substr(sNewDocLine.find_first_not_of(
" \t"), 7) ==
"\\param "
133 || sNewDocLine.substr(sNewDocLine.find_first_not_of(
" \t"), 8) ==
"\\remark ")) || bBeginEnd)
144 _cTip.
sDocumentation += sNewDocLine.substr(sNewDocLine.find_first_not_of(
" \t"));
147 if (nPos != std::string::npos)
149 else if ((nPos = _cTip.
sDocumentation.find(
"\\procedure ")) != std::string::npos)
151 size_t nPos2 = nPos + 10;
174 if (sDocumentation.find_first_not_of(
" \n") != std::string::npos)
177 sDocumentation.erase(0, sDocumentation.find_first_not_of(
" \n"));
179 if (sDocumentation.back() ==
' ' || sDocumentation.back() ==
'\n')
180 sDocumentation.erase(sDocumentation.find_last_not_of(
" \n")+1);
182 size_t nPos = sDocumentation.find(
"\\param ");
185 if (nPos != std::string::npos)
188 if (nPos > 5 && sDocumentation.substr(nPos-5, 5) !=
"\n ")
189 sDocumentation.insert(nPos,
"\n " +
toUpperCase(
_lang.
get(
"GUI_EDITOR_CALLTIP_PROC_PARAMS")) +
"\n ");
191 sDocumentation.insert(nPos,
toUpperCase(
_lang.
get(
"GUI_EDITOR_CALLTIP_PROC_PARAMS")) +
"\n ");
193 while ((nPos = sDocumentation.find(
"\\param ")) != std::string::npos)
195 sDocumentation.replace(nPos, 6,
"-");
196 size_t spacePos = sDocumentation.find(
' ', sDocumentation.find_first_not_of(
' ', nPos+1));
198 if (spacePos == std::string::npos)
201 sDocumentation.insert(spacePos,
":");
203 if (sDocumentation[sDocumentation.find_first_not_of(
' ', nPos+1)] ==
'_')
204 sDocumentation.erase(sDocumentation.find_first_not_of(
' ', nPos+1), 1);
209 while ((nPos = sDocumentation.find(
"\\return ")) != std::string::npos)
213 size_t newReturn =
std::min(sDocumentation.find(
"\\return ", nPos+1), sDocumentation.find(
"\\remark ", nPos+1));
218 std::string sCurrReturn = sDocumentation.substr(nPos+8, newReturn-nPos-8);
219 sDocumentation.erase(nPos, newReturn-nPos);
221 while (sDocumentation.front() ==
' ')
222 sDocumentation.erase(0, 1);
224 if (sReturns.length())
227 sReturns += sCurrReturn.substr(0, sCurrReturn.find(
' '));
231 while ((nPos = sDocumentation.find(
"\\remark ")) != std::string::npos)
232 sDocumentation.replace(nPos, 7,
toUpperCase(
_lang.
get(
"GUI_EDITOR_CALLTIP_PROC_REMARK"))+
":");
235 while ((nPos = sDocumentation.find(
"!!")) != std::string::npos)
236 sDocumentation.erase(nPos, 2);
243 while ((nMatch = sDocumentation.find(
"\\begin{")) != std::string::npos)
245 sDocumentation.erase(nMatch, sDocumentation.find(
'}', nMatch) + 1 - nMatch);
247 if (sDocumentation.substr(nMatch, 5) ==
"\n ")
248 sDocumentation.erase(nMatch, 5);
251 while ((nMatch = sDocumentation.find(
"\\end{")) != std::string::npos)
253 sDocumentation.erase(nMatch, sDocumentation.find(
'}', nMatch) + 1 - nMatch + 1);
257 if (sReturns.length())
259 if (sReturns.find(
',') == std::string::npos)
260 sReturns =
"-> " + sReturns;
262 sReturns =
"-> {" + sReturns +
"}";
266 sDocumentation.clear();
268 return sDocumentation;
293 std::ifstream procedure_in;
294 std::string sProcCommandLine;
295 bool bBlockComment =
false;
296 std::string sDocumentation;
297 bool bDocFound =
false;
298 procedure_in.open(pathname +
".nprc");
301 if (!procedure_in.good())
305 while (!procedure_in.eof())
308 std::getline(procedure_in, sProcCommandLine);
312 if (!sProcCommandLine.length())
320 if (sProcCommandLine.substr(0, 2) ==
"##")
323 if (sProcCommandLine.substr(0, 3) ==
"##!")
330 if (sProcCommandLine.find(
"##") != std::string::npos)
331 sProcCommandLine = sProcCommandLine.substr(0, sProcCommandLine.find(
"##"));
334 if (sProcCommandLine.substr(0, 2) ==
"#*" && sProcCommandLine.find(
"*#", 2) == std::string::npos)
336 if (sProcCommandLine.substr(0, 3) ==
"#*!")
342 bBlockComment =
true;
347 if (bBlockComment && sProcCommandLine.find(
"*#") != std::string::npos)
349 bBlockComment =
false;
353 if (sProcCommandLine.find(
"*#") == sProcCommandLine.length() - 2)
356 sProcCommandLine = sProcCommandLine.substr(sProcCommandLine.find(
"*#") + 2);
358 else if (bBlockComment && sProcCommandLine.find(
"*#") == std::string::npos)
368 if (sProcCommandLine[0] !=
'@' &&
findCommand(sProcCommandLine).sString !=
"procedure")
374 else if (sProcCommandLine[0] ==
'@')
382 if (
findCommand(sProcCommandLine).sString !=
"procedure")
390 if (sProcCommandLine.find(procedurename) == std::string::npos || sProcCommandLine.find(
'(') == std::string::npos)
400 if (
getMatchingParenthesis(sProcCommandLine.substr(sProcCommandLine.find(procedurename))) == std::string::npos)
403 _cTip.
sDefinition = sProcCommandLine.substr(sProcCommandLine.find(procedurename),
getMatchingParenthesis(sProcCommandLine.substr(sProcCommandLine.find(procedurename))) + 1);
408 while (sArgList.length())
412 if (currentarg.front() ==
'_')
413 currentarg.erase(0, 1);
417 if (sArgList.length())
423 if (sProcCommandLine.find(
"::") != std::string::npos)
425 std::string sFlags = sProcCommandLine.substr(sProcCommandLine.find(
"::") + 2).c_str();
427 if (sFlags.find(
"##") != std::string::npos)
428 sFlags.erase(sFlags.find(
"##"));
437 while (!procedure_in.eof())
439 std::getline(procedure_in, sProcCommandLine);
442 if (sProcCommandLine.substr(0, 3) ==
"##!")
444 else if (sProcCommandLine.substr(0, 3) ==
"#*!")
447 bBlockComment =
true;
449 else if (bBlockComment)
453 if (sProcCommandLine.find(
"*#") != std::string::npos)
461 std::string sReturns;
468 if (sReturns.length())
501 size_t nIndentPos = 4;
502 size_t nLastLineBreak = 0;
503 bool isItemize =
false;
508 for (
size_t i = 0; i < sReturn.length(); i++)
510 if (sReturn[i] ==
'\n')
514 if (sReturn.substr(i, 7) ==
"\n - ")
520 if ((i == maxLineLength && !nLastLineBreak)
521 || (nLastLineBreak && i - nLastLineBreak == maxLineLength))
523 for (
int j = i; j >= 0; j--)
525 if (sReturn[j] ==
' ')
528 sReturn.insert(j + 1, nIndentPos + 2*isItemize,
' ');
532 else if (sReturn[j] ==
'-' && j != (
int)i)
536 (sReturn[j - 1] ==
' '
537 || sReturn[j - 1] ==
'('
538 || sReturn[j + 1] ==
')'
539 || sReturn[j - 1] ==
'['
540 || (sReturn[j + 1] >=
'0' && sReturn[j + 1] <=
'9')
541 || sReturn[j + 1] ==
','
542 || (sReturn[j + 1] ==
'"' && sReturn[j - 1] ==
'"')
546 sReturn.insert(j + 1,
"\n");
547 sReturn.insert(j + 2, nIndentPos + 2*isItemize,
' ');
548 nLastLineBreak = j + 1;
551 else if (sReturn[j] ==
',' && j != (
int)i && sReturn[j + 1] !=
' ')
553 sReturn.insert(j + 1,
"\n");
554 sReturn.insert(j + 2, nIndentPos + 2*isItemize,
' ');
555 nLastLineBreak = j + 1;
576 if (sToken ==
"showf")
578 else if (sToken ==
"view")
580 else if (sToken ==
"undef")
582 else if (sToken ==
"ifndef")
583 sToken =
"ifndefined";
584 else if (sToken ==
"redef")
586 else if (sToken ==
"del")
588 else if (sToken ==
"search")
590 else if (sToken ==
"vector")
592 else if (sToken ==
"vector3d")
594 else if (sToken ==
"graph")
596 else if (sToken ==
"graph3d")
598 else if (sToken ==
"gradient")
600 else if (sToken ==
"gradient3d")
602 else if (sToken ==
"surface")
604 else if (sToken ==
"surface3d")
606 else if (sToken ==
"meshgrid")
608 else if (sToken ==
"meshgrid3d")
610 else if (sToken ==
"density")
612 else if (sToken ==
"density3d")
614 else if (sToken ==
"contour")
616 else if (sToken ==
"contour3d")
618 else if (sToken ==
"mtrxop")
620 else if (sToken ==
"man")
622 else if (sToken ==
"credits" || sToken ==
"info")
624 else if (sToken ==
"integrate2" || sToken ==
"integrate2d")
625 sToken =
"integrate";
642 if (sToken ==
"arcsin")
644 else if (sToken ==
"arccos")
646 else if (sToken ==
"arctan")
648 else if (sToken ==
"arsinh")
650 else if (sToken ==
"arcosh")
652 else if (sToken ==
"artanh")
670 std::string pathname = sToken;
671 std::string procedurename = pathname.substr(pathname.rfind(
'~') + 1);
674 if (pathname.find(
"$this~") != std::string::npos)
679 else if (pathname.find(
"$thisfile~") != std::string::npos)
687 if (pathname.find(
"$main~") != std::string::npos)
688 pathname.erase(pathname.find(
"$main~") + 1, 5);
690 while (pathname.find(
'~') != std::string::npos)
691 pathname[pathname.find(
'~')] =
'/';
694 if (pathname[0] ==
'$' && pathname.find(
':') == std::string::npos)
695 pathname.replace(0, 1, sProcPath +
"/");
696 else if (pathname.find(
':') == std::string::npos)
697 pathname.insert(0, sProcPath);
701 pathname = pathname.substr(pathname.find(
'\'') + 1, pathname.rfind(
'\'') - pathname.find(
'\'') - 1);
706 while (procedurename.find(
'\'') != std::string::npos)
707 procedurename.erase(procedurename.find(
'\''), 1);
709 if (procedurename.find(
'/') != std::string::npos)
710 procedurename =
"$" + procedurename.substr(procedurename.rfind(
'/') + 1);
712 if (procedurename.find(
'\\') != std::string::npos)
713 procedurename =
"$" + procedurename.substr(procedurename.rfind(
'\\') + 1);
715 if (procedurename[0] !=
'$')
716 procedurename.insert(0, 1,
'$');
735 size_t highlightlength = sToken.length();
737 if (sToken.find(
' ') != std::string::npos)
738 highlightlength = sToken.find(
' ');
740 return {sToken,
"", 0, highlightlength};
754 if (
_lang.
get(
"PARSERFUNCS_LISTFUNC_METHOD_" +
toUpperCase(sToken) +
"_[STRING]") !=
"PARSERFUNCS_LISTFUNC_METHOD_" +
toUpperCase(sToken) +
"_[STRING]")
755 sToken =
"STRINGVAR." +
_lang.
get(
"PARSERFUNCS_LISTFUNC_METHOD_" +
toUpperCase(sToken) +
"_[STRING]");
757 sToken =
"TABLE()." +
_lang.
get(
"PARSERFUNCS_LISTFUNC_METHOD_" +
toUpperCase(sToken) +
"_[DATA]");
This class handles the internal language system and returns the language strings of the selected lang...
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
CallTip getProcedure(std::string sToken) const
Get the calltip for the selected (global) procedure.
CallTip getOption(std::string sToken) const
Get the calltip for the selected option.
CallTip getConstant(std::string sToken) const
Get the calltip for the selected constant.
CallTip getMethod(std::string sToken) const
Get the calltip for the selected method.
CallTip getFunction(std::string sToken) const
Get the calltip for the selected (built-in) function.
CallTip getCommand(std::string sToken) const
Get the calltip for the selected command.
CallTip getPredef(std::string sToken) const
Get the calltip for the selected predefined symbol.
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
std::string getProcPath() const
Returns the current procedure root import path.
This class is the immutable (const) version of a string view. It can be constructed from a MutableStr...
bool fileExists(const string &)
This function checks, whether the file with the passed file name exists.
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
CallTip FindProcedureDefinition(const std::string &pathname, const std::string &procedurename)
Search the procedure definition in a global file.
CallTip addLinebreaks(CallTip _cTip, size_t maxLineLength)
Adds the necessary linebreaks to the documentation part of the CallTip to fit inside the desired maxi...
static void AppendToDocumentation(CallTip &_cTip, const std::string &sNewDocLine)
Appends the new documentation line to the already existing line.
static std::string CleanDocumentation(std::string sDocumentation, std::string &sReturns)
Checks layout and finishes styling of the documentation string.
static CallTip realignLangString(std::string sLine)
Converts the language file documentation layout into something more fitting for the calltips in the g...
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
This structure contains the data for a single calltip, which might be shown in the editor or the term...
std::string sDocumentation