Skip to content

Commit

Permalink
Fixed some bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
DevReaper0 committed Oct 18, 2021
1 parent f723bef commit 11931d5
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 45 deletions.
18 changes: 11 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# 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).
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and 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
- Easy use of default parameters in functions

## [2.0.1] - 2021-10-9
### Changed
- Moved PCPM code to it's own repository (https://github.com/DaRubyMiner360/PCPM)
## [2.0.1] - 2021-10-18
### Fixed
- Fixed what happens when using `||` and `&&` if you had an expression after the operators. If you ran `"A" == "A" || "A" == "B"`, it would interpret it as `("A" == "A" || "A") == "B"`, so it would return false instead of true.
- Fixed multiline comments not working correctly when used in certain places
- Fixed multiline comments breaking the repl

## [2.0.0] - 2021-10-9
### Added
Expand All @@ -37,6 +41,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Security
- PCPM package uploading doesn't require a login

[Unreleased]: https://github.com/DaRubyMiner360/ParaCode/compare/v2.0.1...HEAD
[2.0.1]: https://github.com/DaRubyMiner360/ParaCode/releases/tag/v2.0.1
[2.0.0]: https://github.com/DaRubyMiner360/ParaCode/releases/tag/v2.0.0
[Unreleased]: https://github.com/DaRubyMiner360/ParaCode/compare/2.0.1...HEAD
[2.0.1]: https://github.com/DaRubyMiner360/ParaCode/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/DaRubyMiner360/ParaCode/releases/tag/2.0.0
3 changes: 1 addition & 2 deletions ParaCode.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ def eval(self, data=None, filename=None, interpret=True, default_imports=['std/_
return None
debug_name = filename
self.data = self.file.read()

elif data != None:
self.data = data

else:
self.data = ""

Expand Down Expand Up @@ -75,6 +73,7 @@ def eval(self, data=None, filename=None, interpret=True, default_imports=['std/_

def eval_file(self, filename):
return self.eval(filename=filename)

def eval_data(self, data):
return self.eval(data=data)

Expand Down
24 changes: 12 additions & 12 deletions interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ def visit_BinOp(self, node):
funstr = '__div__'
elif node.token.type == TokenType.Modulus:
funstr = '__mod__'
elif node.token.type == TokenType.LessThan:
funstr = '__lt__'
elif node.token.type == TokenType.LessThanEqual:
funstr = '__lte__'
elif node.token.type == TokenType.GreaterThan:
funstr = '__gt__'
elif node.token.type == TokenType.GreaterThanEqual:
funstr = '__gte__'
elif node.token.type == TokenType.Compare:
funstr = '__eql__'
elif node.token.type == TokenType.NotCompare:
funstr = '__noteql__'
elif node.token.type == TokenType.And:
funstr = '__and__'
elif node.token.type == TokenType.Or:
Expand All @@ -164,18 +176,6 @@ def visit_BinOp(self, node):
funstr = '__bitshiftright__'
elif node.token.type == TokenType.Spaceship:
funstr = '__compare__'
elif node.token.type == TokenType.LessThan:
funstr = '__lt__'
elif node.token.type == TokenType.LessThanEqual:
funstr = '__lte__'
elif node.token.type == TokenType.GreaterThan:
funstr = '__gt__'
elif node.token.type == TokenType.GreaterThanEqual:
funstr = '__gte__'
elif node.token.type == TokenType.Compare:
funstr = '__eql__'
elif node.token.type == TokenType.NotCompare:
funstr = '__noteql__'

member_access_call_node = NodeCall(
NodeMemberExpression(
Expand Down
33 changes: 24 additions & 9 deletions lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,39 +210,54 @@ def lex(self):
continue


# multiline comments
# comments
if string_type == None and (self.peek_char(0) == '#' or (self.peek_char(0) == '/' and self.peek_char(1) == '/') or (self.peek_char(0) == '/' and self.peek_char(1) == '*')):
self.read_char()
if self.peek_char(-1) == '#' and self.peek_char(0) == '*':
# multiline comment

# skip '*' character
self.read_char()

# read until '*#'
while (self.read_char() != '*' and self.peek_char(1) != '#'):
pass

# EOF
if self.peek_char(0) == '':
break

# skip '*#' characters
self.read_char(1)
self.read_char(2)

# end by pushing the token and skipping any whitespace afterwards
if self.token_data != '':
self.push_token()
self.skip_whitespace()
elif self.peek_char(-1) == '/' and self.peek_char(0) == '*':
# multiline comment

# skip '*' character
self.read_char()

# read until '*/'
while (self.read_char() != '*' and self.peek_char(1) != '/'):
pass
# EOF
if self.peek_char(0) == '':
break

# skip '*/' characters
self.read_char(1)
self.read_char(2)

# end by pushing the token and skipping any whitespace afterwards
if self.token_data != '':
self.push_token()
self.skip_whitespace()
else:
while self.read_char() != '\n':
# EOF
if self.peek_char(0) == '':
break

# skip any whitespace after comment
self.skip_whitespace()
# skip any whitespace after comment
self.skip_whitespace()
continue

# encountered whitespace and not in string, push token
Expand Down
10 changes: 7 additions & 3 deletions parse/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,13 +897,13 @@ def parse_expression(self):
expected_types = (
TokenType.Equals,
TokenType.Plus, TokenType.Minus, TokenType.Modulus,
TokenType.BitwiseOr, TokenType.BitwiseAnd, TokenType.BitwiseXor,
TokenType.And, TokenType.Or,
TokenType.Compare, TokenType.NotCompare,
TokenType.Spaceship,
TokenType.Arrow,
TokenType.LessThan, TokenType.GreaterThan,
TokenType.LessThanEqual, TokenType.GreaterThanEqual,
TokenType.BitwiseOr, TokenType.BitwiseAnd, TokenType.BitwiseXor,
TokenType.And, TokenType.Or,
TokenType.BitwiseLShift, TokenType.BitwiseRShift,
TokenType.Exponentiation
) + multiop_types
Expand All @@ -930,10 +930,14 @@ def parse_expression(self):
assign_node.value = value_node
node = assign_node
continue

if token.type in expected_types:
self.eat()

if (token.type == TokenType.Or or token.type == TokenType.And) and self.peek_token().type in expected_types:
node = NodeBinOp(left=node, token=token, right=self.parse_expression())
continue

node = NodeBinOp(left=node, token=token, right=self.parse_term())
return node

Expand Down
55 changes: 43 additions & 12 deletions repl/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ def __init__(self, paraCode):
You are using a possibly unstable version! If something doesn't work correctly, that is probably why.""" + LogColor.Default
elif latest_version.json()["tag_name"] > paraCode.version:
# Update available
import datetime
self.welcome_message += LogColor.Warning + """
Version {} is available to update to! Download it from GitHub for new features and bug fixes.""".format(latest_version.json()["tag_name"]) + LogColor.Default
Version {} is available to update to! It was released {}. Download it from GitHub for new features and bug fixes.""".format(latest_version.json()["tag_name"], "on " + datetime.datetime.strptime(latest_version.json()["published_at"], "%Y-%m-%dT%H:%M:%SZ").strftime('%A %b %d, %Y at %X')) + LogColor.Default
except:
# Error occured (connection failed, couldn't find any releases, etc.)
pass
Expand Down Expand Up @@ -127,7 +128,7 @@ def accept_input(self):
line = input('>>> ')

trimmed = line.strip()
if os.path.isfile(trimmed) and (trimmed.endswith(".para") or trimmed.endswith(".para/") or trimmed.endswith(".paracode") or trimmed.endswith(".paracode/")):
if os.path.isfile(trimmed) and (trimmed.endswith(".para") or trimmed.endswith(".paracode")):
self.paraCode.eval_file(trimmed)

return
Expand All @@ -143,12 +144,12 @@ def accept_input(self):
self._walkthrough_messages))))
return

(brace_counter, bracket_counter, paren_counter) = self.count_continuation_tokens(line)
(brace_counter, bracket_counter, paren_counter, comment_type) = self.count_continuation_tokens(line)

while brace_counter > 0 or bracket_counter > 0 or paren_counter > 0:
while brace_counter > 0 or bracket_counter > 0 or paren_counter > 0 or comment_type:
next_line = input('... ')
line += next_line + '\n'
(brace_counter, bracket_counter, paren_counter) = self.count_continuation_tokens(line)
(brace_counter, bracket_counter, paren_counter, comment_type) = self.count_continuation_tokens(line)

(line_ast, error_list) = self.parse_line(line)

Expand Down Expand Up @@ -190,18 +191,48 @@ def count_continuation_tokens(self, line):
bracket_counter = 0
paren_counter = 0

started_comment_char = ""
comment_type = ""

for ch in line:
if ch == '{':
if ch == '/' and comment_type == "":
if started_comment_char != "/":
started_comment_char = "/"
else:
started_comment_char = ""
comment_type = "slash_slash"
elif ch == '*' and started_comment_char == "/":
started_comment_char = ""
comment_type = "slash_asterisk"
elif ch == '#' and comment_type == "" and started_comment_char != "#":
started_comment_char = "#"
comment_type = "hashtag"
elif ch == '*' and started_comment_char == "#":
started_comment_char = ""
comment_type = "hashtag_asterisk"
elif ch == '*' and started_comment_char == "":
started_comment_char = "*"
elif ch == '/' and started_comment_char == "*" and comment_type == "slash_asterisk":
started_comment_char = ""
comment_type = ""
elif ch == '#' and started_comment_char == "*" and comment_type == "hashtag_asterisk":
started_comment_char = ""
comment_type = ""

elif ch == '{' and comment_type == "":
brace_counter += 1
elif ch == '}':
elif ch == '}' and comment_type == "":
brace_counter -= 1
elif ch == '(':
elif ch == '(' and comment_type == "":
paren_counter += 1
elif ch == ')':
elif ch == ')' and comment_type == "":
paren_counter -= 1
elif ch == '[':
elif ch == '[' and comment_type == "":
bracket_counter += 1
elif ch == ']':
elif ch == ']' and comment_type == "":
bracket_counter -= 1

return (brace_counter, bracket_counter, paren_counter)
if comment_type == "slash_slash" or comment_type == "hashtag":
comment_type = ""

return (brace_counter, bracket_counter, paren_counter, comment_type)

0 comments on commit 11931d5

Please sign in to comment.