Skip to content

Commit 9fbaad8

Browse files
committed
Update documentation, add syntax highlighting
1 parent cff9b35 commit 9fbaad8

File tree

14 files changed

+682
-38
lines changed

14 files changed

+682
-38
lines changed
File renamed without changes.
File renamed without changes.

OWScript.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import argparse
2+
import os
3+
import re
4+
import sys
5+
from antlr4 import *
6+
from src.OWScriptLexer import OWScriptLexer
7+
from src.OWScriptParser import OWScriptParser
8+
from src.ASTBuilder import ASTBuilder
9+
from src.Transpiler import Transpiler
10+
11+
class UppercaseStream(FileStream):
12+
def _loadString(self):
13+
self._index = 0
14+
self.data = [ord(c.upper()) for c in self.strdata]
15+
self._size = len(self.data)
16+
17+
def process(code, minify=False, save=None):
18+
input_stream = UppercaseStream(code, 'utf-8')
19+
lexer = OWScriptLexer(input_stream)
20+
stream = CommonTokenStream(lexer)
21+
parser = OWScriptParser(stream)
22+
ast = ASTBuilder().run(parser.script())
23+
# print(ast)
24+
output = Transpiler().run(ast)
25+
if minify:
26+
output = re.sub(r'[\s\n]*', '', output)
27+
if not save:
28+
sys.stdout.write(output)
29+
else:
30+
with open(save, 'w') as f:
31+
f.write(output)
32+
33+
if __name__ == '__main__':
34+
sys.path.append(os.path.join(os.getcwd(), 'src'))
35+
parser = argparse.ArgumentParser(description='Generate Overwatch Workshop code from OWScript')
36+
parser.add_argument('input', nargs='*', type=str, help='Standard input to process')
37+
parser.add_argument('-m', '--min', action='store_true', help='Minifies the output by removing whitespace')
38+
parser.add_argument('-s', '--save', help='Save the output to a file instead of printing it')
39+
args = parser.parse_args()
40+
if not args.input:
41+
process(sys.stdin)
42+
for file in args.input:
43+
process(file, minify=args.min, save=args.save)

README.md

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,40 @@ Python-like scripting language which transpiles into Overwatch Workshop script r
33

44
## Setup
55
Installation
6-
====================
6+
============
77
1. Install Python with `pip` if you have not done so already.
88
2. Install the requirements using `pip install -r requirements.txt` on your machine.
9-
3. ~Run the command `python owscript.py <filename>` to convert a file into workshop rules.~
9+
3. Run the command `python OWScript.py` with the following arguments:
10+
- `input` Path to input file, blank for stdin
11+
- `-m | --min` Optional: minifies the output by stripping whitespace
12+
- `-s | --save [FILE]` Optional: saves to the target output file instead of stdout
13+
14+
## Syntax Highlighting
15+
In the `Syntax/` folder, you can find the raw Iro code which I used to generate a Sublime Text file with modifications. You can directly import the `OWScript.sublime-syntax` file by putting it in your ST3 `User` folder.
1016

1117
## Documentation
12-
*See example code in the `Examples/` folder. `.ows` files are input, `.ow` files are output.*
18+
*See example code in the `Examples/` folder.*
19+
Input File: `*.owpy`
20+
Output File: `*.ows` (standard as agreed upon voting results)
21+
22+
**Semantic**
1323
* [Values / Actions](#values--actions)
1424
* [Annotations / Comments](#annotations--comments)
1525
* [Assignment / Arithmetic](#assignment--arithmetic)
1626
* [Logic](#logic)
17-
* Data Types & Structures
18-
* [Variables](#variables)
19-
* [Strings](#strings)
20-
* [Vectors](#vectors)
21-
* [Time](#time)
22-
* [Arrays](#arrays)
2327
* [Functions](#functions)
2428
* [Loops](#loops)
2529

30+
**Data Types & Structures**
31+
* [Variables](#variables)
32+
* [Strings](#strings)
33+
* [Vectors](#vectors)
34+
* [Time](#time)
35+
* [Arrays](#arrays)
36+
2637
## Notes
2738
- Be sure not to conflict variable/function names with built-in functions such as `Add`, `Wait`, or `Damage`.
39+
- Many commonly used values have been aliased in order to reduce verbosity. See the table at the bottom for the list of built-in aliases.
2840

2941
Values / Actions
3042
================
@@ -65,7 +77,8 @@ x = x ^ (x + x) % 3
6577

6678
Logic
6779
=====
68-
Boolean logic is implemented exactly as in Python. The operators `and`, `or`, and `not` function as C-style `&&`, `||`, and `!`. Comparison operators include the traditional `<`, `>`, `<=`, `>=`, `!=`, `==` as well as containment operators `in` and `not in`.
80+
Boolean logic is implemented exactly as in Python. The operators `and`, `or`, and `not` function as C-style `&&`, `|
81+
|`, and `!`. Comparison operators include the traditional `<`, `>`, `<=`, `>=`, `!=`, `==` as well as containment operators `in` and `not in`.
6982
```
7083
x = True and not True
7184
Count Of
@@ -207,4 +220,24 @@ The while loop is syntactic sugar for using the `Loop` action in the Workshop. A
207220
```
208221
while pvar life > 10:
209222
Damage(Event Player, Null, 10)
210-
```
223+
```
224+
225+
## Alias Table
226+
|Alias|Output|
227+
|-----|------|
228+
|Abs|Absolute Value|
229+
|Any True|Is True For Any|
230+
|All True|Is True For All|
231+
|Cos|Cosine From Degrees|
232+
|Cosr|Cosine From Radians|
233+
|Cur Elem|Current Array Element|
234+
|Everyone|All Players(Team(All))|
235+
|Index|Index Of Array Value|
236+
|Lucio|Lúcio|
237+
|On Each Player|Ongoing - Each Player|
238+
|On Global|Ongoing - Global|
239+
|Players In Radius|Players Within Radius|
240+
|Round|Round To Integer|
241+
|Sin|Sine From Degrees|
242+
|Sinr|Sine From Radians|
243+
|Torbjorn|Torbjörn|

0 commit comments

Comments
 (0)