src: Move all source code to src/newlang

The Python ecosystem works much better if we deicide our source code
is actually a module named 'newlang'.

I've been putting off changing this for a long time, but I might as
well do it now.
This commit is contained in:
Jookia 2023-02-13 23:41:05 +11:00
parent b4bdf2afc0
commit 2904a6f7f2
Signed by: Jookia
SSH key fingerprint: SHA256:/gEvgms/9HpbgpcH+K7O4GYXmqkP7siJx9zHeEWRZTg
34 changed files with 61 additions and 57 deletions

View file

@ -38,7 +38,7 @@ def close_file(file):
def find_all_src(srcpath):
paths = srcpath.glob("**/*")
paths = srcpath.rglob("*")
new_paths = [srcpath]
for p in paths:
if "__pycache__" in p.as_posix():
@ -57,33 +57,33 @@ def write_zip_entry(zip, name, data, date):
def write_main(zip, date):
name = "__main__.py"
data = "import src.main\nsrc.main.wait_main()"
data = "import newlang.main\nnewlang.main.wait_main()"
write_zip_entry(zip, name, data, date)
def write_dir(zip, path, date):
def write_dir(zip, path, name, date):
# For some reason Python needs empty files with the names of directories ending in /
name = path.as_posix() + "/"
name = name + "/"
data = ""
write_zip_entry(zip, name, data, date)
def write_file(zip, path, date):
def write_file(zip, path, name, date):
file = path.open("rb")
data = file.read()
new_data = data.replace(b"\r\n", b"\n")
file.close()
name = path.as_posix()
write_zip_entry(zip, name, new_data, date)
def write_src(zip, date):
srcs = sorted(find_all_src(pathlib.Path("src")))
srcs = sorted(find_all_src(pathlib.Path("src/newlang")))
for p in srcs:
name = p.relative_to("src").as_posix()
if p.is_dir():
write_dir(zip, p, date)
write_dir(zip, p, name, date)
else:
write_file(zip, p, date)
write_file(zip, p, name, date)
def main():

View file

