Added manpages for fun and funstx and some small code changes. (0.39.3)
This commit is contained in:
parent
04951bee2a
commit
69b9b87dd4
5 changed files with 188 additions and 13 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
project(fun VERSION 0.39.2 LANGUAGES C)
|
project(fun VERSION 0.39.3 LANGUAGES C)
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 99)
|
set(CMAKE_C_STANDARD 99)
|
||||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
|
|
@ -433,3 +433,11 @@ endif()
|
||||||
install(FILES README.md LICENSE
|
install(FILES README.md LICENSE
|
||||||
DESTINATION /usr/share/doc/fun
|
DESTINATION /usr/share/doc/fun
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# - Manpages
|
||||||
|
# Install section 1 manpages for the CLI tools
|
||||||
|
install(FILES
|
||||||
|
man/fun.1
|
||||||
|
man/funstx.1
|
||||||
|
DESTINATION /usr/share/man/man1
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
#!/usr/bin/env fun
|
#!/usr/bin/env fun
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Fun programming language.
|
* This file is part of the Fun programming language.
|
||||||
* https://fun-lang.xyz/
|
* https://fun-lang.xyz/
|
||||||
*
|
*
|
||||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||||
* Licensed under the terms of the Apache-2.0 license.
|
* Licensed under the terms of the Apache-2.0 license.
|
||||||
* https://opensource.org/license/apache-2-0
|
* https://opensource.org/license/apache-2-0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// To test this you need to go to ./examples/ and test includes running ../build/fun include_local.fun
|
// To test this you need to go to ./examples/ and test includes running ../build/fun include_local.fun
|
||||||
// Local includes are always relative from the $PWD using "" and system includes are located at /usr/lib/fun using <>.
|
// Local includes are always relative from the $PWD using "" and system includes are located at /usr/lib/fun using <>.
|
||||||
|
|
|
||||||
74
man/fun.1
Normal file
74
man/fun.1
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
.TH fun 1 "March 2026" "fun" "User Commands"
|
||||||
|
.SH NAME
|
||||||
|
fun \- Fun language runner and REPL
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B fun
|
||||||
|
\fR[\fIoptions\fR] [\fIscript.fun\fR] [\fB--\fR \fIargs...\fR]
|
||||||
|
.SH DESCRIPTION
|
||||||
|
\fBfun\fR runs programs written for the Fun virtual machine. When invoked
|
||||||
|
with a script path, it parses, compiles and executes the script. If no
|
||||||
|
script is provided and the binary was built with REPL support, \fBfun\fR
|
||||||
|
starts an interactive Read\-Eval\-Print Loop.
|
||||||
|
.SH OPTIONS
|
||||||
|
.TP
|
||||||
|
.B -i , --repl
|
||||||
|
Start the interactive REPL explicitly (if built with REPL support).
|
||||||
|
.TP
|
||||||
|
.B -v , --version
|
||||||
|
Print version and exit.
|
||||||
|
.TP
|
||||||
|
.B -h , --help
|
||||||
|
Show usage information and exit.
|
||||||
|
.PP
|
||||||
|
Note: Available options may vary by build configuration. Check
|
||||||
|
\fBfun --help\fR for your binary.
|
||||||
|
.SH ENVIRONMENT
|
||||||
|
.TP
|
||||||
|
.B FUN_LIB_DIR
|
||||||
|
Top\-priority search path for included Fun modules. Set this when running
|
||||||
|
from the source tree to point to \fI./lib\fR.
|
||||||
|
.TP
|
||||||
|
.B DEFAULT_LIB_DIR
|
||||||
|
Compiled\-in default library directory searched after \fBFUN_LIB_DIR\fR.
|
||||||
|
.SH EXIT STATUS
|
||||||
|
.TP
|
||||||
|
.B 0
|
||||||
|
Success.
|
||||||
|
.TP
|
||||||
|
.B non\-zero
|
||||||
|
Error during parse, compile, or runtime.
|
||||||
|
.SH EXAMPLES
|
||||||
|
.TP
|
||||||
|
Run an installed example:
|
||||||
|
.nf
|
||||||
|
fun /usr/share/fun/examples/hello.fun
|
||||||
|
.fi
|
||||||
|
.TP
|
||||||
|
Run from a build tree without installing (point stdlib to repo):
|
||||||
|
.nf
|
||||||
|
FUN_LIB_DIR=./lib /path/to/build_dir/fun examples/hello.fun
|
||||||
|
.fi
|
||||||
|
.TP
|
||||||
|
Pass arguments to a script (after -- they are forwarded):
|
||||||
|
.nf
|
||||||
|
fun myscript.fun -- arg1 arg2
|
||||||
|
.fi
|
||||||
|
.SH FILES
|
||||||
|
.TP
|
||||||
|
Binary (default install)
|
||||||
|
\fI/usr/bin/fun\fR
|
||||||
|
.TP
|
||||||
|
Standard library (default install)
|
||||||
|
\fI/usr/share/fun/lib\fR
|
||||||
|
.TP
|
||||||
|
Examples (optional, default install)
|
||||||
|
\fI/usr/share/fun/examples\fR
|
||||||
|
.SH SEE ALSO
|
||||||
|
\fBfunstx\fR(1)
|
||||||
|
.br
|
||||||
|
Project documentation: \fIdocs/fun.md\fR, \fIdocs/cli.md\fR, \fIdocs/includes.md\fR
|
||||||
|
.SH AUTHORS
|
||||||
|
The Fun project authors.
|
||||||
|
.SH COPYRIGHT
|
||||||
|
\(co The Fun authors. Licensed under the project license; see the
|
||||||
|
\fILICENSE\fR file distributed with this source.
|
||||||
77
man/funstx.1
Normal file
77
man/funstx.1
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
.TH funstx 1 "March 2026" "fun" "User Commands"
|
||||||
|
.SH NAME
|
||||||
|
funstx \- Fun syntax checker and fixer
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B funstx
|
||||||
|
\fR[\fB--fix\fR] \fIfile1.fun\fR [\fIfile2.fun\fR ...]
|
||||||
|
.SH DESCRIPTION
|
||||||
|
\fBfunstx\fR parses one or more \fI.fun\fR source files to verify syntax
|
||||||
|
without executing them. With \fB--fix\fR, it attempts conservative,
|
||||||
|
idempotent edits to align files with parser expectations and then
|
||||||
|
re\-checks before writing changes.
|
||||||
|
.SH OPTIONS
|
||||||
|
.TP
|
||||||
|
.B --fix
|
||||||
|
Attempt safe automatic corrections before re\-checking. Only writes a file
|
||||||
|
if the fixed version parses successfully.
|
||||||
|
.SH OUTPUT
|
||||||
|
.TP
|
||||||
|
On success
|
||||||
|
Prints "\fIpath/to/file.fun\fR: OK".
|
||||||
|
.TP
|
||||||
|
On failure
|
||||||
|
Prints "\fIpath/to/file.fun\fR:line:col: syntax error: <message>".
|
||||||
|
.SH EXIT STATUS
|
||||||
|
.TP
|
||||||
|
.B 0
|
||||||
|
All provided files parsed successfully.
|
||||||
|
.TP
|
||||||
|
.B 1
|
||||||
|
At least one file failed to parse (after optional fixing).
|
||||||
|
.TP
|
||||||
|
.B 2
|
||||||
|
Incorrect usage (e.g., no files provided).
|
||||||
|
.SH AUTO\-FIX RULES
|
||||||
|
The fixer applies a small set of conservative transformations:
|
||||||
|
.IP \(bu 2
|
||||||
|
Normalize line endings: CRLF/CR \(-> LF.
|
||||||
|
.IP \(bu 2
|
||||||
|
Convert leading tabs to spaces; normalize indentation to multiples of two spaces.
|
||||||
|
.IP \(bu 2
|
||||||
|
Trim trailing spaces.
|
||||||
|
.IP \(bu 2
|
||||||
|
Ensure the file ends with a single newline.
|
||||||
|
.IP \(bu 2
|
||||||
|
Normalize type aliases: \fIsint8|sint16|sint32|sint64\fR \(-> \fIint8|int16|int32|int64\fR (word\-boundary aware).
|
||||||
|
.PP
|
||||||
|
Structural issues that require semantic changes are not auto\-fixed; if
|
||||||
|
parsing still fails, the original file is left unchanged and an error is
|
||||||
|
reported.
|
||||||
|
.SH EXAMPLES
|
||||||
|
.TP
|
||||||
|
Check a single file
|
||||||
|
.nf
|
||||||
|
funstx examples/arrays.fun
|
||||||
|
.fi
|
||||||
|
.TP
|
||||||
|
Check and auto\-fix a file
|
||||||
|
.nf
|
||||||
|
funstx --fix examples/arrays.fun
|
||||||
|
.fi
|
||||||
|
.TP
|
||||||
|
Bulk check and auto\-fix all examples
|
||||||
|
.nf
|
||||||
|
find examples -type f -name '*.fun' -print0 | xargs -0 -n 50 funstx --fix
|
||||||
|
.fi
|
||||||
|
.SH BUILD AND INSTALL
|
||||||
|
Built as CMake target \fBfunstx\fR and installed alongside \fBfun\fR into
|
||||||
|
\fI/usr/bin\fR by default.
|
||||||
|
.SH SEE ALSO
|
||||||
|
\fBfun\fR(1)
|
||||||
|
.br
|
||||||
|
Project documentation: \fIdocs/funstx.md\fR
|
||||||
|
.SH AUTHORS
|
||||||
|
The Fun project authors.
|
||||||
|
.SH COPYRIGHT
|
||||||
|
\(co The Fun authors. Licensed under the project license; see the
|
||||||
|
\fILICENSE\fR file distributed with this source.
|
||||||
26
src/funstx.c
26
src/funstx.c
|
|
@ -16,7 +16,7 @@
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
static void usage(const char *prog) {
|
static void usage(const char *prog) {
|
||||||
fprintf(stderr, "Usage: %s [--fix] <file1.fun> [file2.fun ...]\n", prog);
|
fprintf(stderr, "Usage: %s [--fix] [--quiet] <file1.fun> [file2.fun ...]\n", prog);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read entire file into a malloc'd buffer terminated with '\0'. Returns 1 on success. */
|
/* Read entire file into a malloc'd buffer terminated with '\0'. Returns 1 on success. */
|
||||||
|
|
@ -244,16 +244,32 @@ static char *apply_fixes(const char *src, size_t len, size_t *out_len) {
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
int do_fix = 0;
|
int do_fix = 0;
|
||||||
|
int quiet = 0;
|
||||||
int first_file_arg = 1;
|
int first_file_arg = 1;
|
||||||
|
|
||||||
|
// Parse leading flags
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
if (strcmp(argv[i], "--fix") == 0) {
|
if (strcmp(argv[i], "--fix") == 0) {
|
||||||
do_fix = 1;
|
do_fix = 1;
|
||||||
first_file_arg++;
|
first_file_arg++;
|
||||||
} else
|
continue;
|
||||||
break;
|
}
|
||||||
|
if (strcmp(argv[i], "--quiet") == 0) {
|
||||||
|
quiet = 1;
|
||||||
|
first_file_arg++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// stop on first non-flag
|
||||||
|
if (argv[i][0] != '-') break;
|
||||||
|
// unknown flag -> usage error
|
||||||
|
if (strncmp(argv[i], "--", 2) == 0) {
|
||||||
|
usage(argv[0]);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 1 + (do_fix ? 1 : 0) + 1) {
|
if (first_file_arg >= argc) {
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
@ -328,7 +344,7 @@ int main(int argc, char **argv) {
|
||||||
continue; // keep checking remaining files
|
continue; // keep checking remaining files
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "%s: OK\n", path);
|
if (!quiet) fprintf(stdout, "%s: OK\n", path);
|
||||||
bytecode_free(bc);
|
bytecode_free(bc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue