Skip to content

Commit

Permalink
feat: renamed include to import.
Browse files Browse the repository at this point in the history
  • Loading branch information
Almas-Ali committed May 1, 2024
1 parent 0dc1576 commit c573ddf
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion core/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def visit_VarAssignNode(self, node: VarAssignNode, context: Context) -> RTResult
pos_end=node.pos_end,
)

def visit_IncludeNode(self, node: IncludeNode, context: Context) -> RTResult[Value]:
def visit_ImportNode(self, node: ImportNode, context: Context) -> RTResult[Value]:
res = RTResult[Value]()
exec_ctx = context

Expand Down
2 changes: 1 addition & 1 deletion core/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(
)


class IncludeNode:
class ImportNode:
module: Token

pos_start: Position
Expand Down
6 changes: 3 additions & 3 deletions core/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,22 +221,22 @@ def statement(self) -> ParseResult[Node]:
assert switch_node is not None
return res.success(switch_node)

if self.current_tok.matches(TT_KEYWORD, "include"):
if self.current_tok.matches(TT_KEYWORD, "import"):
self.advance(res)

if self.current_tok.type != TT_STRING and self.current_tok.type != TT_IDENTIFIER:
return res.failure(
InvalidSyntaxError(
self.current_tok.pos_start,
self.current_tok.pos_end,
"Expected string or identifier as included module",
"Expected string or identifier as imported module",
)
)

module = self.current_tok
self.advance(res)

return res.success(IncludeNode(module))
return res.success(ImportNode(module))

expr = res.register(self.expr())
if res.error:
Expand Down
2 changes: 1 addition & 1 deletion core/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def copy(self) -> Position:
"continue",
"break",
"class",
"include",
"import",
"try",
"catch",
"as",
Expand Down
2 changes: 1 addition & 1 deletion examples/args_test.rn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include Argparser
import Argparser

parser = Argparser("Utility Tool", "A simple utility tool.")

Expand Down
2 changes: 1 addition & 1 deletion examples/arrays.rn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include Array
import Array

arr = Array.Array([1,2,3,4,5,6,7,8,9,10])
arr.append(11)
Expand Down
2 changes: 1 addition & 1 deletion examples/colors_test.rn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include Colorlib
import Colorlib

# Print colored text to the console using the colorlib library
print(Colorlib.white("My name is John Doe"))
Expand Down
4 changes: 2 additions & 2 deletions examples/import_test.rn
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
# require("String")

#!
include String
import String

data = "Hello World !"
str = String.String(data)

print(str.len())

!#
include Math
import Math

print(Math.PI) # Ligal

12 changes: 12 additions & 0 deletions examples/operators-bug.rn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
x = 5
y = 2

x /= y
print(x) # 2.5 OK as floor division.

x //= y
print(x) # 1.0 Failed as Integer division

assert 5 / 5 == 1.0 # 1.0 OK as floor division.

assert 5 // 5 == 1 # Invalid Syntax: Token cannot appear after previous tokens
2 changes: 1 addition & 1 deletion tests/universe.rn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

include Universe
import Universe


0 comments on commit c573ddf

Please sign in to comment.