Skip to content

Commit

Permalink
added markdown test (to become Rocket)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanisham committed May 26, 2024
1 parent 4700a1f commit 12eaa3d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 30 deletions.
2 changes: 2 additions & 0 deletions include/lib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,6 @@ namespace encoding {
void md_to_html(WrenVM* vm);
}



} // namespace lib
42 changes: 21 additions & 21 deletions lang/encoding.fan
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ class Markdown {
foreign static toHTML(buff)
}

foreign class JSON {
construct new() {}

static fromMap(map) {
if (!(map is Map)) {
Fiber.abort("Paramater is not of type Map")
}

var json = JSON.new()

for (entry of map) {
json.set(entry.key, entry.value)
}
}

foreign set(key, val);

[set]=(value) {
this.set(key, value)
}
}
// foreign class JSON {
// construct new() {}
//
// static fromMap(map) {
// if (!(map is Map)) {
// Fiber.abort("Parameter is not of type Map")
// }
//
// var json = JSON.new()
//
// for (entry of map) {
// json.set(entry.key, entry.value)
// }
// }
//
// foreign set(key, val);
//
// [set]=(value) {
// this.set(key, value)
// }
// }
3 changes: 1 addition & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <curl/curl.h>
#include <filesystem>
#include <fstream>
#include <sstream>

/**
* Fan is a language runtime focused on making software devlopment easy,
* Fan is a language runtime focused on making software development easy,
* performant, and fun. The Fan command line tool features a simple REPL and
* the ability to execute a script, typically the last argument value on the
* command line if no other commands or flags are passed.
Expand Down
10 changes: 4 additions & 6 deletions src/vm/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,8 @@ std::string lib::wren_type_to_string(const WrenType& type) {
return "null";
case WREN_TYPE_STRING:
return "String";
case WREN_TYPE_UNKNOWN:
return "unknown";
default:
return "invalid";
return "unknown";
}
}

Expand Down Expand Up @@ -439,12 +437,12 @@ WrenInterpretResult vm::Runtime::execute(const std::string& code, const std::str
}

void vm::Runtime::repl() const {
std::string line;
std::string buffer;
std::cout << rang::style::bold << "Fan " << cli::VERSION << " REPL" << std::endl;
std::cout << rang::fg::blue << "%> " << rang::fg::reset;

while (true) {
if (!std::getline(std::cin, line)) {
if (!std::getline(std::cin, buffer)) {
if (std::cin.eof()) {
// Handle EOF (Ctrl+D) here
std::cin.clear();
Expand All @@ -455,7 +453,7 @@ void vm::Runtime::repl() const {
break;
}
}
if (auto stat = this->execute(line); stat != WREN_RESULT_SUCCESS) {
if (auto stat = this->execute(buffer); stat != WREN_RESULT_SUCCESS) {
// std::cerr << "Error: " + stat << std::endl;
}
std::cout << rang::fg::blue << "%> " << rang::fg::reset;
Expand Down
5 changes: 4 additions & 1 deletion src/vm/std/encoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ void lib::encoding::md_to_html(WrenVM* vm) {
auto const input = wrenGetSlotString(vm, 1);

auto out = cmark_markdown_to_html(input, std::strlen(input), 0);
wrenSetSlotString(vm, 0, out);
std::string buffer{out};
wrenSetSlotString(vm, 0, buffer.c_str());

// Free the memory returned by CMark
if (out != nullptr) {
std::free(out);
out = nullptr;
Expand Down
16 changes: 16 additions & 0 deletions tests/std/markdown.fan
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import "std/encoding" for Markdown
import "std/fs" for Fs, Path

var files = Fs.listAllRecursive(Fs.cwd())

// List of markdown files in the directory
var mdFiles = []

for (i in files) {
if (Path.ext(i) == "md") {
System.print(i)
mdFiles.add(i)
}
}

System.print(mdFiles.count)

0 comments on commit 12eaa3d

Please sign in to comment.