Skip to content

Commit 698b9be

Browse files
committed
Release 1.0
Core features are implemented and syntax highlighting is working almost perfectly. This is the first version I consider stable enough for a full release.
1 parent 12eb5fc commit 698b9be

File tree

12 files changed

+208
-143
lines changed

12 files changed

+208
-143
lines changed

Examples/conditionals.owpy

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ Rule "If and Else"
1111
y = 3
1212
y = 4
1313
elif x < 1:
14-
z = 1
14+
z = 1
15+
else:
16+
z = 'yes'

Examples/for.owpy

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ Rule "For Loop"
44
Actions
55
angles = [15, 30, 45, 60, 75, 90]
66
angles2 = range(15, 91, 15)
7-
for ang in angles:
8-
Msg(Event Player, ang)
7+
for ang in angles2:
8+
Set Facing
9+
Direction From Angles
10+
horizontal: ang
11+
vertical: 45

Gamemodes/OWClicker.owpy

+94-93
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Reevaluation: Visible To
1717
%UpgradePortal(pos)
1818
Portal(pos, Good Aura, Yellow, "Upgrades")
19-
portals.push(pos)
19+
portals.append(pos)
2020
%ShopPortal(pos)
2121
Portal(pos, Good Aura, Purple, `{0} {1}`("Previous", "Boss"))
2222
shop_portal = pos
@@ -92,95 +92,96 @@ Rule "Initialize Effects (Portals / Upgrades / Boundaries)"
9292
UpgradePortal(<41, 3.5, 78.5>)
9393
UpgradePortal(<-118.5, 1.5, 99.5>)
9494
ShopPortal(<-7.000, 3, 75>)
95-
// 1 -> 2 Modify Global Variable(E, Append To Array, Vector(-55.000, 1.500, 141.500));
96-
// 2 -> 3 Modify Global Variable(E, Append To Array, Vector(-25.500, 7.500, 50.500));
97-
// 3 -> 4 Modify Global Variable(E, Append To Array, Vector(-80.000, 1.500, 71));
98-
// 4 -> 5 Modify Global Variable(E, Append To Array, Vector(-63.000, 2.500, 115.500));
99-
// 5 -> 6 Modify Global Variable(E, Append To Array, Vector(41, 3.500, 67.500));
100-
// prestige: <-172, 3, 96>
101-
// create boundary function
102-
103-
Rule "Initialize Player HUD Stats"
104-
Event_Team(Team 1)
105-
Actions
106-
Hud
107-
Visible_To: Event Player
108-
Header: `{0}: {1}`("Money", pvar money)
109-
Subheader: Null
110-
Text: Null
111-
Location: Top
112-
Sort_Order: 0
113-
Header_Color: White
114-
Subheader_Color: White
115-
Text_Color: White
116-
Reevaluation: Visible To And String
117-
SmallHud(Top, `{0} / {1}`(`{0}: {1}`("Damage", `{0}%`(pvar damage_scale)), `{0}: {1}`("Defend", `{0}%`(pvar defense))), Red)
118-
SmallHud(Top, `{0} sec`(pvar reload_speed), Yellow)
119-
SmallHud(Top, `{0} {1}`(`{0}%`(pvar money_multiplier * 100), "Money"), Green)
120-
//Create In-World Text(All Players(Team 1), String("{0} - {1} - {2}", String("{0}: {1}", String("Damage", Null, Null, Null), String(
121-
// "{0}%", Player Variable(Event Player, B), Null, Null), Null), String("{0} sec", Player Variable(Event Player, E), Null, Null),
122-
// String("{0} {1}", String("{0}%", Multiply(Player Variable(Event Player, J), 100), Null, Null), String("Money", Null, Null,
123-
// Null), Null)), Event Player, 0.750, Clip Against Surfaces, Visible To Position and String);
124-
125-
Rule "Validate Bosses"
126-
Event_Global()
127-
Conditions
128-
All True
129-
boss_heroes
130-
Is Hero Being Played
131-
Cur Elem
132-
Team 2
133-
== False
134-
Actions
135-
Msg
136-
Everyone
137-
`{0}: {1}`
138-
"Warning"
139-
`{0} {1}`
140-
"Bad"
141-
"Bosses"
142-
Wait(2min + 1.5s)
143-
Loop If Condition Is True
144-
145-
Rule "Initialize Bosses"
146-
Event_Global()
147-
Conditions
148-
Is Game In Progress;
149-
Actions
150-
Msg(Everyone, "Go")
151-
SpawnBoss(Roadhog)
152-
SpawnBoss(Soldier: 76)
153-
SpawnBoss(Mei)
154-
SpawnBoss(Lucio)
155-
SpawnBoss(Ana)
156-
SpawnBoss(Reaper)
157-
158-
Rule "Teleport to Shop"
159-
Event_Team(All)
160-
Conditions
161-
Any True
162-
Array: portals
163-
Condition: Distance Between
164-
Event Player
165-
Cur Elem
166-
<= 1.5
167-
== True
168-
Actions
169-
Teleport(Event Player, shop_pos)
170-
pvar location = -1
171-
// Add sound effect
172-
173-
Rule "Teleport from Shop"
174-
Event_Team(All)
175-
Conditions
176-
Distance Between
177-
Event Player
178-
shop_portal
179-
<= 1.5
180-
pvar location == -1
181-
Actions
182-
Msg(Event Player, "Bosses")
183-
Big Msg("Hello")
184-
pvar location = pvar cur_boss
185-
Teleport(Event Player, player_spawns[pvar location])
186-
// Add sound effect
95+
// // 1 -> 2 Modify Global Variable(E, Append To Array, Vector(-55.000, 1.500, 141.500));
96+
// // 2 -> 3 Modify Global Variable(E, Append To Array, Vector(-25.500, 7.500, 50.500));
97+
// // 3 -> 4 Modify Global Variable(E, Append To Array, Vector(-80.000, 1.500, 71));
98+
// // 4 -> 5 Modify Global Variable(E, Append To Array, Vector(-63.000, 2.500, 115.500));
99+
// // 5 -> 6 Modify Global Variable(E, Append To Array, Vector(41, 3.500, 67.500));
100+
// // prestige: <-172, 3, 96>
101+
// // create boundary function
102+
//
103+
//Rule "Initialize Player HUD Stats"
104+
// Event_Team(Team 1)
105+
// Actions
106+
// Hud
107+
// Visible_To: Event Player
108+
// Header: `{0}: {1}`("Money", pvar money)
109+
// Subheader: Null
110+
// Text: Null
111+
// Location: Top
112+
// Sort_Order: 0
113+
// Header_Color: White
114+
// Subheader_Color: White
115+
// Text_Color: White
116+
// Reevaluation: Visible To And String
117+
// SmallHud(Top, `{0} / {1}`(`{0}: {1}`("Damage", `{0}%`(pvar damage_scale)), `{0}: {1}`("Defend", `{0}%`(pvar defense))), Red)
118+
// SmallHud(Top, `{0} sec`(pvar reload_speed), Yellow)
119+
// SmallHud(Top, `{0} {1}`(`{0}%`(pvar money_multiplier * 100), "Money"), Green)
120+
// //Create In-World Text(All Players(Team 1), String("{0} - {1} - {2}", String("{0}: {1}", String("Damage", Null, Null, Null), String(
121+
//// "{0}%", Player Variable(Event Player, B), Null, Null), Null), String("{0} sec", Player Variable(Event Player, E), Null, Null),
122+
//// String("{0} {1}", String("{0}%", Multiply(Player Variable(Event Player, J), 100), Null, Null), String("Money", Null, Null,
123+
//// Null), Null)), Event Player, 0.750, Clip Against Surfaces, Visible To Position and String);
124+
//
125+
//Rule "Validate Bosses"
126+
// Event_Global()
127+
// Conditions
128+
// All True
129+
// boss_heroes
130+
// Is Hero Being Played
131+
// Cur Elem
132+
// Team 2
133+
// == False
134+
// Actions
135+
// Msg
136+
// Everyone
137+
// `{0}: {1}`
138+
// "Warning"
139+
// `{0} {1}`
140+
// "Bad"
141+
// "Bosses"
142+
// Wait(2min + 1.5s)
143+
// Loop If Condition Is True
144+
//
145+
//Rule "Initialize Bosses"
146+
// Event_Global()
147+
// Conditions
148+
// Is Game In Progress;
149+
// Actions
150+
// Msg(Everyone, "Go")
151+
// SpawnBoss(Roadhog)
152+
// SpawnBoss(Soldier: 76)
153+
// SpawnBoss(Mei)
154+
// SpawnBoss(Lucio)
155+
// SpawnBoss(Ana)
156+
// SpawnBoss(Reaper)
157+
//
158+
//Rule "Teleport to Shop"
159+
// Event_Team(All)
160+
// Conditions
161+
// Any True
162+
// Array: portals
163+
// Condition: Distance Between
164+
// Event Player
165+
// Cur Elem
166+
// <= 1.5
167+
// == True
168+
// Actions
169+
// Teleport(Event Player, shop_pos)
170+
// pvar location = -1
171+
// // Add sound effect
172+
//
173+
//Rule "Teleport from Shop"
174+
// Event_Team(All)
175+
// Conditions
176+
// Distance Between
177+
// Event Player
178+
// shop_portal
179+
// <= 1.5
180+
// pvar location == -1
181+
// Actions
182+
// Msg(Event Player, "Bosses")
183+
// Big Msg("Hello")
184+
// pvar location = pvar cur_boss
185+
// Teleport(Event Player, player_spawns[pvar location])
186+
// // Add sound effect
187+
//

