bare-script


Namebare-script JSON
Version 3.0.16 PyPI version JSON
download
home_pagehttps://github.com/craigahobbs/bare-script
Summarybare-script
upload_time2024-11-08 19:03:34
maintainerNone
docs_urlNone
authorCraig A. Hobbs
requires_pythonNone
licenseMIT
keywords bare-script
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # bare-script

[![PyPI - Status](https://img.shields.io/pypi/status/bare-script)](https://pypi.org/project/bare-script/)
[![PyPI](https://img.shields.io/pypi/v/bare-script)](https://pypi.org/project/bare-script/)
[![GitHub](https://img.shields.io/github/license/craigahobbs/bare-script-py)](https://github.com/craigahobbs/bare-script-py/blob/main/LICENSE)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/bare-script)](https://pypi.org/project/bare-script/)

[BareScript](https://craigahobbs.github.io/bare-script/language/)
is a simple, lightweight, and portable programming language. Its Pythonic syntax is influenced by
JavaScript, C, and the Unix Shell. BareScript also has a library of built-in functions for common
programming operations. BareScript can be embedded within applications or used as a stand-alone
programming language using the command-line interface.

There are two implementations of BareScript:
[BareScript for Python](https://github.com/craigahobbs/bare-script-py#readme)
(this package) and
[BareScript for JavaScript](https://github.com/craigahobbs/bare-script#readme).
Both implementations have 100% unit test coverage with identical unit test suites, so you can be
confident that BareScript will execute the same regardless of the underlying runtime environment.


## Links

- [The BareScript Language](https://craigahobbs.github.io/bare-script/language/)
- [The BareScript Library](https://craigahobbs.github.io/bare-script-py/library/)
- [The BareScript Expression Library](https://craigahobbs.github.io/bare-script-py/library/expression.html)
- [API Documentation](https://craigahobbs.github.io/bare-script-py/)
- [Source code](https://github.com/craigahobbs/bare-script-py)


## Executing BareScript Scripts

To execute a BareScript script, parse the script using the
[parse_script](https://craigahobbs.github.io/bare-script-py/scripts.html#parse-script)
function. Then execute the script using the
[execute_script](https://craigahobbs.github.io/bare-script-py/scripts.html#execute-script)
function. For example:

~~~ python
from bare_script import execute_script, parse_script

# Parse the script
script = parse_script('''\
# Double a number
function double(n):
    return n * 2
endfunction

return N + ' times 2 is ' + double(N)
''')

# Execute the script
globals = {'N': 10}
print(execute_script(script, {'globals': globals}))
~~~

This outputs:

~~~
10 times 2 is 20
~~~


### The BareScript Library

[The BareScript Library](https://craigahobbs.github.io/bare-script-py/library/)
includes a set of built-in functions for mathematical operations, object manipulation, array
manipulation, regular expressions, HTTP fetch and more. The following example demonstrates the use
of the
[systemFetch](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='System'&systemfetch),
[objectGet](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='Object'&objectget), and
[arrayLength](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='Array'&arraylength)
functions.

~~~ python
import urllib.request

from bare_script import execute_script, fetch_http, parse_script

# Parse the script
script = parse_script('''\
# Fetch the BareScript library documentation JSON
docs = jsonParse(systemFetch('https://craigahobbs.github.io/bare-script-py/library/library.json'))

# Return the number of library functions
return 'The BareScript Library has ' + arrayLength(objectGet(docs, 'functions')) + ' functions'
''')

# Execute the script
print(execute_script(script, {'fetchFn': fetch_http}))
~~~

This outputs:

~~~
The BareScript Library has 105 functions
~~~


## Evaluating BareScript Expressions

To evaluate a
[BareScript expression](https://craigahobbs.github.io/bare-script/language/#expressions),
parse the expression using the
[parse_expression](https://craigahobbs.github.io/bare-script-py/expressions.html#parse-expression)
function. Then evaluate the expression using the
[evaluate_expression](https://craigahobbs.github.io/bare-script-py/expressions.html#evaluate-expression)
function.

Expression evaluation includes the
[BareScript Expression Library](https://craigahobbs.github.io/bare-script-py/library/expression.html),
a set of built-in, spreadsheet-like functions.

For example:

~~~ python
from bare_script import evaluate_expression, parse_expression

# Parse the expression
expr = parse_expression('2 * max(a, b, c)')

# Evaluate the expression
variables = {'a': 1, 'b': 2, 'c': 3}
print(evaluate_expression(expr, None, variables))
~~~

This outputs:

~~~
6
~~~


## The BareScript Command-Line Interface (CLI)

You can run BareScript from the command line using the BareScript CLI, "bare". BareScript script
files use the ".bare" file extension.

~~~
bare script.bare
~~~

**Note:** In the BareScript CLI, import statements and the
[systemFetch](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='System'&systemfetch)
function read non-URL paths from the local file system.
[systemFetch](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='System'&systemfetch)
calls with a non-URL path and a
[request body](https://craigahobbs.github.io/bare-script-py/library/model.html#var.vName='SystemFetchRequest')
write the body to the path.


## MarkdownUp, a Markdown Viewer with BareScript

[MarkdownUp](https://craigahobbs.github.io/markdown-up/)
is a Markdown Viewer that executes BareScript embedded within Markdown documents.
MarkdownUp includes the
[MarkdownUp Library](https://craigahobbs.github.io/markdown-up/library/),
which extends the
[BareScript Library](https://craigahobbs.github.io/bare-script-py/library/)
with functions for dynamically rendering Markdown text, drawing SVG images, etc.

For example:

```
# Markdown Application

This is a Markdown document with embedded BareScript:

~~~ markdown-script
markdownPrint('Hello, Markdown!')
~~~
```


## Development

This package is developed using [python-build](https://github.com/craigahobbs/python-build#readme).
It was started using [python-template](https://github.com/craigahobbs/python-template#readme) as follows:

~~~
template-specialize python-template/template/ bare-script-py/ -k package bare-script -k name 'Craig A. Hobbs' -k email 'craigahobbs@gmail.com' -k github 'craigahobbs'
~~~

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/craigahobbs/bare-script",
    "name": "bare-script",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "bare-script",
    "author": "Craig A. Hobbs",
    "author_email": "craigahobbs@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/11/bf/16223ea473f406ce829b2ab592c5898326766f10acb165b5f0269a678f5f/bare_script-3.0.16.tar.gz",
    "platform": null,
    "description": "# bare-script\n\n[![PyPI - Status](https://img.shields.io/pypi/status/bare-script)](https://pypi.org/project/bare-script/)\n[![PyPI](https://img.shields.io/pypi/v/bare-script)](https://pypi.org/project/bare-script/)\n[![GitHub](https://img.shields.io/github/license/craigahobbs/bare-script-py)](https://github.com/craigahobbs/bare-script-py/blob/main/LICENSE)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/bare-script)](https://pypi.org/project/bare-script/)\n\n[BareScript](https://craigahobbs.github.io/bare-script/language/)\nis a simple, lightweight, and portable programming language. Its Pythonic syntax is influenced by\nJavaScript, C, and the Unix Shell. BareScript also has a library of built-in functions for common\nprogramming operations. BareScript can be embedded within applications or used as a stand-alone\nprogramming language using the command-line interface.\n\nThere are two implementations of BareScript:\n[BareScript for Python](https://github.com/craigahobbs/bare-script-py#readme)\n(this package) and\n[BareScript for JavaScript](https://github.com/craigahobbs/bare-script#readme).\nBoth implementations have 100% unit test coverage with identical unit test suites, so you can be\nconfident that BareScript will execute the same regardless of the underlying runtime environment.\n\n\n## Links\n\n- [The BareScript Language](https://craigahobbs.github.io/bare-script/language/)\n- [The BareScript Library](https://craigahobbs.github.io/bare-script-py/library/)\n- [The BareScript Expression Library](https://craigahobbs.github.io/bare-script-py/library/expression.html)\n- [API Documentation](https://craigahobbs.github.io/bare-script-py/)\n- [Source code](https://github.com/craigahobbs/bare-script-py)\n\n\n## Executing BareScript Scripts\n\nTo execute a BareScript script, parse the script using the\n[parse_script](https://craigahobbs.github.io/bare-script-py/scripts.html#parse-script)\nfunction. Then execute the script using the\n[execute_script](https://craigahobbs.github.io/bare-script-py/scripts.html#execute-script)\nfunction. For example:\n\n~~~ python\nfrom bare_script import execute_script, parse_script\n\n# Parse the script\nscript = parse_script('''\\\n# Double a number\nfunction double(n):\n    return n * 2\nendfunction\n\nreturn N + ' times 2 is ' + double(N)\n''')\n\n# Execute the script\nglobals = {'N': 10}\nprint(execute_script(script, {'globals': globals}))\n~~~\n\nThis outputs:\n\n~~~\n10 times 2 is 20\n~~~\n\n\n### The BareScript Library\n\n[The BareScript Library](https://craigahobbs.github.io/bare-script-py/library/)\nincludes a set of built-in functions for mathematical operations, object manipulation, array\nmanipulation, regular expressions, HTTP fetch and more. The following example demonstrates the use\nof the\n[systemFetch](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='System'&systemfetch),\n[objectGet](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='Object'&objectget), and\n[arrayLength](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='Array'&arraylength)\nfunctions.\n\n~~~ python\nimport urllib.request\n\nfrom bare_script import execute_script, fetch_http, parse_script\n\n# Parse the script\nscript = parse_script('''\\\n# Fetch the BareScript library documentation JSON\ndocs = jsonParse(systemFetch('https://craigahobbs.github.io/bare-script-py/library/library.json'))\n\n# Return the number of library functions\nreturn 'The BareScript Library has ' + arrayLength(objectGet(docs, 'functions')) + ' functions'\n''')\n\n# Execute the script\nprint(execute_script(script, {'fetchFn': fetch_http}))\n~~~\n\nThis outputs:\n\n~~~\nThe BareScript Library has 105 functions\n~~~\n\n\n## Evaluating BareScript Expressions\n\nTo evaluate a\n[BareScript expression](https://craigahobbs.github.io/bare-script/language/#expressions),\nparse the expression using the\n[parse_expression](https://craigahobbs.github.io/bare-script-py/expressions.html#parse-expression)\nfunction. Then evaluate the expression using the\n[evaluate_expression](https://craigahobbs.github.io/bare-script-py/expressions.html#evaluate-expression)\nfunction.\n\nExpression evaluation includes the\n[BareScript Expression Library](https://craigahobbs.github.io/bare-script-py/library/expression.html),\na set of built-in, spreadsheet-like functions.\n\nFor example:\n\n~~~ python\nfrom bare_script import evaluate_expression, parse_expression\n\n# Parse the expression\nexpr = parse_expression('2 * max(a, b, c)')\n\n# Evaluate the expression\nvariables = {'a': 1, 'b': 2, 'c': 3}\nprint(evaluate_expression(expr, None, variables))\n~~~\n\nThis outputs:\n\n~~~\n6\n~~~\n\n\n## The BareScript Command-Line Interface (CLI)\n\nYou can run BareScript from the command line using the BareScript CLI, \"bare\". BareScript script\nfiles use the \".bare\" file extension.\n\n~~~\nbare script.bare\n~~~\n\n**Note:** In the BareScript CLI, import statements and the\n[systemFetch](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='System'&systemfetch)\nfunction read non-URL paths from the local file system.\n[systemFetch](https://craigahobbs.github.io/bare-script-py/library/#var.vGroup='System'&systemfetch)\ncalls with a non-URL path and a\n[request body](https://craigahobbs.github.io/bare-script-py/library/model.html#var.vName='SystemFetchRequest')\nwrite the body to the path.\n\n\n## MarkdownUp, a Markdown Viewer with BareScript\n\n[MarkdownUp](https://craigahobbs.github.io/markdown-up/)\nis a Markdown Viewer that executes BareScript embedded within Markdown documents.\nMarkdownUp includes the\n[MarkdownUp Library](https://craigahobbs.github.io/markdown-up/library/),\nwhich extends the\n[BareScript Library](https://craigahobbs.github.io/bare-script-py/library/)\nwith functions for dynamically rendering Markdown text, drawing SVG images, etc.\n\nFor example:\n\n```\n# Markdown Application\n\nThis is a Markdown document with embedded BareScript:\n\n~~~ markdown-script\nmarkdownPrint('Hello, Markdown!')\n~~~\n```\n\n\n## Development\n\nThis package is developed using [python-build](https://github.com/craigahobbs/python-build#readme).\nIt was started using [python-template](https://github.com/craigahobbs/python-template#readme) as follows:\n\n~~~\ntemplate-specialize python-template/template/ bare-script-py/ -k package bare-script -k name 'Craig A. Hobbs' -k email 'craigahobbs@gmail.com' -k github 'craigahobbs'\n~~~\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "bare-script",
    "version": "3.0.16",
    "project_urls": {
        "Homepage": "https://github.com/craigahobbs/bare-script"
    },
    "split_keywords": [
        "bare-script"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "75334f2588b71bbc3e712705755a71a48d72831f072d403f813be31063851eac",
                "md5": "7aaf21a1855830fe3acdd2be94ef99c8",
                "sha256": "8b3c1fca5e69ce3a4535415e3a43fd3d12bfb61cb9b54954484c6eea90d544ac"
            },
            "downloads": -1,
            "filename": "bare_script-3.0.16-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7aaf21a1855830fe3acdd2be94ef99c8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 42049,
            "upload_time": "2024-11-08T19:03:33",
            "upload_time_iso_8601": "2024-11-08T19:03:33.609368Z",
            "url": "https://files.pythonhosted.org/packages/75/33/4f2588b71bbc3e712705755a71a48d72831f072d403f813be31063851eac/bare_script-3.0.16-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "11bf16223ea473f406ce829b2ab592c5898326766f10acb165b5f0269a678f5f",
                "md5": "3003957e8f9b718e453791e57459eddf",
                "sha256": "e213143a333f0013423b84b449c7e206013bd3e27fbb73f8a904590dec9fd5a3"
            },
            "downloads": -1,
            "filename": "bare_script-3.0.16.tar.gz",
            "has_sig": false,
            "md5_digest": "3003957e8f9b718e453791e57459eddf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 39432,
            "upload_time": "2024-11-08T19:03:34",
            "upload_time_iso_8601": "2024-11-08T19:03:34.637625Z",
            "url": "https://files.pythonhosted.org/packages/11/bf/16223ea473f406ce829b2ab592c5898326766f10acb165b5f0269a678f5f/bare_script-3.0.16.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-08 19:03:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "craigahobbs",
    "github_project": "bare-script",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "bare-script"
}
        
Elapsed time: 0.57992s