Skip to content

Commit

Permalink
fix: module auto doc generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Almas-Ali committed Oct 29, 2024
1 parent f7248a6 commit 3173526
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
10 changes: 9 additions & 1 deletion core/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,15 @@ def visit_ImportNode(self, node: ImportNode, context: Context) -> RTResult[Value

with open(module_name, "r") as f:
script = f.read()
docs: str = "[No Description]"
# take the first string as the docs
try:
docs = script.split('"')[1]
except IndexError:
docs = ""

if docs == "":
docs: str = "[No Description]"

except Exception as e:
return RTResult[Value]().failure(
RTError(node.pos_start, node.pos_end, f'Failed to load script "{module_name}"\n' + str(e), exec_ctx)
Expand Down
1 change: 1 addition & 0 deletions core/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ def statement(self) -> ParseResult[Node]:

module = self.current_tok
self.advance(res)

docs: str = "[No Description]"

if self.current_tok.matches(TT_KEYWORD, "as"):
Expand Down
23 changes: 22 additions & 1 deletion stdlib/os.rn
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
"This is OS module"
"os - OS routines for NT or Posix depending on what system we're on.

This exports:
- all functions from posix or nt, e.g. unlink, stat, etc.
- os.path is either posixpath or ntpath
- os.name is either 'posix' or 'nt'
- os.curdir is a string representing the current directory (always '.')
- os.pardir is a string representing the parent directory (always '..')
- os.sep is the (or a most common) pathname separator ('/' or '\\')
- os.extsep is the extension separator (always '.')
- os.altsep is the alternate pathname separator (None or '/')
- os.pathsep is the component separator used in $PATH etc
- os.linesep is the line separator in text files ('\r' or '\n' or '\r\n')
- os.defpath is the default search path for executables
- os.devnull is the file path of the null device ('/dev/null', etc.)

Programs that import and use 'os' stand a better chance of being
portable between different platforms. Of course, they must then
only use functions that are defined by all platforms (e.g., unlink
and opendir), and leave all pathname manipulation to os.path
(e.g., split and join).
"

fun getcwd() {
"Get the current working directory."
Expand Down

0 comments on commit 3173526

Please sign in to comment.