Skip to content

Commit

Permalink
[translation] Fix crash translating osh/bool_parse.py and osh/word_.py
Browse files Browse the repository at this point in the history
- Also adjust some code so it translates better.  Still have many
  compile errors.
- fix to make examples/parse translate, compile, and run again

Also:

[doc] Start validating more generated HTML.
  • Loading branch information
Andy Chu committed Nov 13, 2019
1 parent 39a61cd commit 7d586af
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
6 changes: 5 additions & 1 deletion mycpp/examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ typecheck-oil() {
local flags='--no-strict-optional'

set +o errexit
MYPYPATH="$REPO_ROOT" \
MYPYPATH="$REPO_ROOT:$REPO_ROOT/native" \
mypy --py2 --strict $flags examples/$name.py | tee _tmp/err.txt
set -o errexit

Expand Down Expand Up @@ -294,8 +294,12 @@ namespace arith_nt {
$REPO_ROOT/pgen2/parse.py \
$REPO_ROOT/oil_lang/expr_parse.py \
$REPO_ROOT/oil_lang/expr_to_ast.py \
$REPO_ROOT/osh/bool_parse.py \
$REPO_ROOT/osh/word_.py \
examples/$name.py

# TODO: move bool_parse.py elsewhere

compile-pgen2_demo
}

Expand Down
10 changes: 4 additions & 6 deletions osh/bool_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,11 @@

from _devbuild.gen.id_kind_asdl import Id, Kind
from _devbuild.gen.types_asdl import lex_mode_t, lex_mode_e
from _devbuild.gen.syntax_asdl import (
word_t, word__Compound, word__String,
bool_expr, bool_expr_t,
)
from _devbuild.gen.syntax_asdl import word_t, word_e, bool_expr, bool_expr_t
from frontend import lookup
from osh import word_
from core.util import p_die


from typing import List, Optional, TYPE_CHECKING
if TYPE_CHECKING:
from osh.word_parse import WordParser
Expand Down Expand Up @@ -203,7 +199,9 @@ def ParseFactor(self):
self._Next()
w = self.cur_word
# e.g. [[ -f < ]]. But [[ -f '<' ]] is OK
if not isinstance(w, (word__Compound, word__String)):

tag = w.tag_()
if tag != word_e.Compound and tag != word_e.String:
p_die('Invalid argument to unary operator', word=w)
self._Next()
node = bool_expr.Unary(op, w) # type: bool_expr_t
Expand Down
13 changes: 8 additions & 5 deletions osh/word_.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from asdl import runtime
from core import util
from frontend import lookup
from mycpp import mylib

from typing import Tuple, Optional, List, TYPE_CHECKING
if TYPE_CHECKING:
Expand Down Expand Up @@ -648,11 +649,13 @@ def SpanIdFromError(error):
return runtime.NO_SPID


def ErrorWord(fmt, err):
# type: (str, _ErrorWithLocation) -> word__Compound
error_str = fmt % err.UserErrorString()
t = token(Id.Lit_Chars, error_str, runtime.NO_SPID)
return word.Compound([word_part.Literal(t)])
if mylib.PYTHON:
# Doesn't translate with mycpp because of dynamic %
def ErrorWord(fmt, err):
# type: (str, _ErrorWithLocation) -> word__Compound
error_str = fmt % err.UserErrorString()
t = token(Id.Lit_Chars, error_str, runtime.NO_SPID)
return word.Compound([word_part.Literal(t)])


def Pretty(w):
Expand Down
13 changes: 12 additions & 1 deletion test/doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@ validate-html() {
fi
}

manifest() {
find \
_release/VERSION _tmp/unit \
-name '*.html'
# There are a lot of empty <pre></pre> here which I don't care about
# _tmp/spec \
#_tmp/test-opy _tmp/metrics \

# TODO: include benchmarks. Look at devtools/release.sh compress
}

all-html() {
find _release/VERSION -name '*.html' | xargs -n 1 --verbose -- $0 validate-html
manifest | xargs -n 1 --verbose -- $0 validate-html
}

"$@"

0 comments on commit 7d586af

Please sign in to comment.