~jamii/focus

3987b3e5c5e1abe0637bc0751711aa7acfaf508a — Jamie Brandon 1 year, 7 months ago e93290e
imp => imp2
6 files changed, 20 insertions(+), 20 deletions(-)

M README.md
M build.zig
D imp
A imp2
M lib/focus/imp_repl.zig
M lib/focus/language.zig
M README.md => README.md +1 -1
@@ 5,7 5,7 @@ Probably not useful for anyone but me, but perhaps a useful starting point to fo
Unlikely to build out of the box on anything that isn't my laptop. But as a starting point:

```
git clone https://github.com/jamii/imp ../imp
git clone --branch v2 https://github.com/jamii/imp ../imp2
nix-shell
zig build run -Drelease-safe=true
```

M build.zig => build.zig +2 -2
@@ 1,6 1,6 @@
const builtin = @import("builtin");
const std = @import("std");
const imp = @import("imp/build.zig");
const imp2 = @import("imp2/build.zig");
const Builder = std.build.Builder;
const allocator = std.testing.allocator;



@@ 49,7 49,7 @@ fn includeCommon(exe: *std.build.LibExeObjStep) !void {
    try includeNix(exe, "NIX_SDL2_TTF_DEV");
    try includeNix(exe, "NIX_PCRE2_DEV");
    exe.setOutputDir("./zig-cache");
    imp.addDeps(exe);
    imp2.addDeps(exe);
}

fn includeNix(exe: *std.build.LibExeObjStep, env_var: []const u8) !void {

D imp => imp +0 -1
@@ 1,1 0,0 @@
../imp/
\ No newline at end of file

A imp2 => imp2 +1 -0
@@ 0,0 1,1 @@
../imp2/
\ No newline at end of file

M lib/focus/imp_repl.zig => lib/focus/imp_repl.zig +7 -7
@@ 8,15 8,15 @@ const Editor = focus.Editor;
const Window = focus.Window;
const style = focus.style;
const Selector = focus.Selector;
const imp = @import("../../imp/lib/imp.zig");
const imp2 = @import("../../imp2/lib/imp.zig");

pub const ImpRepl = struct {
    app: *App,
    program_editor: *Editor,
    result_editor: *Editor,
    imp_worker: *imp.lang.Worker,
    imp_worker: *imp2.lang.Worker,
    last_request_id: usize,
    last_response: imp.lang.Worker.Response,
    last_response: imp2.lang.Worker.Response,

    pub fn init(app: *App, program_editor: *Editor) *ImpRepl {
        const empty_buffer = Buffer.initEmpty(app, .{


@@ 27,10 27,10 @@ pub const ImpRepl = struct {
            .show_status_bar = false,
            .show_completer = false,
        });
        const imp_worker = imp.lang.Worker.init(
        const imp_worker = imp2.lang.Worker.init(
            app.allocator,
            .{
                .db_path = "/home/jamie/exo-secret/imp.db",
                .db_path = "/home/jamie/exo-secret/imp2.db",
                .memory_limit_bytes = 1024 * 1024 * 1024,
            },
        ) catch |err|


@@ 63,7 63,7 @@ pub const ImpRepl = struct {
    }

    // called from program_editor on change
    pub fn setProgram(self: *ImpRepl, program: []const u8, selection: imp.lang.SourceSelection, action: imp.lang.Worker.Request.Action) void {
    pub fn setProgram(self: *ImpRepl, program: []const u8, selection: imp2.lang.SourceSelection, action: imp2.lang.Worker.Request.Action) void {
        self.last_request_id += 1;
        self.imp_worker.setRequest(.{
            .id = self.last_request_id,


@@ 79,7 79,7 @@ pub const ImpRepl = struct {
            self.last_response = response;
            self.result_editor.buffer.replace(response.text);
            self.result_editor.buffer.language = switch (response.kind) {
                .Ok => .Imp,
                .Ok => .Imp2,
                .Err => .Unknown,
            };
        }

M lib/focus/language.zig => lib/focus/language.zig +9 -9
@@ 3,7 3,7 @@ const focus = @import("../focus.zig");
const u = focus.util;
const c = focus.util.c;
const style = focus.style;
const imp = @import("../../imp/lib/imp.zig");
const imp2 = @import("../../imp2/lib/imp.zig");

pub const Language = enum {
    Zig,


@@ 11,7 11,7 @@ pub const Language = enum {
    Shell,
    Julia,
    Javascript,
    Imp,
    Imp2,
    Unknown,

    pub fn fromFilename(filename: []const u8) Language {


@@ 26,15 26,15 @@ pub const Language = enum {
            return .Julia
        else if (std.mem.endsWith(u8, filename, ".js"))
            return .Javascript
        else if (std.mem.endsWith(u8, filename, ".imp"))
            return .Imp
        else if (std.mem.endsWith(u8, filename, ".imp2"))
            return .Imp2
        else
            return .Unknown;
    }

    pub fn commentString(self: Language) ?[]const u8 {
        return switch (self) {
            .Zig, .Java, .Javascript, .Imp => "//",
            .Zig, .Java, .Javascript, .Imp2 => "//",
            .Shell, .Julia => "#",
            .Unknown => null,
        };


@@ 84,14 84,14 @@ pub const Language = enum {
                    }
                }
            },
            .Imp => {
            .Imp2 => {
                var arena = u.ArenaAllocator.init(allocator);
                defer arena.deinit();
                var error_info: ?imp.lang.pass.parse.ErrorInfo = null;
                var parser = imp.lang.pass.parse.Parser{
                var error_info: ?imp2.lang.pass.parse.ErrorInfo = null;
                var parser = imp2.lang.pass.parse.Parser{
                    .arena = &arena,
                    .source = source[extended_range[0]..extended_range[1]],
                    .exprs = u.ArrayList(imp.lang.repr.syntax.Expr).init(arena.allocator()),
                    .exprs = u.ArrayList(imp2.lang.repr.syntax.Expr).init(arena.allocator()),
                    .from_source = u.ArrayList([2]usize).init(arena.allocator()),
                    .position = 0,
                    .error_info = &error_info,