OWScript.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import re
23
import sys
34
from OWScript.Lexer import Lexer
45
from OWScript.Parser import Parser
@@ -14,14 +15,24 @@ def transpile(text, minify=False, save=None, debug=0):
1415
lexer = Lexer(text=text)
1516
tokens = lexer.lex()
1617
if debug & DEBUG.TOKENS:
17-
lexer.print_tokens()
18+
if save:
19+
with open(save, 'w', errors='ignore') as f:
20+
f.write(lexer.print_tokens())
21+
else:
22+
lexer.print_tokens()
1823
parser = Parser(tokens=tokens)
1924
tree = parser.script()
2025
if debug & DEBUG.TREE:
2126
print(tree.string())
2227
transpiler = Transpiler(tree=tree)
2328
code = transpiler.run()
24-
print(code)
29+
if minify:
30+
code = re.sub(r'[\s\n]*', '', code)
31+
if not save:
32+
sys.stdout.write(code)
33+
else:
34+
with open(save, 'w') as f:
35+
f.write(code)
2536

2637

2738
if __name__ == '__main__':
@@ -34,5 +45,5 @@ def transpile(text, minify=False, save=None, debug=0):
3445
file_input = args.input[0] if args.input else sys.stdin
3546
with open(file_input) as f:
3647
text = f.read()
37-
transpile(text, minify=args.min, save=args.save, debug=args.debug)
48+
transpile(text, minify=args.min, save=args.save, debug=args.debug or 0)
3849

