From 16ff2e4aad83398c6ca79f3596530c395bed6d5f Mon Sep 17 00:00:00 2001 From: Chance Snow Date: Sat, 3 Feb 2024 01:29:02 -0600 Subject: [PATCH 1/5] Update docs --- cli.wren | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cli.wren b/cli.wren index 10b9a30..0046641 100644 --- a/cli.wren +++ b/cli.wren @@ -13,10 +13,9 @@ /// - The D programming language's [documentation generator](https://dlang.org/spec/ddoc.html) (AKA DDoc). /// - The Domepunk [documentation generator](https://github.com/NinjasCL/domepunk/blob/main/tools/docs/__main__.py). /// -/// Authors: Chance Snow +/// Authors: Chance Snow /// Copyright: Copyright © 2024 Chance Snow /// License: MIT License -/// See Also: https://github.com/chances/descartes-d import "io" for File, Directory, Stdin, Stderr import "os" for Process From 51bd8849792362b65c6dd02a9859bc770c9680c9 Mon Sep 17 00:00:00 2001 From: Chance Snow Date: Sat, 3 Feb 2024 01:55:59 -0600 Subject: [PATCH 2/5] Add an API entry script --- api.wren | 3 +++ module.yml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 api.wren diff --git a/api.wren b/api.wren new file mode 100644 index 0000000..e0c5126 --- /dev/null +++ b/api.wren @@ -0,0 +1,3 @@ +/// Authors: Chance Snow +/// Copyright: Copyright © 2024 Chance Snow +/// License: MIT License diff --git a/module.yml b/module.yml index 38e75ba..989b748 100644 --- a/module.yml +++ b/module.yml @@ -3,7 +3,7 @@ version: 0.1.0 description: Documentation generator for Wren author: Chance Snow license: MIT -index: +index: api.wren cli: cli.wren tests: src/**/*.spec.wren dependencies: [wren-args, wren-colors, wren-path] From 25536bf938deefa7d22eaaebe93b1c745993db74 Mon Sep 17 00:00:00 2001 From: Chance Snow Date: Sat, 3 Feb 2024 01:57:49 -0600 Subject: [PATCH 3/5] Parse Wren sources --- analyzer.wren | 21 +++++++++++++++++++++ cli.wren | 17 ++++++++++++----- package.wren | 1 + 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 analyzer.wren diff --git a/analyzer.wren b/analyzer.wren new file mode 100644 index 0000000..789fba0 --- /dev/null +++ b/analyzer.wren @@ -0,0 +1,21 @@ +/// Authors: Chance Snow +/// Copyright: Copyright © 2024 Chance Snow +/// License: MIT License +import "./wren_modules/wrenalyzer/lexer" for Lexer +import "./wren_modules/wrenalyzer/parser" for Parser +import "./wren_modules/wrenalyzer/reporter" for PrettyReporter +import "./wren_modules/wrenalyzer/source_file" for SourceFile + +class Analyzer { + /// Params: + /// path: String + /// code: String + static parse(path, code) { + __reporter = __reporter == null ? PrettyReporter.new() : __reporter + + var source = SourceFile.new(path, code) + var lexer = Lexer.new(source) + var parser = Parser.new(lexer, __reporter) + return parser.parseModule() + } +} diff --git a/cli.wren b/cli.wren index 0046641..fc37c99 100644 --- a/cli.wren +++ b/cli.wren @@ -19,10 +19,12 @@ import "io" for File, Directory, Stdin, Stderr import "os" for Process +import "./analyzer" for Analyzer import "./ensure" for Ensure import "./wren_modules/wren-path/Path" for Path import "./wren_modules/wren-args/args" for Args +var cwd = Process.cwd var args = Args.parse(Process.arguments) var flags = args[0] var params = args[1] @@ -42,12 +44,17 @@ if (flags["help"] || flags["h"]) { // Bail if the user only wanted the version if (flags["version"]) Process.exit() -// Create and switch to the docs directory Ensure.exec("mkdir", ["-p", "docs"]) -var cwd = Process.cwd -Process.chdir(Path.join([cwd, "docs"])) +// Create index of generated documentation +Ensure.exec("touch", [Path.join([cwd, "docs", "index.json"])]) -// Create -Ensure.exec("touch", ["index.json"]) +// Find Wren sources +// TODO: Recursivly search for sources, ignoring "wren_modules" directories +var sources = Directory.list(cwd).where {|entry| + return entry.endsWith(".wren") && File.exists(entry) +}.map {|entry| + var path = Path.join([cwd, entry]) + Analyzer.parse(path, File.read(path)) +}.toList // TODO: Read all *.wren files, parse symbols and neighboring comments, emit docs diff --git a/package.wren b/package.wren index c9ed02c..ed3d249 100644 --- a/package.wren +++ b/package.wren @@ -5,6 +5,7 @@ class Package is WrenPackage { name { "docs" } dependencies { return [ + Dependency.new("wrenalyzer", "v0.4.0-alpha-1", "https://github.com/chances/wrenalyzer.git"), Dependency.new("wren-args", "master", "https://github.com/nanaian/wren-args.git"), Dependency.new("wren-assert", "v1.1.2", "https://github.com/RobLoach/wren-assert.git"), Dependency.new("wren-colors", "master", "https://github.com/gsmaverick/wren-colors.git"), From 9734e43054c1c25dd74a88503cfd45ec0797245d Mon Sep 17 00:00:00 2001 From: Chance Snow Date: Sat, 3 Feb 2024 04:22:20 -0600 Subject: [PATCH 4/5] Fix returned values in list of sources --- analyzer.wren | 2 ++ cli.wren | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/analyzer.wren b/analyzer.wren index 789fba0..875eacc 100644 --- a/analyzer.wren +++ b/analyzer.wren @@ -1,6 +1,7 @@ /// Authors: Chance Snow /// Copyright: Copyright © 2024 Chance Snow /// License: MIT License +import "./wren_modules/wrenalyzer/ast" for Module import "./wren_modules/wrenalyzer/lexer" for Lexer import "./wren_modules/wrenalyzer/parser" for Parser import "./wren_modules/wrenalyzer/reporter" for PrettyReporter @@ -10,6 +11,7 @@ class Analyzer { /// Params: /// path: String /// code: String + /// Returns: Module static parse(path, code) { __reporter = __reporter == null ? PrettyReporter.new() : __reporter diff --git a/cli.wren b/cli.wren index fc37c99..55b2369 100644 --- a/cli.wren +++ b/cli.wren @@ -54,7 +54,7 @@ var sources = Directory.list(cwd).where {|entry| return entry.endsWith(".wren") && File.exists(entry) }.map {|entry| var path = Path.join([cwd, entry]) - Analyzer.parse(path, File.read(path)) + return Analyzer.parse(path, File.read(path)) }.toList // TODO: Read all *.wren files, parse symbols and neighboring comments, emit docs From 40500d1d76ef704861aeb6291bd13a51bfc255e4 Mon Sep 17 00:00:00 2001 From: Chance Snow Date: Fri, 9 Feb 2024 19:32:56 -0600 Subject: [PATCH 5/5] Refactor source parsing --- cli.wren | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cli.wren b/cli.wren index 55b2369..f6cd7f7 100644 --- a/cli.wren +++ b/cli.wren @@ -50,11 +50,13 @@ Ensure.exec("touch", [Path.join([cwd, "docs", "index.json"])]) // Find Wren sources // TODO: Recursivly search for sources, ignoring "wren_modules" directories -var sources = Directory.list(cwd).where {|entry| +var sources = {} +Directory.list(cwd).where {|entry| return entry.endsWith(".wren") && File.exists(entry) -}.map {|entry| +}.each {|entry| var path = Path.join([cwd, entry]) - return Analyzer.parse(path, File.read(path)) -}.toList + sources[path] = Analyzer.parse(path, File.read(path)) +} +System.print("Parsed %(sources.keys.count) modules") // TODO: Read all *.wren files, parse symbols and neighboring comments, emit docs - +// NOTE: "There is a convention that methods ending in "_" are private." See https://github.com/wren-lang/wren/issues/117 and https://github.com/wren-lang/wren/issues/498#issuecomment-376209364