Skip to content

Commit

Permalink
Version 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DevReaper0 committed Oct 9, 2021
1 parent e20c356 commit 1ed951f
Show file tree
Hide file tree
Showing 92 changed files with 2,898 additions and 483 deletions.
11 changes: 1 addition & 10 deletions .breakpoints
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
{
"files": {
"interpreter/env/builtins.py": [
{
"id": "9f98d1ad-f7d9-47e0-b397-4693b1af0ec4",
"line": 531,
"version": 3942,
"index": 15827
}
]
}
"files": {}
}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
/dist/
*.bat
*.spec
preferences.toml
.env
.env
2 changes: 1 addition & 1 deletion .replit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run = "python3 main.py"
run = "py3clean . & python3 main.py"
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Changelog
All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Support for variables in the `catch` statement
- Complete requests HTTP library
- Complete regex support
- Better interfacing with python code from ParaCode

## [2.0.0] - 2021-10-9
### Added
- Standard library written largely in ParaCode itself
- Repl
- PCPM (ParaCode Package Manager)
- Documentation
- More, higher quality, examples
- Update script
- `try`/`catch` statements and exceptions
- New types and aliases
- Basic interfacing with python code from ParaCode

### Changed
- Completely rewrote the language as an OOP language
- Separated everything into multiple files
- Improved `import` statement drastically

### Removed
- `shell.py` file
- Unnecessary files

### Security
- PCPM package uploading doesn't require a login

[Unreleased]: https://github.com/DaRubyMiner360/ParaCode/compare/v2.0.0...HEAD
[2.0.0]: https://github.com/DaRubyMiner360/ParaCode/releases/tag/v2.0.0
Binary file modified PCPM
Binary file not shown.
11 changes: 8 additions & 3 deletions ParaCode.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class ParaCode():
data = ""
initialized = False

# Language Info
version = "2.0.0"
release_stage = "stable"

def __init__(self):
ParaCode.instance = self

Expand Down Expand Up @@ -75,8 +79,8 @@ def eval_data(self, data):
return self.eval(data=data)

def call_function(self, function_name, arguments=[]):
if not self.initialized:
self.eval()
# if not self.initialized:
# self.eval()
if self.interpreter == None:
raise Exception("ParaCode not initialized! please run ")
if type(arguments) != list:
Expand All @@ -86,4 +90,5 @@ def call_function(self, function_name, arguments=[]):

def repl(self):
repl = Repl(self)
repl.loop()
repl.loop()

10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,21 @@ Later I plan to rewrite ParaCode in C/C++ for better speed, efficiency. I plan t