OWScript/AST.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ def __init__(self, elements=None):
9696
def append(self, elem):
9797
self.elements.append(elem)
9898

99+
def __iter__(self):
100+
return iter(self.elements)
101+
99102
def __len__(self):
100103
return len(self.elements)
101104

@@ -158,7 +161,7 @@ def __init__(self, name, params):
158161
self.params = params
159162

160163
def __repr__(self):
161-
return '%{}({}): {}'.format(self.name, ', '.join(self.params), self.format_children)
164+
return '%{}({}): {}'.format(self.name, ', '.join(map(repr, self.params)), self.format_children)
162165

163166
class Attribute(Trailer):
164167
def __init__(self, name, parent):

OWScript/Lexer.py

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def print_tokens(self):
2626
"""Outputs the current token list."""
2727
tokens = '\n'.join(map(repr, self.tokens))
2828
print(tokens)
29+
return tokens
2930

3031
def lex(self):
3132
"""Tokenizes input into a list of tokens."""

OWScript/Parser.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def compare(self):
273273
if node.children:
274274
break
275275
op = self.curvalue
276-
if op == '>' and self.peek().type in ('DEDENT', 'RPAREN', 'COMMA'):
276+
if op == '>' and self.peek().type in ('DEDENT', 'RPAREN', 'RBRACK', 'COMMA', 'NEWLINE'):
277277
break
278278
self.eat(self.curtype)
279279
node = Compare(left=node, op=op, right=self.term())
@@ -360,6 +360,7 @@ def atom(self):
360360
elif self.curtype == 'LBRACK':
361361
node = self.array()
362362
else:
363+
print(self.tokens[self.pos - 5:self.pos])
363364
raise Errors.ParseError('Unexpected token of type {} on line {}:{}'.format(self.curtype, self.curtoken.line, self.curtoken.column))
364365
return node
365366

OWScript/Tokens.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __repr__(self):
5050

5151
class Tokens:
5252
"""Mapping of token names to regular expressions."""
53-
COMMENT : r'(\/\*(.|[\n])*?\*\/|\/\/[^\n]*\n?)'
53+
COMMENT : r'(\/\*(.|[\n])*?\*\/\n?|\/\/[^\n]*\n?)'
5454
COMPARE : r'(>=|<=|==|!=|>|<)'
5555
ASSIGN : r'(=|\+=|-=|\*=|\/=|^=|%=)'
5656
PLUS : r'\+'
@@ -65,7 +65,7 @@ class Tokens:
6565
RPAREN : r'\)'
6666
LBRACK : r'\['
6767
RBRACK : r'\]'
68-
STRING : r'"[^\\\r\n\f]*"'
68+
STRING : r'("[^\\\r\n\f]*"|\'[^\\\r\n\f]*\')'
6969
F_STRING : r'`[^\\\r\n\f]*`'
7070
TIME : r'[0-9]+(\.[0-9]+)?(ms|s|min)'
7171
FLOAT : r'[0-9]+\.[0-9]+'
@@ -84,7 +84,7 @@ class Tokens:
8484
GVAR : r'GVAR\b'
8585
RULE : r'RULE\b'
8686
ANNOTATION : r'[_a-zA-Z0-9][_a-zA-Z0-9]*:(?!\n)'
87-
OWID : fr'({"|".join(OWID)})(?=[\b\s\n\(,]+)'
87+
OWID : fr'({"|".join(OWID)})(?=[\b\s\n\(\),]+)'
8888
RULEBLOCK : r'(EVENT|CONDITIONS|ACTIONS)\b'
8989
NAME : r'[_a-zA-Z][_\-a-zA-Z0-9]*'
9090
WHITESPACE : r'[ \t]+'

0 commit comments

Comments
 (0)