Begin design of comment evaluation and {{variables}}
This commit is contained in:
@@ -1172,3 +1172,25 @@ API void CloseStdin(Process *process) {
|
|||||||
API double GetTimeSeconds() {
|
API double GetTimeSeconds() {
|
||||||
return GetTimeMicros() / 1000000.0;
|
return GetTimeMicros() / 1000000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
API String WriteTempFile(String data) {
|
||||||
|
Scratch scratch;
|
||||||
|
|
||||||
|
#if OS_WINDOWS
|
||||||
|
int buffer_len = MAX_PATH+1;
|
||||||
|
char16_t *buffer = AllocArray(scratch, char16_t, buffer_len);
|
||||||
|
Assert(sizeof(char16_t) == sizeof(wchar_t));
|
||||||
|
DWORD result = GetTempPath2W(buffer_len, (LPWSTR)buffer);
|
||||||
|
Assert(result != 0);
|
||||||
|
String16 temp16 = {buffer, result};
|
||||||
|
NormalizePathInPlace(temp16);
|
||||||
|
String temp_directory = ToString(scratch, temp16);
|
||||||
|
#else
|
||||||
|
String temp_directory = "/tmp";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
String temp_filename = Format(scratch, "%S/temp%llu", temp_directory, GetTimeNanos());
|
||||||
|
bool done = WriteFile(temp_filename, data);
|
||||||
|
Assert(done);
|
||||||
|
return temp_filename;
|
||||||
|
}
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ API Int GetWordEnd(Buffer *buffer, Int pos) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
API bool IsLoadWord(char16_t w) {
|
API bool IsLoadWord(char16_t w) {
|
||||||
bool result = w == u'-' || w == u'/' || w == u'\\' || w == u':' || w == u'$' || w == u'_' || w == u'.' || w == u'!' || w == u'@';
|
bool result = w == u'-' || w == u'/' || w == u'\\' || w == u':' || w == u'$' || w == u'_' || w == u'.' || w == u'!' || w == u'@' || w == '{' || w == '}';
|
||||||
if (!result) {
|
if (!result) {
|
||||||
result = !(IsSymbol(w) || IsWhitespace(w));
|
result = !(IsSymbol(w) || IsWhitespace(w));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ void Appendf(View *view, const char *fmt, ...) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ReportErrorf(const char *fmt, ...) {
|
void ReportErrorf(const char *fmt, ...) {
|
||||||
|
ErrorCount += 1;
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
STRING_FORMAT(scratch, fmt, string);
|
STRING_FORMAT(scratch, fmt, string);
|
||||||
if (BreakOnError) {
|
if (BreakOnError) {
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ Int ErrorCount;
|
|||||||
String16 InitialScratchContent = uR"==(:OpenProject
|
String16 InitialScratchContent = uR"==(:OpenProject
|
||||||
C:/text_editor/src/text_editor/text_editor.cpp
|
C:/text_editor/src/text_editor/text_editor.cpp
|
||||||
:Set FontSize 70
|
:Set FontSize 70
|
||||||
|
/*
|
||||||
|
!python {{TEMP}}
|
||||||
|
for it in i:
|
||||||
|
memes
|
||||||
|
*/
|
||||||
0
|
0
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
|
|||||||
@@ -56,6 +56,17 @@ void CMD_EvalCommandsLineByLine() {
|
|||||||
EvalCommandsLineByLine(set);
|
EvalCommandsLineByLine(set);
|
||||||
} RegisterCommand(CMD_EvalCommandsLineByLine, "", "Goes line by line over a buffer and evaluates every line as a command, ignores empty or lines starting with '//'");
|
} RegisterCommand(CMD_EvalCommandsLineByLine, "", "Goes line by line over a buffer and evaluates every line as a command, ignores empty or lines starting with '//'");
|
||||||
|
|
||||||
|
Variable *GetVariable(String name) {
|
||||||
|
Variable *var = NULL;
|
||||||
|
For (Variables) {
|
||||||
|
if (name == it.name) {
|
||||||
|
var = ⁢
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return var;
|
||||||
|
}
|
||||||
|
|
||||||
BufferID LoadConfig(String config_path) {
|
BufferID LoadConfig(String config_path) {
|
||||||
ReportConsolef("Loading config %S...", config_path);
|
ReportConsolef("Loading config %S...", config_path);
|
||||||
Window *window = GetWindow(NullWindowID);
|
Window *window = GetWindow(NullWindowID);
|
||||||
@@ -69,7 +80,6 @@ BufferID LoadConfig(String config_path) {
|
|||||||
return buffer->id;
|
return buffer->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define ExpectP(x, ...) \
|
#define ExpectP(x, ...) \
|
||||||
if (!(x)) { \
|
if (!(x)) { \
|
||||||
ReportErrorf("Failed to parse '" __FUNCTION__ "' command, " __VA_ARGS__); \
|
ReportErrorf("Failed to parse '" __FUNCTION__ "' command, " __VA_ARGS__); \
|
||||||
@@ -80,14 +90,7 @@ void Set(String string) {
|
|||||||
String name = SkipIdent(&string);
|
String name = SkipIdent(&string);
|
||||||
ExpectP(name.len != 0, "expected a variable name, instead got '%S'", string);
|
ExpectP(name.len != 0, "expected a variable name, instead got '%S'", string);
|
||||||
|
|
||||||
Variable *var = NULL;
|
Variable *var = GetVariable(name);
|
||||||
For (Variables) {
|
|
||||||
if (name == it.name) {
|
|
||||||
var = ⁢
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (var) {
|
if (var) {
|
||||||
SkipWhitespace(&string);
|
SkipWhitespace(&string);
|
||||||
if (var->type == VariableType_String) {
|
if (var->type == VariableType_String) {
|
||||||
|
|||||||
@@ -854,7 +854,7 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
InitScratch();
|
InitScratch();
|
||||||
InitOS((OSErrorReport *)printf);
|
InitOS((OSErrorReport *)printf);
|
||||||
#if _WIN32
|
#if OS_WINDOWS
|
||||||
int argc = __argc;
|
int argc = __argc;
|
||||||
char **argv = __argv;
|
char **argv = __argv;
|
||||||
AttachConsole(ATTACH_PARENT_PROCESS);
|
AttachConsole(ATTACH_PARENT_PROCESS);
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ void MouseLoadWord(Event event, ResolveOpenMeta meta = ResolveOpenMeta_Normal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool IsOpenBoundary(char c) {
|
bool IsOpenBoundary(char c) {
|
||||||
bool result = c == 0 || IsBrace(c) || c == ':' || c == '\t' || c == '\n' || c == '"' || c == '\'';
|
bool result = c == 0 || c == ':' || c == '\t' || c == '\n' || c == '"' || c == '\'';
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,6 +224,8 @@ ResolvedOpen ResolveOpen(Allocator alo, Window *window, String path, ResolveOpen
|
|||||||
bool exec = !(ResolveOpenMeta_DontExec & meta);
|
bool exec = !(ResolveOpenMeta_DontExec & meta);
|
||||||
|
|
||||||
#if PLUGIN_CONFIG
|
#if PLUGIN_CONFIG
|
||||||
|
// @todo: variable substitution {{ProjectDirectory}}/build/te.exe
|
||||||
|
|
||||||
if (exec && result.kind == OpenKind_Invalid && StartsWith(path, ":Set ")) {
|
if (exec && result.kind == OpenKind_Invalid && StartsWith(path, ":Set ")) {
|
||||||
result.kind = OpenKind_Set;
|
result.kind = OpenKind_Set;
|
||||||
result.path = Skip(path, 5);
|
result.path = Skip(path, 5);
|
||||||
@@ -253,6 +255,15 @@ ResolvedOpen ResolveOpen(Allocator alo, Window *window, String path, ResolveOpen
|
|||||||
if (exec && result.kind == OpenKind_Invalid && StartsWith(path, "!")) {
|
if (exec && result.kind == OpenKind_Invalid && StartsWith(path, "!")) {
|
||||||
result.kind = OpenKind_Exec;
|
result.kind = OpenKind_Exec;
|
||||||
result.path = Skip(path, 1);
|
result.path = Skip(path, 1);
|
||||||
|
|
||||||
|
Int idx = 0;
|
||||||
|
String needle = "{{TEMP}}";
|
||||||
|
if (Seek(result.path, needle, &idx, SeekFlag_None)) {
|
||||||
|
String rest = Skip(result.path, idx + needle.len);
|
||||||
|
String begin = GetPrefix(result.path, idx);
|
||||||
|
String temp_filename = WriteTempFile(rest);
|
||||||
|
result.path = Format(alo, "%S%S", begin, temp_filename);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://web
|
// https://web
|
||||||
@@ -291,7 +302,6 @@ ResolvedOpen ResolveOpen(Allocator alo, Window *window, String path, ResolveOpen
|
|||||||
}
|
}
|
||||||
path = {pstart.data, (Int)(p.data - pstart.data)};
|
path = {pstart.data, (Int)(p.data - pstart.data)};
|
||||||
|
|
||||||
// @todo: verify!
|
|
||||||
// For (LINE:COLUMN): error: - we can either backtrack at the end since we are including
|
// For (LINE:COLUMN): error: - we can either backtrack at the end since we are including
|
||||||
// the parenthesis and whitespace or alternatively we can look for patterns on every
|
// the parenthesis and whitespace or alternatively we can look for patterns on every
|
||||||
// character move in the loop... For now let's do backtracking. This doesn't handle all paths
|
// character move in the loop... For now let's do backtracking. This doesn't handle all paths
|
||||||
|
|||||||
Reference in New Issue
Block a user