diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..679fd4b --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,92 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL Advanced" + +on: + push: + branches: [ "main", "canarary", "preview" ] + pull_request: + branches: [ "main", "canarary", "preview" ] + schedule: + - cron: '32 20 * * 2' + +jobs: + analyze: + name: Analyze (${{ matrix.language }}) + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners (GitHub.com only) + # Consider using larger runners or machines with greater resources for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + permissions: + # required for all workflows + security-events: write + + # required to fetch internal or private CodeQL packs + packages: read + + # only required for workflows in private repositories + actions: read + contents: read + + strategy: + fail-fast: false + matrix: + include: + - language: python + build-mode: none + # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' + # Use `c-cpp` to analyze code written in C, C++ or both + # Use 'java-kotlin' to analyze code written in Java, Kotlin or both + # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both + # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis, + # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning. + # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how + # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + build-mode: ${{ matrix.build-mode }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + # If the analyze step fails for one of the languages you are analyzing with + # "We were unable to automatically build your code", modify the matrix above + # to set the build mode to "manual" for that language. Then modify this step + # to build your code. + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + - if: matrix.build-mode == 'manual' + shell: bash + run: | + echo 'If you are using a "manual" build mode for one or more of the' \ + 'languages you are analyzing, replace this with the commands to build' \ + 'your code, for example:' + echo ' make bootstrap' + echo ' make release' + exit 1 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/pyre.yml b/.github/workflows/pyre.yml new file mode 100644 index 0000000..faa77b6 --- /dev/null +++ b/.github/workflows/pyre.yml @@ -0,0 +1,46 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# This workflow integrates Pyre with GitHub's +# Code Scanning feature. +# +# Pyre is a performant type checker for Python compliant with +# PEP 484. Pyre can analyze codebases with millions of lines +# of code incrementally – providing instantaneous feedback +# to developers as they write code. +# +# See https://pyre-check.org + +name: Pyre + +on: + workflow_dispatch: + push: + branches: [ "main", "canarary", "preview" ] + pull_request: + branches: [ "main", "canarary", "preview" ] + +permissions: + contents: read + +jobs: + pyre: + permissions: + actions: read + contents: read + security-events: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Run Pyre + uses: facebook/pyre-action@60697a7858f7cc8470d8cc494a3cf2ad6b06560d + with: + # To customize these inputs: + # See https://github.com/facebook/pyre-action#inputs + repo-directory: './' + requirements-path: 'requirements.txt' diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..18d3afd --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,71 @@ +# This workflow will upload a Python Package to PyPI when a release is created +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Upload Python Package + +on: + release: + types: [published] + +permissions: + contents: read + +jobs: + release-build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.10" + + - name: Build release distributions + run: | + # NOTE: put your own distribution build steps here. + python -m pip install build + python -m build --init + + - name: Upload distributions + uses: actions/upload-artifact@v4 + with: + name: release-dists + path: dist/ + + pypi-publish: + runs-on: ubuntu-latest + needs: + - release-build + permissions: + # IMPORTANT: this permission is mandatory for trusted publishing + id-token: write + + # Dedicated environments with protections for publishing are strongly recommended. + # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules + environment: + name: pypi + # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status: + # url: https://pypi.org/p/YOURPROJECT + # + # ALTERNATIVE: if your GitHub Release name is the PyPI project version string + # ALTERNATIVE: exactly, uncomment the following line instead: + # url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }} + + steps: + - name: Retrieve release distributions + uses: actions/download-artifact@v4 + with: + name: release-dists + path: dist/ + + - name: Publish release distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: dist/ + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ef86222 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Andres Bautista + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..68d2072 --- /dev/null +++ b/README.md @@ -0,0 +1,165 @@ +# UniLang Script (ULS) Interpreter + +**UniLang Script (ULS)** is a simple, interpreted programming language designed for beginners. It draws inspiration from Python and JavaScript, striving to provide a straightforward, accessible environment for learning fundamental programming concepts. + +## Features + +- **Beginner-Friendly Syntax:** + ULS uses braces `{}` to denote code blocks and supports both line breaks and optional semicolons `;` as statement separators. + +- **Familiar Data Types:** + - **Numbers:** `int` and `float` + - **Strings:** `"Hello, World!"` (with escape sequences) + - **Booleans:** `true`, `false` + - **Lists:** `[1, 2, 3]` or `["apple", "banana"]` + - **Triple-Quoted Strings:** `"""Multi-line text here..."""` + +- **Control Structures:** + - `if/else` conditions + - `while` loops + - `for i in range(...)` loops + - `break` to exit loops + +- **Functions:** + Define and call functions: + ```uls + define greet(name) { + result "Hello, " + name + "!" + } + + print(greet("ULS User")) + ``` + +- **Built-in Functions:** + - **I/O:** `print()`, `input()` + - **Conversions:** `str()`, `int()`, `float()` + - **Math & Utilities:** `abs()`, `round()`, `min()`, `max()`, `sqrt()`, `pow()`, `sin()`, `cos()`, `tan()`, `log()` + - **Strings:** `replace()`, `upper()`, `lower()`, `capitalize()`, `find()`, `substring()`, `split()`, `join()` + - **Lists:** `append()`, `remove()`, `len()`, `sum()`, `any()`, `all()`, `sorted()`, `reverse()`, `random_choice()`, `random_shuffle()` + - **Random:** `randomint(min, max)` + - **Date/Time:** `current_time()`, `current_date()` + - **File I/O:** `read_file()`, `write_file()`, `append_file()` + - **Networking:** `http_get(url)` + +- **Advanced Features:** + - `eval(code)`: Execute ULS code at runtime. + - `python_eval(expr)`: Evaluate a Python expression at runtime (for trusted code only). + - `try/except/finally` blocks for basic exception handling. + - Optional semicolon `;` as a statement separator. + - Escape sequences in strings (`\n`, `\t`, etc.) and support for ANSI codes in strings if the terminal supports them. + +- **Empty `print()` for New Lines:** + Just call `print()` with no arguments to print a blank line. + +## Installation + +1. **Requirements:** + - Python or PyPy + - `ply` and `colorama` Python packages + - `requests` for `check_for_update()` function + + If any dependencies are missing, which are later automatially installed if they are, you can manually run: + ```bash + pip install ply colorama requests + ``` + +2. **Clone the Repo:** + ```bash + git clone https://github.com/UN7X/unilang.git + cd unilang + ``` + +3. **Initialize the Interpreter:** + ```bash + pypy interpreter.py --init + ``` + + Or use Python if PyPy is not available: + ```bash + python interpreter.py --init + ``` + +4. **Run the Interpreter:** + (PyPy) + ```bash + pypy interpreter.py example_scripts/test_features.uls + ``` + (Python) + ```bash + python interpreter.py example_scripts/test_features.uls + ``` + +## Usage + +- **Run a Script:** + ```bash + pypy interpreter.py my_script.uls + ``` + +- **Show the Manual:** + ```bash + pypy interpreter.py --man + pypy interpreter.py --man 3 + ``` + Use `--man ` to navigate the included manual pages. + +- **About:** + ```bash + pypy interpreter.py --about + ``` + +- **Init (First-Time Setup OR changes made to the Interpreter itself):** + ```bash + pypy interpreter.py --init + ``` + +- **Check for Updates:** + ```bash + pypy interpreter.py --check + ``` + +## Example + +```uls +# example.uls +x = 10 +if (x > 5) { + print("x is greater than 5") +} else { + print("x is 5 or less") +} + +lst = [1, 2, 3] +append(lst, 4) +print("List after append: " + str(lst)) # [1, 2, 3, 4] + +# Using a function +define add(a, b) { + result a + b +} +print(add(5,7)) # 12 + +# File I/O example: +write_file("out.txt", "Hello, ULS!") +print(read_file("out.txt")) +``` + +Run it: +```bash +pypy interpreter.py example.uls +``` + +## Development + +Contributions are welcome! Key areas that might need improvement: +- More robust escape sequence handling in strings. +- Better error messages and debugging tools. +- More built-in functions or libraries. + +## License + +This project is licensed under the MIT License. See [LICENSE](LICENSE) for details. + +## Contact + +For questions or suggestions, open an issue on GitHub or visit [https://un7x.net/unilang-script](https://un7x.net/unilang-script). (Site WIP)