Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions analyzer.wren
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// Authors: Chance Snow <git@chancesnow.me>
/// 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()
}
}
3 changes: 3 additions & 0 deletions api.wren
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Authors: Chance Snow <git@chancesnow.me>
/// Copyright: Copyright © 2024 Chance Snow
/// License: MIT License
24 changes: 16 additions & 8 deletions cli.wren
Original file line number Diff line number Diff line change
Expand Up @@ -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 <git@chancesnow.me>
/// 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]
Expand All @@ -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
2 changes: 1 addition & 1 deletion module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 0.1.0
description: Documentation generator for Wren
author: Chance Snow <git@chancesnow.me>
license: MIT
index:
index: api.wren
cli: cli.wren
tests: src/**/*.spec.wren
dependencies: [wren-args, wren-colors, wren-path]
Expand Down
1 change: 1 addition & 0 deletions package.wren
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down