Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honor the -w flag in REPL mode. #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Sep 21, 2023

  1. Honor the -w flag in REPL mode.

    Right now, `-w` (write-decls-and-statements) is only used when gomacro
    is called with file arguments.  But it might be useful to save a
    record of what was run for interactive mode as well.  For instance,
    you might want to play around with some code interactively, save the
    results, and then use that as the basis of writing a script.
    
    This PR makes it so `-w` is respected when run as a REPL.  In the
    existing (file-based) usage, the output of `-w` is based on the
    filename.  For the new, REPL case there's nothing to base the ouptut
    filename on, so I just hard-code a name.
    
    Test plan:
    I ran the following:
    ```
    gomacro% go run . -w
    // Welcome to gomacro. Type :help for help, :copy for copyright and license.
    // This is free software with ABSOLUTELY NO WARRANTY.
    gomacro> func() { return 5; }
    repl.go:1:8: expected 'IDENT', found '{'
    gomacro> func a() { return 5; }
    return: expecting 0 expressions, found 1: return 5
    gomacro> a := func() int { return 5 }
    gomacro> :exit
    
    gomacro% cat repl.go
    // -------------------------------------------------------------
    // DO NOT EDIT! this file was generated automatically by gomacro
    // Any change will be lost when the file is re-generated
    // -------------------------------------------------------------
    
    // REPL run: 2023-09-21T13:42:27-07:00
    package main
    
    func a() { return 5 }
    var a = func() { return 5 }
    var a = func() int { return 5 }
    ```
    which shows that the declarations are being saved and emitted as
    expected.
    csilvers committed Sep 21, 2023
    Configuration menu
    Copy the full SHA
    6fcff33 View commit details
    Browse the repository at this point in the history