Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix and refactor main program.
- Loading branch information
Andy Chu
committed
Nov 1, 2020
1 parent
8f82981
commit 81a79a5
Showing
12 changed files
with
163 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Tea Language | ||
============ | ||
|
||
This is an experiment! Background: | ||
|
||
- <http://www.oilshell.org/blog/2020/10/big-changes.html#appendix-the-tea-language> | ||
- <https://old.reddit.com/r/ProgrammingLanguages/comments/jb5i5m/help_i_keep_stealing_features_from_elixir_because/g8urxou/> | ||
- <https://lobste.rs/s/4hx42h/assorted_thoughts_on_zig_rust#c_mqpg6e> | ||
|
||
tl;dr Tea is a cleanup of Oil's metalanguages, which can be called "statically | ||
typed Python with sum types". (Zephyr ASDL is pretty clean, but mycpp is | ||
messy, and needs cleanup.) | ||
|
||
- Tea Grammar: <https://github.com/oilshell/oil/blob/master/oil_lang/grammar.pgen2#L363> | ||
- Tea ASDL Schema: <https://github.com/oilshell/oil/blob/master/frontend/syntax.asdl#L324> | ||
|
||
## Testing | ||
|
||
This is currently run in the continuous build | ||
(<http://travis-ci.oilshell.org/jobs/>). | ||
|
||
tea/run.sh travis | ||
|
||
## Demo | ||
|
||
$ bin/oil -O parse_tea -n -c 'data Point(x Int, y Int)' | ||
|
||
TODO: `bin/tea -c`. | ||
|
||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Usage: | ||
# ./run.sh <function name> | ||
|
||
set -o nounset | ||
set -o pipefail | ||
set -o errexit | ||
|
||
tea-files() { | ||
find tea/testdata -name '*.tea' | ||
} | ||
|
||
parse-all-tea() { | ||
# Parse with the Oil binary | ||
tea-files | xargs -n 1 -- bin/oil -O parse_tea -n | ||
|
||
# Standalone tea parser | ||
tea-files | xargs -n 1 -- bin/tea | ||
} | ||
|
||
travis() { | ||
parse-all-tea | ||
} | ||
|
||
"$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env python2 | ||
""" | ||
tea_main.py | ||
""" | ||
from __future__ import print_function | ||
|
||
import sys | ||
|
||
from _devbuild.gen.option_asdl import option_i | ||
from _devbuild.gen.syntax_asdl import source | ||
from frontend import parse_lib | ||
from frontend import reader | ||
from core import alloc | ||
from core import error | ||
from core import optview | ||
from core import pyutil | ||
from core.pyutil import stderr_line | ||
from core import state | ||
from core import ui | ||
from mycpp import mylib | ||
|
||
import posix_ as posix | ||
|
||
from typing import List, Dict, cast, TYPE_CHECKING | ||
if TYPE_CHECKING: | ||
from frontend import args | ||
|
||
|
||
def Main(arg_r): | ||
# type: (args.Reader) -> int | ||
""" | ||
Usage: | ||
tea myprog.tea # Run the script | ||
tea -c 'func main() { echo "hi" }' # Run this snippet. Not common since | ||
# there's no top level statementes! | ||
# Use bin/oil for that. | ||
tea -n -c 'var x = 1' # Parse it | ||
# Compile to C++. Produce myprog.cc and myprog.h. | ||
tea --cpp-out myprog myprog.tea lib.tea | ||
""" | ||
argv = arg_r.Rest() | ||
arena = alloc.Arena() | ||
try: | ||
script_name = argv[0] | ||
arena.PushSource(source.MainFile(script_name)) | ||
except IndexError: | ||
arena.PushSource(source.Stdin()) | ||
f = mylib.Stdin() # type: mylib.LineReader | ||
else: | ||
try: | ||
# Hack for type checking. core/shell.py uses fd_state.Open(). | ||
f = cast('mylib.LineReader', open(script_name)) | ||
except IOError as e: | ||
stderr_line("tea: Couldn't open %r: %s", script_name, | ||
posix.strerror(e.errno)) | ||
return 2 | ||
|
||
# Dummy value; not respecting aliases! | ||
aliases = {} # type: Dict[str, str] | ||
|
||
loader = pyutil.GetResourceLoader() | ||
oil_grammar = pyutil.LoadOilGrammar(loader) | ||
|
||
# Not used in tea, but OK... | ||
opt0_array = state.InitOpts() | ||
no_stack = None # type: List[bool] # for mycpp | ||
opt_stacks = [no_stack] * option_i.ARRAY_SIZE # type: List[List[bool]] | ||
parse_opts = optview.Parse(opt0_array, opt_stacks) | ||
|
||
# parse `` and a[x+1]=bar differently | ||
parse_ctx = parse_lib.ParseContext(arena, parse_opts, aliases, oil_grammar) | ||
|
||
line_reader = reader.FileLineReader(f, arena) | ||
|
||
try: | ||
parse_ctx.ParseTeaModule(line_reader) | ||
status = 0 | ||
except error.Parse as e: | ||
ui.PrettyPrintError(e, arena) | ||
status = 2 | ||
|
||
return status |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
./core/shell.py | ||
./osh/builtin_process.py | ||
#./osh/builtin_comp.py | ||
./tea/tea_main.py |