@ -30,6 +30,8 @@ Function Setup {
If (Test-Path -Path venv\.stamp) { Activate } Else { Setup }
$env:PYTHONPATH += ";$PWD\src";
# NOTE: PowerShell functions always return success even if the commands inside
# failed. This makes it infeasible to do proper error checking.
# See https://github.com/PowerShell/PowerShell/issues/12218

2
env.sh
View file

@ -23,6 +23,8 @@ setup() {
if test -e venv/.stamp; then activate; else setup; fi
export PYTHONPATH="$PYTHONPATH:$PWD/src"
unset -f activate die setup
resetenv() { rm -r venv; . ./env.sh; }

4
run.py
View file

@ -2,5 +2,5 @@
# SPDX-License-Identifier: LGPL-2.1-only
# Copyright 2022 Jookia <contact@jookia.org>
import src.main
src.main.wait_main()
import newlang.main
newlang.main.wait_main()

View file

@ -1,7 +1,7 @@
# SPDX-License-Identifier: LGPL-2.1-only
# Copyright 2021 Jookia <contact@jookia.org>
from src import ast_types
from newlang import ast_types
import sys

View file

@ -4,12 +4,12 @@
import os
import sys
from src import port
from src import log
from src.parse2 import tokenize as tokenize2
from src.parse2 import parse as parse2
from src import parse
from src import interp
from newlang import port
from newlang import log
from newlang.parse2 import tokenize as tokenize2
from newlang.parse2 import parse as parse2
from newlang import parse
from newlang import interp
def run_file(file, log_level=log.NORMAL):

View file

@ -1,8 +1,8 @@
# SPDX-License-Identifier: LGPL-2.1-only
# Copyright 2021 Jookia <contact@jookia.org>
from src import log
from src import ast_types
from newlang import log
from newlang import ast_types
class ParseLocation:

View file

@ -1,9 +1,9 @@
# SPDX-License-Identifier: LGPL-2.1-only
# Copyright 2022 Jookia <contact@jookia.org>
from src.i18n import Message
from src.ast_types import Bool, Conditional, Reference, Set, Statement, Text
from src.parse2.token import TokenStream
from newlang.i18n import Message
from newlang.ast_types import Bool, Conditional, Reference, Set, Statement, Text
from newlang.parse2.token import TokenStream
# Words that can't be used as references

View file

@ -1,7 +1,7 @@
# SPDX-License-Identifier: LGPL-2.1-only
# Copyright 2022 Jookia <contact@jookia.org>
from src.parse2.token import Token, TokenLocation
from newlang.parse2.token import Token, TokenLocation
# Valid space code points
spaces = [

View file

@ -1 +1 @@
# Dummy file to help pytest find the src module
# Dummy file to help pytest find the tests module

View file

@ -3,8 +3,8 @@
from hypothesis.strategies import composite, integers
from src.parse2.parse import ParseErrorException
from src.parse2.token import TokenStream
from newlang.parse2.parse import ParseErrorException
from newlang.parse2.token import TokenStream
from tests.parse2.test_token import static_token_by_value

View file

@ -4,8 +4,8 @@
from hypothesis import assume, given
from hypothesis.strategies import composite
from src.ast_types import Bool
from src.parse2.parse import (
from newlang.ast_types import Bool
from newlang.parse2.parse import (
ParseContext,
ParseError,
ParseErrorException,

View file

@ -16,14 +16,14 @@
from hypothesis import given
from hypothesis.strategies import composite, just, lists, one_of
from src.parse2.parse import (
from newlang.parse2.parse import (
clear_notes,
ParseContext,
ParseError,
ParseErrorException,
ParseTask,
)
from src.parse2.token import TokenStream
from newlang.parse2.token import TokenStream
from tests.parse2.templates import template_test_invalid
from tests.parse2.test_error import static_parse_context
from tests.parse2.test_note import (

View file

@ -39,8 +39,8 @@ import enum
from hypothesis import assume, given
from hypothesis.strategies import composite, data, integers, just, one_of
from src.ast_types import Conditional
from src.parse2.parse import (
from newlang.ast_types import Conditional
from newlang.parse2.parse import (
ParseContext,
ParseError,
ParseErrorException,

View file

@ -26,7 +26,7 @@ import enum
from hypothesis import given
from hypothesis.strategies import composite, just, one_of
from src.parse2.parse import (
from newlang.parse2.parse import (
ParseContext,
ParseError,
ParseErrorException,
@ -42,7 +42,7 @@ from tests.parse2.test_token import (
static_token_by_value,
)
from tests.parse2.test_error import static_parse_context
from src.ast_types import Bool, Statement
from newlang.ast_types import Bool, Statement
#
# Helper functions

View file

@ -27,8 +27,8 @@
from hypothesis import given
from hypothesis.strategies import composite, integers, sampled_from, text
from src.i18n import Message
from src.parse2.parse import (
from newlang.i18n import Message
from newlang.parse2.parse import (
ParseContext,
ParseError,
ParseErrorException,

View file

@ -15,8 +15,8 @@
from hypothesis import given
from hypothesis.strategies import composite, just, lists
from src.parse2.token import TokenStream
from src.parse2.parse import (
from newlang.parse2.token import TokenStream
from newlang.parse2.parse import (
ParseContext,
ParseTask,
parse_file,

View file

@ -21,7 +21,7 @@ from hypothesis.strategies import (
lists,
)
from src.parse2.parse import (
from newlang.parse2.parse import (
skip_note,
ParseContext,
ParseError,

View file

@ -4,13 +4,13 @@
from hypothesis import given
from hypothesis.strategies import lists
from src.parse2.parse import (
from newlang.parse2.parse import (
clear_notes,
ParseErrorException,
parse,
parse_file,
)
from src.parse2.token import TokenStream
from newlang.parse2.token import TokenStream
from tests.parse2.test_token import draw_token_random
from tests.parse2.test_error import draw_parse_context

View file

@ -4,8 +4,8 @@
from hypothesis import given
from hypothesis.strategies import composite
from src.ast_types import Reference
from src.parse2.parse import (
from newlang.ast_types import Reference
from newlang.parse2.parse import (
ParseContext,
ParseError,
ParseErrorException,

View file

@ -36,8 +36,8 @@ import enum
from hypothesis import assume, given
from hypothesis.strategies import composite, data, integers
from src.ast_types import Set
from src.parse2.parse import (
from newlang.ast_types import Set
from newlang.parse2.parse import (
ParseContext,
ParseError,
ParseErrorException,

View file

@ -6,8 +6,8 @@ import enum
from hypothesis import assume, given
from hypothesis.strategies import composite, integers, lists
from src.ast_types import Statement
from src.parse2.parse import (
from newlang.ast_types import Statement
from newlang.parse2.parse import (
ParseContext,
ParseError,
ParseErrorException,

View file

@ -7,8 +7,8 @@ from hypothesis.strategies import (
lists,
)
from src.ast_types import Text
from src.parse2.parse import (
from newlang.ast_types import Text
from newlang.parse2.parse import (
ParseContext,
ParseError,
ParseErrorException,

View file

@ -12,7 +12,7 @@ from hypothesis.strategies import (
text,
)
from src.parse2.token import Token, TokenLocation, TokenStream
from newlang.parse2.token import Token, TokenLocation, TokenStream
from tests.templates import template_test_structure
# Keywords recognized by the language

View file

@ -13,8 +13,8 @@ from hypothesis.strategies import (
text,
)
from src.parse2 import tokenize
from src.parse2.token import Token, TokenLocation
from newlang.parse2 import tokenize
from newlang.parse2.token import Token, TokenLocation
from tests.parse2.test_token import static_token_location

View file

@ -6,7 +6,7 @@ import enum
from hypothesis import assume, given
from hypothesis.strategies import composite, just, one_of
from src.parse2.parse import (
from newlang.parse2.parse import (
ParseContext,
ParseError,
ParseErrorException,

View file

@ -15,7 +15,7 @@ from hypothesis.strategies import (
text,
)
from src.i18n import Message
from newlang.i18n import Message
from tests.templates import template_test_structure

View file

@ -14,7 +14,7 @@ from hypothesis.strategies import (
just,
)
from src import parse
from newlang import parse
# Whitespace that separates lexer words
lexer_whitespace = "\n\t "

View file

@ -1,7 +1,7 @@
# SPDX-License-Identifier: LGPL-2.1-only
# Copyright 2022 Jookia <contact@jookia.org>
from src import parse
from newlang import parse
# The parser had some logic along the lines of 'read token until whitespace',