Skip to content
Permalink
Branch: master
Commits on Jun 14, 2019
  1. cmd/shfmt: fix the tests on a terminal

    mvdan committed Jun 14, 2019
    Set the color global as part of main, instead of init. The code can also
    be simpler.
  2. cmd/shfmt: simplify json's handling of pos methods

    mvdan committed Jun 12, 2019
    While at it, give "recurse" a better name.
  3. interp: remove stat module TODO

    mvdan committed Jun 12, 2019
    I can't think of a good use for it right now. We could replace
    OpenModule with an interface that includes some combination of other
    methods like Stat, Lstat, Readlink, and Samefile. However, that would
    complicate the module.
    
    One nice property about the current OpenModule is that, while being
    simple, it allows controlling write access to the system, along with
    ExecModule, since OpenFile is the only call that can modify the
    filesystem.
    
    Let's leave it as it is for v3 for now. If there's a real need for a
    more powerful module in the future, we can always consider it
    separately.
  4. syntax: make SplitBraces work in-place

    mvdan committed Jun 12, 2019
    This makes it consistent with Simplify. Modifying nodes in-place is
    better than generating copies, because most of the time the user doesn't
    need both in memory at once.
    
    In the rare cases that one does have that need, it's always possible to
    print and re-parse the node, as a simple way to do a deep copy.
    
    On the other hand, if the API always makes a full copy by design,
    there's no way to work around that extra garbage generation.
Commits on Jun 5, 2019
  1. interp: gofmt

    mvdan committed Jun 5, 2019
    Forgot to run it, apparently.
  2. interp: expose ExecBuiltin

    mvdan committed Jun 5, 2019
    It's generally useful. Add it to ExampleExecModule too.
  3. interp: refactor the modules API

    mvdan committed Jun 5, 2019
    I never liked the named functions. Moreover, we didn't support chaining
    modules via a list, so it didn't scale well at all.
    
    Another benefit is that we no longer have to add an extra interface, nor
    do we need to declare the default module funcs as variables.
    
    The one disadvantage is that writing some simple modules now requires
    one extra closure level. However, I presume that users will be reading
    or using middlewares more often than writing new ones.
Commits on Jun 4, 2019
  1. syntax: fix nested <<- printer crash

    mvdan committed Jun 4, 2019
    Found by go-fuzz. Instead of relying on the parent to initialise
    tabsPrinter, allocate a new one each time.
    
    This is a bit more wasteful in the common case, but at least it's not
    buggy.
Commits on Jun 3, 2019
  1. syntax: fix escaped newline crash in heredocs

    mvdan committed Jun 3, 2019
    Both with and without quotes.
    
    Found by go-fuzz after our escaped newline refactor.
Commits on Jun 2, 2019
  1. cmd/shfmt: remove StmtList case from -json

    mvdan committed Jun 2, 2019
    Luckily, we got rid of that node type, so we can get rid of this hack.
  2. syntax: refactor how escaped newlines are handled

    mvdan committed Jun 2, 2019
    We used to treat escaped newlines like any other escaped character in
    the lexer. The parser would then deal with them as needed.
    
    This produced inconsistent syntax trees. For example, an escaped newline
    within double quotes should be skipped as per the POSIX Shell spec, but
    we would include it as part of a literal. Then, the expand package would
    be in charge of getting rid of it.
    
    Instead, treat escaped lines especially in the lexer, conforming with
    the spec. Most code gets simpler, particularly in the parser, as it
    doesn't have to deal with skipping and discarding bytes any more. Two
    cases want to keep escaped newlines (single quotes and comments), but
    that's a simple append.
    
    Double-quoted strings now represent escaped newlines by separating the
    parts in different lines, even if the two parts are just *Lit. This is
    enough information for the printer to do the right thing.
    
    Besides the simplification in the lexer and in the code, the syntax tree
    is now closer to what people would expect when wanting to expand or
    interpret it.
    
    Finally, this requires adding another special rune to the lexer. We were
    already using RuneSelf as an EOF rune, so RuneSelf+1 now represents an
    escaped newline.
    
    Fixes #321.
Commits on May 19, 2019
  1. all: properly mark test helpers

    mvdan committed May 19, 2019
  2. syntax: add a parser method for arithmetic expressions

    mvdan committed May 19, 2019
    This is necessary to parse arithmetic expressions at run-time. For
    example:
    
    	expr='1 + 2'
    	echo $(($expr))
    
    The expand package doesn't support this right now, but it might soon.
  3. syntax: don't parse options in DeclClause

    mvdan committed May 19, 2019
    It's impossible to do statically. For example, imagine:
    
    	opts="-a -b"
    	declare $opts name=value
    
    We already support parsing declare arguments at run-time, so do the same
    for options. This unfortunately makes the node less easy to analyze
    statically, but that's just how Bash is designed.
    
    On the plus side, the new design is simpler. Now DeclClause is almost a
    regular builtin via CallExpr, except that it can also contain arrays.
    
    Fixes #332.
Commits on May 18, 2019
  1. syntax: report the use of backquotes in the parser

    mvdan committed May 18, 2019
    It's fine if the printer only supports the $(cmds) form, but the parser
    needs to be able to tell if the source used the deprecated backquotes
    instead.
    
    For example, this is necessary to do proper syntax highlighting, as the
    tokens $( and ` have different lengths.
    
    Fixes #319.
  2. all: apply gofumpt

    mvdan committed May 18, 2019
    And remove a forgotten commented out print.
  3. syntax: don't print any trailing tabs

    mvdan committed May 18, 2019
    Fixes #382.
Commits on Apr 26, 2019
  1. fix minor issue found by staticcheck

    mvdan committed Apr 26, 2019
    Shouldn't be a big deal, as we regularly fuzz the parser and this wasn't
    causing a crash. But the break was still ineffective and confusing.
Commits on Apr 8, 2019
  1. interp: fix Params with only flags

    mvdan committed Apr 8, 2019
    For example, "set -e" is unlike "set foo" or "set --", because it
    shouldn't modify previously set positional parameters.
    
    Thanks to Marcin Bilski for spotting the bug and providing the test
    case.
    
    Fixes #378.
Commits on Apr 5, 2019
  1. README: mention that Go 1.11 isn't strictly required

    mvdan committed Apr 5, 2019
    For #267.
Commits on Mar 31, 2019
  1. make gofumpt happy

    mvdan committed Mar 31, 2019
    Just a stricter gofmt; see mvdan.cc/gofumpt.
Commits on Mar 26, 2019
  1. expand: add support for syntax.BitNegation

    mvdan committed Mar 26, 2019
  2. syntax: add support for the bitwise negation op ~

    mvdan committed Mar 26, 2019
    We supported '!' in arithmetic operations, but we had forgotten about
    '~'. This is a part of POSIX Shell, as seen on
    http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap01.html,
    under "Arithmetic Precision and Operations"
    
    While at it, re-generate stringer code with a new version of stringer,
    which adds the compile-time enum value checks.
    
    Fixes #373.
Commits on Mar 25, 2019
  1. syntax: parse [[ X = Y ]] without changes

    mvdan committed Mar 25, 2019
    The parser used to parse the operator as if the input were [[ X == Y ]],
    since that form is more consistent and there's no reason to use '='
    instead.
    
    However, this was problematic. It was hard to syntax highlight the
    original form, as it was impossible to know what token was used in the
    input without looking at the input bytes directly.
    
    Instead, apply this transformation as part of syntax.Simplify. It's now
    possible to parse and print the original test expression without
    changing the token.
    
    Updates #319.
Commits on Mar 18, 2019
  1. syntax: support coprocs with non-literal names

    mvdan committed Mar 18, 2019
    From the Bash 5.0 release notes:
    
    	h. The name argument to the coproc reserved word now undergoes
    	word expansion, so unique coprocs can be created in loops.
    
    In other words, the name used to just be a name literal, and now can be
    any word which expands to a valid name.
    
    On Bash 4.4:
    
    	$ var=name
    	$ coproc $var { echo foo; }
    	bash4: `$var': not a valid identifier
    
    And on 5.0, we don't get an error:
    
    	$ var=name
    	$ coproc $var { echo foo; }
    
    To adapt to this, simply allow any word in that node field, and not just
    literals. The interp package doesn't yet support this syntax node, so we
    don't have anything else to do.
    
    Fixes #346.
  2. interp: fix TestRunnerResetFields on Windows

    mvdan committed Mar 18, 2019
  3. interp: record runner state at the first Reset call

    mvdan committed Mar 18, 2019
    This is perhaps a bit confusing, but it's a good middle ground. This
    lets us support Reset while not undoing changes that the user has done
    outside of New, which is common.
    
    The downside is that making any changes after the first call to Run or
    Reset are undone by further calls to Reset. However, that's fine; Reset
    is meant to return a runner to its initial state, not any other previous
    or arbitrary state.
  4. interp: don't allow cd and exec to bypass Reset

    mvdan committed Mar 18, 2019
    Much like the last commit, but applied to even more fields.
  5. interp: don't allow the set builtin to bypass Reset

    mvdan committed Mar 18, 2019
    We must keep the original fields somewhere. For now, simply add field
    duplicates to do exactly that.
    
    Fixes #367.
Commits on Mar 15, 2019
  1. syntax: fix reserved words immediately followed by redirects

    mvdan committed Mar 15, 2019
    This was broken due to a small oversight; in the added test case below,
    "fi>/dev/null" would parse similarly to "2>/dev/null", as if "fi" was a
    file descriptor number.
    
    This mistake in the lexer confused the parser, which then proceeded to
    complain about "fi" being missing or displaced.
    
    Fixes #369.
Commits on Mar 14, 2019
  1. syntax: give glob option operators better names

    mvdan committed Mar 14, 2019
    Like in previous commits, names which describe what the operators do.
    
    Fixes #345.
  2. syntax: give better names to some param ops

    mvdan committed Mar 14, 2019
    The eight param substitution variants combining ':' with '+', '-', '?',
    and '=', now have descriptive names.
    
    Updates #345.
  3. syntax: give better names to Quest and Colon

    mvdan committed Mar 14, 2019
    These arithmetic operators are only used for ternary expressions, so
    call them TernQuest and TernColon.
    
    Updates #345.
Commits on Mar 13, 2019
  1. interp: deduplicate some of the test code

    mvdan committed Mar 13, 2019
Commits on Mar 12, 2019
  1. syntax: get rid of StmtList

    mvdan committed Mar 12, 2019
    Its main purpose was to easily share two fields and a few methods across
    the entire syntax package, meaning we wouldn't need to have the same
    pairs of fields in a dozen structs.
    
    However, this leaks into the API and makes it ugly. Composite literals
    get more complex, and we add the complexity of promoted fields to most
    of the nodes.
    
    This is also a problem when exposing the syntax package to other
    languages. For example, JavaScript has no promoted fields, so all
    accesses to statement lists had to be explicit and verbose.
    
    Instead, get rid of the indirection. The internal syntax code gets
    slightly more verbose, but also simpler. And most importantly,
    practically all users of the syntax package get their code slightly
    simplified.
Older
You can’t perform that action at this time.