Skip to content

Commit

Permalink
Add parse error for [[ -f < ]].
Browse files Browse the repository at this point in the history
Unrelated:

- Remove unnecessary code in osh2oil.
- Minor cleanups of imports
  • Loading branch information
Andy Chu committed Sep 9, 2018
1 parent 6aadc3b commit 923d32d
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 30 deletions.
5 changes: 1 addition & 4 deletions bin/oil.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,7 @@ def OshCommandMain(argv):
# stderr: show how we're following imports?

if action == 'translate':
# TODO: FIx this invocation up.
#debug_spans = opt.debug_spans
debug_spans = False
osh2oil.PrintAsOil(arena, node, debug_spans)
osh2oil.PrintAsOil(arena, node)

elif action == 'arena': # for debugging
osh2oil.PrintArena(arena)
Expand Down
1 change: 0 additions & 1 deletion core/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
- NOTE: GNU getopt has fuzzy matching for long flags. I think we should rely
on good completion instead.
"""

from core import util
Expand Down
4 changes: 1 addition & 3 deletions core/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"""

import os
import signal
import sys

from core import args
Expand Down Expand Up @@ -1034,9 +1035,6 @@ def UnAlias(argv, aliases):
return status


import signal


def _SigIntHandler(unused, unused_frame):
"""
Either this handler is installed, or the user's handler is installed.
Expand Down
2 changes: 0 additions & 2 deletions core/glob_.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ def GlobToERE(pat):
return None, warnings

if 0:
#import sys
#from asdl import format as fmt
print('---')
for p in parts:
print(p)
Expand Down
4 changes: 4 additions & 0 deletions osh/bool_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
except ImportError:
from benchmarks import fake_libc as libc

word_e = ast.word_e
lex_mode_e = types.lex_mode_e
log = util.log
p_die = util.p_die
Expand Down Expand Up @@ -184,6 +185,9 @@ def ParseFactor(self):
op = self.op_id
self._Next()
w = self.cur_word
# e.g. [[ -f < ]]. But [[ -f '<' ]] is OK
if w.tag not in (word_e.CompoundWord, word_e.StringWord):
p_die('Invalid argument to unary operator', word=w)
self._Next()
node = ast.BoolUnary(op, w)
return node
Expand Down
4 changes: 1 addition & 3 deletions osh/lex.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,9 @@
Op_LBracket Op_RBracketEqual
"""

from osh.meta import Id, Kind, ID_SPEC
from osh.meta import types, Id, Kind, ID_SPEC
from core.lexer import C, R

from osh.meta import types

lex_mode_e = types.lex_mode_e


Expand Down
9 changes: 9 additions & 0 deletions scripts/count.sh
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ imports() {
oil-osh-files | xargs grep --no-filename -w import | hist
}

imports-not-at-top() {
oil-osh-files | xargs grep -n -w import | awk -F : ' $2 > 100'
}

# For the compiler, see what's at the top level.
top-level() {
grep '^[a-zA-Z]' {core,osh}/*.py \
Expand Down Expand Up @@ -245,4 +249,9 @@ pickle-bytecodes() {
#show-pickle _devbuild/*_asdl.pickle
}

# Some of these are "abstract classes" like ChildStateChange
NotImplementedError() {
grep NotImplementedError */*.py
}

"$@"
7 changes: 5 additions & 2 deletions spec/dbracket.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ FOO=bar [[ foo == foo ]]
## stdout-json: "false\nfalse\n"

#### Argument that looks like a real operator
[[ -f < ]]
[[ -f < ]] && echo 'should be parse error'
## status: 2
## OK mksh status: 1

Expand Down Expand Up @@ -205,7 +205,10 @@ false
[[ 1+2 -eq 3 ]] && echo true
expr='1+2'
[[ $expr -eq 3 ]] && echo true # must be dynamically parsed
## stdout-json: "true\ntrue\n"
## STDOUT:
true
true
## END

#### -eq coercion produces weird results
[[ '' -eq 0 ]] && echo true
Expand Down
2 changes: 1 addition & 1 deletion test/spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ assoc-zsh() {
# NOTE: zsh passes about half and fails about half. It supports a subset of [[
# I guess.
dbracket() {
sh-spec spec/dbracket.test.sh --osh-failures-allowed 2 \
sh-spec spec/dbracket.test.sh --osh-failures-allowed 1 \
$BASH $MKSH $OSH_LIST "$@"
#sh-spec spec/dbracket.test.sh $BASH $MKSH $OSH_LIST $ZSH "$@"
}
Expand Down
15 changes: 1 addition & 14 deletions tools/osh2oil.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,7 @@ def PrintSpans(arena):
print('(%d spans)' % len(arena.spans), file=sys.stderr)


def PrintAsOil(arena, node, debug_spans):
if len(arena.spans) == 1: # Special case for line_id == -1
# Nothing to print; would crash otherwise.
return

#print node
#print(spans)
if debug_spans:
for i, span in enumerate(arena.spans):
line = arena.GetLine(span.line_id)
piece = line[span.col : span.col + span.length]
print('%5d %r' % (i, piece), file=sys.stderr)
print('(%d spans)' % len(arena.spans), file=sys.stderr)

def PrintAsOil(arena, node):
cursor = Cursor(arena, sys.stdout)
fixer = OilPrinter(cursor, arena, sys.stdout)
fixer.DoCommand(node, None, at_top_level=True) # no local symbols yet
Expand Down

0 comments on commit 923d32d

Please sign in to comment.