[arrays](https://replit.com/@DaRubyMiner360/ParaCode-Rewrite#doc/40_arrays.md) - Array operations

[dictionary](https://replit.com/@DaRubyMiner360/ParaCode-Rewrite#doc/41_dictionary.md) - Dictionary operations

[iterators](https://replit.com/@DaRubyMiner360/ParaCode-Rewrite#doc/50_iterators.md) - Building custom iterator objects

[random](https://replit.com/@DaRubyMiner360/ParaCode-Rewrite#doc/55_random.md) - Random number generation

[modules](https://replit.com/@DaRubyMiner360/ParaCode-Rewrite#doc/60_modules.md) - Modules

[packages](https://replit.com/@DaRubyMiner360/ParaCode-Rewrite#doc/61_packages.md) - Packages

[console](https://replit.com/@DaRubyMiner360/ParaCode-Rewrite#doc/70_console.md) - Console input and output

[files](https://replit.com/@DaRubyMiner360/ParaCode-Rewrite#doc/80_files.md) - File reading and writing

[json](https://replit.com/@DaRubyMiner360/ParaCode-Rewrite#doc/81_json.md) - File reading and writing
[json](https://replit.com/@DaRubyMiner360/ParaCode-Rewrite#doc/81_json.md) - JSON reading and writing


### Examples
Expand All @@ -54,6 +58,8 @@ Later I plan to rewrite ParaCode in C/C++ for better speed, efficiency. I plan t

[pythagorean theorem calculator](https://replit.com/@DaRubyMiner360/ParaCode-Rewrite#examples/pythagorean.para)

[rule110](https://replit.com/@DaRubyMiner360/ParaCode-Rewrite#examples/rule110.para)

Be sure to check out our TicTacToe example!
Start the REPL by running `main.py` and call `tictactoe();` to try it out!

Expand All @@ -62,3 +68,5 @@ To update ParaCode, run the `update.sh` file. On most operating systems this can
sh update.sh
```
Or, to install and update ParaCode, run everything from `update.sh`.

You can find the [Changelog](https://replit.com/@DaRubyMiner360/ParaCode-Rewrite#CHANGELOG.md) here.
54 changes: 54 additions & 0 deletions dataCounter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import subprocess
import sys
import os

rcmd = "( find ./ -name '*.%s' -print0 | xargs -0 cat ) | wc -l"
types = ['c', 'cpp', 'h', 'hpp', 'py', 'para', 'paracode', 'go', 'sh']

if len(sys.argv) > 1:
if sys.argv[1].lower() == "lines":
rcmd = "( find ./ -name '*.%s' -print0 | xargs -0 cat ) | wc -l"
elif sys.argv[1].lower() == "words":
rcmd = "( find ./ -name '*.%s' -print0 | xargs -0 cat ) | wc -w"
elif sys.argv[1].lower() == "chars":
rcmd = "( find ./ -name '*.%s' -print0 | xargs -0 cat ) | wc -m"
elif sys.argv[1].lower() == "bytes":
rcmd = "( find ./ -name '*.%s' -print0 | xargs -0 cat ) | wc -c"
elif sys.argv[1].lower() == "maxlinelength" or sys.argv[1].lower() == "max-line-length" or sys.argv[1].lower() == "mll":
rcmd = "( find ./ -name '*.%s' -print0 | xargs -0 cat ) | wc -L"

if len(sys.argv) > 2:
if sys.argv[2].lower() == "c":
types = ['c', 'h']
elif sys.argv[2].lower() == "c++" or sys.argv[2].lower() == "cpp":
types = ['cpp', 'h', 'hpp']
elif sys.argv[2].lower() == "allc":
types = ['c', 'cpp', 'h', 'hpp']
elif sys.argv[2].lower() == "python" or sys.argv[2].lower() == "py":
types = ['py']
elif sys.argv[2].lower() == "paracode" or sys.argv[2].lower() == "para":
types = ['para', 'paracode']
elif sys.argv[2].lower() == "main":
types = ['c', 'cpp', 'h', 'hpp', 'py', 'para', 'paracode']
elif sys.argv[2].lower() == "go":
types = ['go']
elif sys.argv[2].lower() == "sh":
types = ['sh']

sum = 0
for el in types:
if len(sys.argv) > 1 and sys.argv[1].lower() != "files":
cmd = rcmd % (el)
p = subprocess.Popen([cmd],stdout=subprocess.PIPE,shell=True)
out = int(p.stdout.read().strip())
print("*.%s: %s" % (el, out))
sum += out
else:
out = 0
for root, dirs, files in os.walk(os.path.dirname(os.path.realpath(__file__))):
for file in files:
if file.endswith("." + el):
out += 1
print("*.%s: %s" % (el, out))
sum += out
print("sum: %d" % (sum))
4 changes: 4 additions & 0 deletions doc/16_operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ Some examples of what method names operators are paired with are:
* `*` - `__mul__`
* `/` - `__div__`
* `%` - `__mod__`
* `**` - `__expon__`
* `==` - `__eql__`
* `!=` - `__noteql__`
* `!` - `__not__`
* `~` - `__bitnot__`
* `<=>` - `__compare__` (spaceship operator: return -1 if less than, 0 if equal, 1 if greater than)
* `<` - `__lt__` (defaults to `(self <=> other) == -1;`)
* `<=` - `__lte__` (defaults to `(self <=> other) != 1;`)
Expand All @@ -25,6 +27,8 @@ Some examples of what method names operators are paired with are:
* `&` - `__bitand__`
* `|` - `__bitor__`
* `^` - `__bitxor__`
* `<<` - `__bitshiftleft__`
* `>>` - `__bitshiftright__`
* `&&` - `__and__`
* `||` - `__or__`
* `()` (function call) - `__call__`
Expand Down
4 changes: 2 additions & 2 deletions doc/41_dictionaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ names.containskey('Buddy'); // true

names.append(['Tiffany', 'Jones']); // names is now {'Jeffrey': 'Williams', 'Sam': 'Johnson', 'Buddy': 'White', 'Tiffany': 'Jones'}

names | [['Sam', 'Johnson'], ['Tyler', 'Scotts']]; // returns {'Jeffrey': 'Williams', 'Sam': 'Johnson', 'Buddy': 'White', 'Tyler': 'Scotts'}
names | Dict.new(['Sam', 'Johnson'], ['Tyler', 'Scotts']); // returns {'Jeffrey': 'Williams', 'Sam': 'Johnson', 'Buddy': 'White', 'Tyler': 'Scotts'}

names & [['Sam', 'Johnson'], ['Tyler', 'Scotts']]; // returns {'Sam': 'Johnson'}
names & Dict.new(['Sam', 'Johnson'], ['Tyler', 'Scotts']); // returns {'Sam': 'Johnson'}
```
25 changes: 0 additions & 25 deletions doc/62_fileessentials.md

This file was deleted.

16 changes: 13 additions & 3 deletions error.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
from util import LogColor

class InterpreterError(Exception):
pass
def __init__(self, m, node=None, type=None, message=None, cont=False, name=None, classnames=None):
super().__init__(m)
self.node = node
self.type = type
self.message = message
self.cont = cont
self.name = name
self.classnames = classnames

class ErrorType(Enum):
Exception = auto()
Syntax = auto()
DoesNotExist = auto()
TypeError = auto()
Expand All @@ -13,11 +21,12 @@ class ErrorType(Enum):
MacroExpansionError = auto()

class Error():
def __init__(self, type, location, message, filename):
def __init__(self, type, location, message, filename, name=None):
self.type = type
self.filename = filename
self.message = message
self.location = location
self.name = name

@property
def location_filename(self):
Expand All @@ -42,6 +51,8 @@ def location_col(self):

def __repr__(self):
nstr = f"{self.location_filename}:{self.location_row}:{self.location_col}: {LogColor.Error}{self.type.name} error:{LogColor.Default}"
if self.type == ErrorType.Exception:
nstr = f"{self.location_filename}:{self.location_row}:{self.location_col}: {LogColor.Error}{self.name}:{LogColor.Default}"
return f"{LogColor.Bold}{nstr}{LogColor.Default} {self.message}"
__str__ = __repr__

Expand All @@ -61,4 +72,3 @@ def print_errors(self):

def get_errors(self):
return self.errors

Binary file removed examples/__pycache__/embed.cpython-38.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/embed.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ParaCode import ParaCode

def example_embed(paraCode):
paraCode.call_function('print', ["Hello from embed.py!"])
paraCode.call_function('print', ["Hello from embed.py!"])
23 changes: 23 additions & 0 deletions examples/exceptions.para
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
try {
// Comment below line, change the exception to MultipleDefinitionError, TypeError, ArgumentError, MacroExpansionError, or Exception
ArgumentError.new("A").raise();
print("TRY");
}
catch MultipleDefinitionError {
print("CATCH MultipleDefinitionError");
}
catch [TypeError, ArgumentError] {
print("CATCH ArgumentError/TypeError");
}
catch MacroExpansionError {
print("CATCH MacroExpansionError");
}
catch {
print("CATCH Any Exception");
}
else {
print("ELSE");
}
finally {
print("FINALLY");
}
1 change: 0 additions & 1 deletion examples/mandle.para
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

let width = 40.0;
let height = 20.0;

Expand Down
2 changes: 1 addition & 1 deletion examples/numbers.para
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ print("Initial value: "+x);
x += 10;
print("Value after addition: "+x);
// Multiply x by 2
print("Number call: "+2(x));
print("Number call: "+2(x));
28 changes: 14 additions & 14 deletions examples/operator_overloading.para
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
let Person = Type.extend({
instance = {
name: str
instance = {
name: str

// overload the | operator
func __bitor__(self, other) {
return Person.new(self.name + ' ' + other.name);
}
// overload the | operator
func __bitor__(self, other) {
return Person.new(self.name + ' ' + other.name);
}

// example of lambdas
to_str: Func = self -> "Person [name: " + self.name + "]"
}
// example of lambdas
to_str: Func = self -> "Person [name: " + self.name + "]"
}

// constructor
func __construct__(self, name) {
self.name = name;
}
// constructor
func __construct__(self, name) {
self.name = name;
}
});

let person_a = Person.new('Bruce');
let person_b = Person.new('Wayne');
let combined = person_a | person_b;
io.write_color(Console.RED, combined); // prints `Person [name: 'Bruce Wayne']` in red
io.write_color(Console.RED, combined); // prints `Person [name: 'Bruce Wayne']` in red
18 changes: 9 additions & 9 deletions examples/patching.para
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Int.patch({
// overload object being called as a function.
// arguments are passed in as an array, so
// you need to splat (*) the arguments, expanding
// from the first (the first argument would be the `Int` type
// itself)
func __call__(self, args) {
return self.__mul__(*(args.from(1)));
}
// overload object being called as a function.
// arguments are passed in as an array, so
// you need to splat (*) the arguments, expanding
// from the first (the first argument would be the `Int` type
// itself)
func __call__(self, args) {
return self.__mul__(*(args.from(1)));
}
});

let result = 10(20);
print(result); // prints 200
print(result); // prints 200
Loading

0 comments on commit 1ed951f

Please sign in to comment.