diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8005543 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "submodules/zpp"] + path = submodules/zpp + url = ssh://git@gitea.pestctrl.io:2223/Zander/zpp.git +[submodule "extern/zpp"] + path = extern/zpp + url = ssh://git@gitea.pestctrl.io:2223/Zander/zpp.git diff --git a/cmdln/new.c b/cmdln/new.c index b2c9c1a..af0e021 100644 --- a/cmdln/new.c +++ b/cmdln/new.c @@ -86,12 +86,14 @@ struct cmdln_flags* new_cmdln_flags( break; } + #ifndef RELEASE_BUILD case 5: // --test-interactive-using-input-file { test_interactive_using_input_file = optarg; break; } + #endif case 'c': // --command { diff --git a/extern/zpp b/extern/zpp new file mode 160000 index 0000000..89bb342 --- /dev/null +++ b/extern/zpp @@ -0,0 +1 @@ +Subproject commit 89bb34256e6d876ecebd8d8ca1175a0388c3ddfc diff --git a/globals/terminalcolors.c b/globals/terminalcolors.c index 2921255..48614d7 100644 --- a/globals/terminalcolors.c +++ b/globals/terminalcolors.c @@ -1,7 +1,7 @@ #include "terminalcolors.h" -#include "bin/globals/terminalcolors.cpp-4.c" +#include "bin/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" @@ -15,13 +15,13 @@ struct colors terminalcolors = { .precedences = { -#include "bin/globals/terminalcolors.cpp-18.c" + #include "bin/94850162c0dceac6c6f9558e763457a6e8ac75c569da6ba6c986030bd21d4b1f" }, -#include "bin/globals/terminalcolors.cpp-24.c" + #include "bin/6a7d755dd4b2ea24593a9d09a7cfd18ae05601661eb1ff5416e878a887508378" diff --git a/globals/terminalcolors.cpp b/globals/terminalcolors.cpp index 2f83e80..3cb510b 100644 --- a/globals/terminalcolors.cpp +++ b/globals/terminalcolors.cpp @@ -1,7 +1,7 @@ #include "terminalcolors.h" -/*/ python +/*/ import colorsys; diff --git a/makefile b/makefile index dc8fd1f..dffda42 100644 --- a/makefile +++ b/makefile @@ -33,9 +33,9 @@ include srclist.mk .PRECIOUS: %.c -%.c: %.cpp zog.py | bin/ +%.c: %.cpp ./extern/zpp/zpp | bin/ @echo "preprocessing ${<} ..." - @./zog.py -i $< --snippet-directory=bin -o $@ + @./extern/zpp/zpp $< --snippet-directory=bin -o $@ ${prefix}/%.o ${prefix}/%.d: %.c ${optionset} | ${prefix}/%/ @echo "compiling (${buildtype}) ${*}.c ..." diff --git a/parse/tokenizer/next.c b/parse/tokenizer/next.c index 8844fe0..e741890 100644 --- a/parse/tokenizer/next.c +++ b/parse/tokenizer/next.c @@ -26,6 +26,7 @@ #include "struct.h" #include "next.h" +#if 0 static const enum state { s_error, @@ -136,6 +137,7 @@ static const enum state { [s_reading_identifier]['0' ... '9'] = s_reading_identifier, [s_reading_identifier][128] = s_reading_identifier, }; +#endif void tokenizer_next( struct tokenizer* this) diff --git a/repl/main.c b/repl/main.c new file mode 100644 index 0000000..cb4d2fe --- /dev/null +++ b/repl/main.c @@ -0,0 +1,135 @@ + +#include + +#include + +#include "main.h" + +void repl_main(void) +{ + ENTER; + + TODO; + + // if we're actually connected to a terminal: + // set terminal options. + // otherwise, open the file we're pretending is a terminal. + + // create input string + // which is an actual string that the history object has a reference to? + + // create history: + // I think this is a list of strings? + + // create terminal tokenizer + + // create terminal buffer: + // which keeps track of what characters we want where (not nessarily \\ + the entire height of the terminal, but certianly the entire width) \\ + characters can have foreground color (and maybe boldness?). + // has a insert column and line. handles word-wrap. + // keeps track of what's on the screen and only edits as nessisary. + // starts with assuming we're only editing one line (full width), but \\ + if the expression line gets too long or printing error messages \\ + might push us beyond that, then --even if we cleared-- we would \\ + need to consider the new editing height. + // this terminal buffer also keeps track of where the cursor should \\ + be vs. where it is and will update that apprioately as well. + + // loop: + // read next token + + // somehow also check if the terminal resized. If it did: + // tell the terminal buffer. + // internally this will completely reset what's live. + + // match token.kind: + // (almost) every case clears and redraws what we want the buffer \\ + to contain. + + // case up, down: + // selects history index? + // which selects the string we're editing? + + // case left, right: + // just move cursor position, no clear needed. + + // case 'a-zA-Z0-9', etc.: + // insert the letter into the string + + // create parsing tokenizer + + // parse the string + // all statements and expressions keep references to the \\ + tokens. + + // tell the statement to color tokens + + // the tokenizer keeps references to all tokens too. + + // clear the buffer + + // set buffer insert position to 0, 0. + + // maybe the prompt + line is longer than the terminal width. + // some maybe we word-wrap? + + // draw the prompt line (either green or red) + + // iterate through tokenizer's tokens: + // each token knows how many whitespace characters were \\ + read since the previous one. + // print their text into the buffer with the token's color. + // the buffer will handle word-wrapping. + // some tokens don't have an expression or statement that \\ + owns them. + // some part of the input text may not be part of a \\ + token? like a comment? + // I think comments will need to be considered \\ + tokens that the parser doesn't pick up. That way \\ + it at least appears in the output line. + + // case delete, backspace: + // remove the letter at location + + // run through basically the same parsing logic as inserting \\ + a character + + // case enter: + // push a newline + // if line is not empty: + // evaluate statement + // which might print a value + // into the terminal buffer? or straight out? + // I think straight out. + // terminal buffer.clear(true-reset = True): + // true reset will clear what's "live" and the buffer, \\ + and set the height back to 1. + // new string line + // new history entry + // redraw prompt. + + // update buffer: + // compare (buffer of what we want vs. what's live) + + TODO; + + EXIT; +} + + + + + + + + + + + + + + + + + diff --git a/repl/main.h b/repl/main.h new file mode 100644 index 0000000..fb0f38b --- /dev/null +++ b/repl/main.h @@ -0,0 +1,2 @@ + +void repl_main(void); diff --git a/repl/tokenizer/free.c b/repl/tokenizer/free.c new file mode 100644 index 0000000..e69de29 diff --git a/repl/tokenizer/free.h b/repl/tokenizer/free.h new file mode 100644 index 0000000..e69de29 diff --git a/repl/tokenizer/new.c b/repl/tokenizer/new.c new file mode 100644 index 0000000..e69de29 diff --git a/repl/tokenizer/new.h b/repl/tokenizer/new.h new file mode 100644 index 0000000..e69de29 diff --git a/repl/tokenizer/next.c b/repl/tokenizer/next.c new file mode 100644 index 0000000..e69de29 diff --git a/repl/tokenizer/next.h b/repl/tokenizer/next.h new file mode 100644 index 0000000..e69de29 diff --git a/repl/tokenizer/struct.h b/repl/tokenizer/struct.h new file mode 100644 index 0000000..e69de29 diff --git a/zog.py b/zog.py deleted file mode 100755 index 695cad7..0000000 --- a/zog.py +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env python3 - -import os; -import sys; -import io; -import argparse; - -parser = argparse.ArgumentParser(prog = 'zog'); - -parser.add_argument('-i', '--input', required = True); -parser.add_argument('-o', '--output', required = True); -parser.add_argument('-s', '--snippet-directory', default = "/tmp/"); - -args = parser.parse_args(sys.argv[1:]); - -input_file = args.input; -output_file = args.output; -snippet_directory = args.snippet_directory; - -while input_file.startswith("./"): - input_file = input_file[2:]; - -while snippet_directory.startswith("./"): - snippet_directory = snippet_directory[2:]; - -while snippet_directory.endswith("/"): - snippet_directory = snippet_directory[:-1]; - -myglobals = dict(); - -istream = open(input_file, "r"); -ostream = open(output_file, "w"); - -lines = istream.readlines(); - -i = 0; -n = len(lines); - -while i < n: - if "/*/" in lines[i]: - indentation = lines[i].index("/*/"); - - start_index = i; - - i += 1; - - source = "" - - while "/*/" not in lines[i]: - source += lines[i][indentation:]; - i += 1; - - end_index = i; - i += 1; - - real_stdout = sys.stdout - sys.stdout = captured_stdout = io.StringIO() - eval(compile(source, "", "exec"), myglobals); - sys.stdout = real_stdout - - outstring = captured_stdout.getvalue(); - - if outstring and outstring[-1] != "\n": - outstring += "\n" - - temppath = f"{snippet_directory}/{input_file}-{start_index+1}.c"; - - tempdir = temppath[:temppath.rindex('/')]; - - os.makedirs(tempdir, exist_ok = True); - - with open(temppath, "w") as stream: - for outline in outstring.split("\n"): - stream.write((" " * indentation) + outline + '\n'); - - ostream.write(f'#include "{temppath}"' + "\n"); - ostream.write("\n" * (end_index - start_index)); - else: - ostream.write(lines[i]); - i += 1; - -istream.close(); -ostream.close(); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -