bare-script


Namebare-script JSON
Version 3.0.11 PyPI version JSON
download
home_pagehttps://github.com/craigahobbs/bare-script
Summarybare-script
upload_time2024-05-02 22:10:58
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/b8/47/cba2e625e352fa731f97cc9ef5c3350e4bb9a17931ffa83fffa24624f647/bare_script-3.0.11.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.11",
    "project_urls": {
        "Homepage": "https://github.com/craigahobbs/bare-script"
    },
    "split_keywords": [
        "bare-script"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "07252ed1d75cb5800ee19d757041f50f30c9326e5e52defc9c3b171b3969ddc7",
                "md5": "c0607c44ac81b2a84bbce66acef148f1",
                "sha256": "ede0fa185e1988e763af43194d454e4debd67a5d3930a8985a54a957b8a8bb73"
            },
            "downloads": -1,
            "filename": "bare_script-3.0.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c0607c44ac81b2a84bbce66acef148f1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 41998,
            "upload_time": "2024-05-02T22:10:57",
            "upload_time_iso_8601": "2024-05-02T22:10:57.030884Z",
            "url": "https://files.pythonhosted.org/packages/07/25/2ed1d75cb5800ee19d757041f50f30c9326e5e52defc9c3b171b3969ddc7/bare_script-3.0.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b847cba2e625e352fa731f97cc9ef5c3350e4bb9a17931ffa83fffa24624f647",
                "md5": "f54770a2fbb5f68a3b4e0732601b2fd1",
                "sha256": "52500e325c1a48ccef3d65e7f4a85ed6d4b26c8a623fb8150c091c3acf9b0526"
            },
            "downloads": -1,
            "filename": "bare_script-3.0.11.tar.gz",
            "has_sig": false,
            "md5_digest": "f54770a2fbb5f68a3b4e0732601b2fd1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 39364,
            "upload_time": "2024-05-02T22:10:58",
            "upload_time_iso_8601": "2024-05-02T22:10:58.937966Z",
            "url": "https://files.pythonhosted.org/packages/b8/47/cba2e625e352fa731f97cc9ef5c3350e4bb9a17931ffa83fffa24624f647/bare_script-3.0.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-02 22:10:58",
    "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.24275s