Skip to content

Commit 562c09d

Browse files
Merge pull request #5 from Conqu3red/improvements
classes
2 parents ab88ee0 + ff87ec6 commit 562c09d

File tree

7 files changed

+209
-20
lines changed

7 files changed

+209
-20
lines changed

.github/workflows/test_examples.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Test example files
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: [3.8]
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v2
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
27+
- name: Test examples
28+
working-directory: ./src
29+
run: |
30+
python test_examples.py
31+

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ dist
88
win-src/*.py
99
!ECPUser.py
1010
*.exe
11-
executables/ecp
11+
executables/ecp
12+
*.zip

examples/class_test.ecp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
CLASS a
2+
3+
temp := 1
4+
5+
SUBROUTINE INIT()
6+
this.b := 0
7+
ENDSUBROUTINE
8+
9+
SUBROUTINE STR()
10+
RETURN "<aaa>"
11+
ENDSUBROUTINE
12+
13+
SUBROUTINE REPR()
14+
RETURN this.STR()
15+
ENDSUBROUTINE
16+
17+
SUBROUTINE inc_b(value)
18+
this.b := this.b + value
19+
ENDSUBROUTINE
20+
ENDCLASS
21+
22+
instance := a()
23+
OUTPUT instance
24+
OUTPUT [instance, "aa"]
25+
26+
OUTPUT "b", instance.b
27+
instance.inc_b(1)
28+
OUTPUT "b", instance.b
29+
30+
OUTPUT "base", a.temp

src/ecp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "1.0.0-alpha"
1+
__version__ = "1.1.1-beta"
22
from lexer import *
33
from parse import *
44
import argparse

src/lexer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class TokenType(Enum):
4949
STRING = "STRING"
5050
ARRAY = "ARRAY"
5151
BUILTIN_FUNCTION = "BUILTIN_FUNCTION"
52+
SUBROUTINE = "SUBROUTINE"
5253

5354
ID = "ID"
5455
KEYWORD = "KEYWORD"
@@ -67,6 +68,7 @@ class TokenType(Enum):
6768
CONSTANT = "CONSTANT"
6869
TRY = "TRY"
6970
CATCH = "CATCH"
71+
CLASS = "CLASS"
7072
RECORD = "RECORD"
7173

7274
class Token:
@@ -130,12 +132,13 @@ def __repr__(self):
130132
#"SQRT",
131133
]
132134
keywords = {
133-
"SUBROUTINE": TokenType.KEYWORD,
135+
"SUBROUTINE": TokenType.SUBROUTINE,
134136
"ENDSUBROUTINE": TokenType.KEYWORD,
135137
"RETURN": TokenType.MAGIC,
136138
"CONTINUE": TokenType.MAGIC,
137139
"BREAK": TokenType.MAGIC,
138140
"OUTPUT": TokenType.MAGIC,
141+
"USERINPUT": TokenType.MAGIC,
139142
"False": TokenType.BOOLEAN,
140143
"True": TokenType.BOOLEAN,
141144

@@ -162,6 +165,8 @@ def __repr__(self):
162165
"TRY": TokenType.TRY,
163166
"CATCH": TokenType.CATCH,
164167
"ENDTRY": TokenType.KEYWORD,
168+
"CLASS": TokenType.CLASS,
169+
"ENDCLASS": TokenType.KEYWORD,
165170
}
166171

167172
types = {

0 commit comments

Comments
 (0)