diff --git a/analyzer.wren b/analyzer.wren new file mode 100644 index 0000000..875eacc --- /dev/null +++ b/analyzer.wren @@ -0,0 +1,23 @@ +/// 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 +import "./wren_modules/wrenalyzer/source_file" for SourceFile + +class Analyzer { + /// Params: + /// path: String + /// code: String + /// Returns: Module + 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/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/cli.wren b/cli.wren index 10b9a30..f6cd7f7 100644 --- a/cli.wren +++ b/cli.wren @@ -13,17 +13,18 @@ /// - 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 +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] @@ -43,12 +44,19 @@ 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) +}.each {|entry| + var path = Path.join([cwd, entry]) + 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 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] 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"),