Skip to content

Commit

Permalink
v0.10.3 (#486)
Browse files Browse the repository at this point in the history
* Fixed bug according to #451

* Updated CHANGELOG.md

* Prettified code

* Standardised error output of the `@kipper/cli` (#489)

* Update README.md

Signed-off-by: Luna <luna.klatzer@gmail.com>

* Updated and simplified PULL_REQUEST_TEMPLATE.md

Signed-off-by: Luna <luna.klatzer@gmail.com>

* Update PULL_REQUEST_TEMPLATE.md

Signed-off-by: Luna <luna.klatzer@gmail.com>

* Update README.md

Signed-off-by: Luna <luna.klatzer@gmail.com>

* Added missing space in `kipper` README.md

Signed-off-by: Luna <luna.klatzer@gmail.com>

* Restructured CLI and implemented standardised prettified errors

* Removed suffix message from `KipperInternalError`

* Updated CHANGELOG.md

* Fixed accidentally renamed args property in `getFile`

* Fixed invalid use of `getTarget` in analyse.ts

* Renamed `getFile` to `getParseStream`

* Updated CHANGELOG.md

* Fixed `LogLevel` being too high in analyse.ts

* Fixed error being thrown in analyse.ts

The logger already handles the error, so the error must be caught and then ignored.

* Prettified code

* Updated analyse.test.ts to fit code changes

* Updated analyse.test.ts to fit code changes

* Updated CHANGELOG.md

---------

Signed-off-by: Luna <luna.klatzer@gmail.com>

---------

Signed-off-by: Luna <luna.klatzer@gmail.com>
  • Loading branch information
Luna-Klatzer authored Jul 22, 2023
1 parent d3dd21e commit 433664d
Show file tree
Hide file tree
Showing 30 changed files with 373 additions and 245 deletions.
25 changes: 24 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ To use development versions of Kipper download the

</details>

## [0.10.3] - 2023-07-22

### Added

- New modules in `@kipper/cli`:
- `input`, which contains all input-related handling functions and classes.
- `output`, which contains the output-related handling functions and classes.
- New decorator `prettifiedErrors` in `@kipper/cli`, which applies standardised error formatting to any thrown error.

### Changed

- Standardised error output for the CLI as described in [#435](https://github.com/Luna-Klatzer/Kipper/issues/435).
- Error message of `KipperInternalError`, which does not have " - Report this bug to the developer using the traceback!"
as a suffix anymore.
- Changed success message of the `kipper analyse` command `Finished code analysis in ...` to `Done in ...`.
- Renamed `getFile` to `getParseStream`.

### Fixed

- CLI bug where the `-t` shortcut flag was incorrectly shown for the command `help compile`.
([#451](https://github.com/Luna-Klatzer/Kipper/issues/451))

## [0.10.2] - 2023-06-16

### Added
Expand Down Expand Up @@ -1177,7 +1199,8 @@ To use development versions of Kipper download the

- Updated file structure to separate `commands` (for `oclif`) and `compiler` (for the compiler source-code)

[unreleased]: https://github.com/Luna-Klatzer/Kipper/compare/v0.10.2...HEAD
[unreleased]: https://github.com/Luna-Klatzer/Kipper/compare/v0.10.3...HEAD
[0.10.3]: https://github.com/Luna-Klatzer/Kipper/compare/v0.10.2...v0.10.3
[0.10.2]: https://github.com/Luna-Klatzer/Kipper/compare/v0.10.1...v0.10.2
[0.10.1]: https://github.com/Luna-Klatzer/Kipper/compare/v0.10.0...v0.10.1
[0.10.0]: https://github.com/Luna-Klatzer/Kipper/compare/v0.9.2...v0.10.0
Expand Down
2 changes: 0 additions & 2 deletions bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ else
git commit -a -m "Release $1"
git tag -a "v$1" -m "Release $1"

git commit -a -m "Release 0.10.2";git tag -a "v0.10.2" -m "Release 0.10.2"

# Update lock files
echo "-- Updating lock files"
pnpm install
Expand Down
37 changes: 16 additions & 21 deletions kipper/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ and the [Kipper website](https://kipper-lang.org)._
[![Publish size](https://badgen.net/packagephobia/publish/@kipper/cli)](https://packagephobia.com/result?p=@kipper/cli)

<!-- toc -->

- [Kipper CLI - `@kipper/cli`](#kipper-cli---kippercli)
- [Usage](#usage)
- [Commands](#commands)
* [Kipper CLI - `@kipper/cli` 🦊🖥️](#kipper-cli---kippercli-️)
* [Usage](#usage)
* [Commands](#commands)
<!-- tocstop -->

## General Information
Expand All @@ -39,30 +38,27 @@ and the [Kipper website](https://kipper-lang.org)._
# Usage

<!-- usage -->

```sh-session
$ npm install -g @kipper/cli
$ kipper COMMAND
running command...
$ kipper (--version)
@kipper/cli/0.10.2 linux-x64 node-v18.15.0
@kipper/cli/0.10.3 linux-x64 node-v20.3.1
$ kipper --help [COMMAND]
USAGE
$ kipper COMMAND
...
```

<!-- usagestop -->

# Commands

<!-- commands -->

- [`kipper analyse [FILE]`](#kipper-analyse-file)
- [`kipper compile [FILE]`](#kipper-compile-file)
- [`kipper help [COMMAND]`](#kipper-help-command)
- [`kipper run [FILE]`](#kipper-run-file)
- [`kipper version`](#kipper-version)
* [`kipper analyse [FILE]`](#kipper-analyse-file)
* [`kipper compile [FILE]`](#kipper-compile-file)
* [`kipper help [COMMAND]`](#kipper-help-command)
* [`kipper run [FILE]`](#kipper-run-file)
* [`kipper version`](#kipper-version)

## `kipper analyse [FILE]`

Expand All @@ -84,7 +80,7 @@ OPTIONS
-w, --[no-]warnings Show warnings that were emitted during the analysis.
```

_See code: [src/commands/analyse.ts](https://github.com/Luna-Klatzer/Kipper/blob/v0.10.2/kipper/cli/src/commands/analyse.ts)_
_See code: [src/commands/analyse.ts](https://github.com/Luna-Klatzer/Kipper/blob/v0.10.3/kipper/cli/src/commands/analyse.ts)_

## `kipper compile [FILE]`

Expand Down Expand Up @@ -112,18 +108,18 @@ OPTIONS
-s, --string-code=string-code The content of a Kipper file that can be passed as a replacement for the 'file'
parameter.
-t, --[no-]log-timestamp Show the timestamp of each log message.
-t, --target=js|ts [default: js] The target language where the compiled program should be emitted to.
-w, --[no-]warnings Show warnings that were emitted during the compilation.
--[no-]abort-on-first-error Abort on the first error the compiler encounters.
--[no-]log-timestamp Show the timestamp of each log message.
--[no-]recover Recover from compiler errors and log all detected semantic issues.
```

_See code: [src/commands/compile.ts](https://github.com/Luna-Klatzer/Kipper/blob/v0.10.2/kipper/cli/src/commands/compile.ts)_
_See code: [src/commands/compile.ts](https://github.com/Luna-Klatzer/Kipper/blob/v0.10.3/kipper/cli/src/commands/compile.ts)_

## `kipper help [COMMAND]`

Expand All @@ -140,7 +136,7 @@ OPTIONS
--all see all commands in CLI
```

_See code: [src/commands/help.ts](https://github.com/Luna-Klatzer/Kipper/blob/v0.10.2/kipper/cli/src/commands/help.ts)_
_See code: [src/commands/help.ts](https://github.com/Luna-Klatzer/Kipper/blob/v0.10.3/kipper/cli/src/commands/help.ts)_

## `kipper run [FILE]`

Expand Down Expand Up @@ -179,7 +175,7 @@ OPTIONS
--[no-]recover Recover from compiler errors and display all detected compiler errors.
```

_See code: [src/commands/run.ts](https://github.com/Luna-Klatzer/Kipper/blob/v0.10.2/kipper/cli/src/commands/run.ts)_
_See code: [src/commands/run.ts](https://github.com/Luna-Klatzer/Kipper/blob/v0.10.3/kipper/cli/src/commands/run.ts)_

## `kipper version`

Expand All @@ -190,8 +186,7 @@ USAGE
$ kipper version
```

_See code: [src/commands/version.ts](https://github.com/Luna-Klatzer/Kipper/blob/v0.10.2/kipper/cli/src/commands/version.ts)_

_See code: [src/commands/version.ts](https://github.com/Luna-Klatzer/Kipper/blob/v0.10.3/kipper/cli/src/commands/version.ts)_
<!-- commandsstop -->

## Contributing to Kipper
Expand Down
2 changes: 1 addition & 1 deletion kipper/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@kipper/cli",
"description": "The Kipper Command Line Interface (CLI).",
"version": "0.10.2",
"version": "0.10.3",
"author": "Luna-Klatzer @Luna-Klatzer",
"bin": {
"kipper": "./bin/run"
Expand Down
68 changes: 37 additions & 31 deletions kipper/cli/src/commands/analyse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
* 'analyse' command for analysing the syntax of a file.
* @since 0.0.5
*/
import type { args } from "@oclif/parser";
import { Command, flags } from "@oclif/command";
import { KipperCompiler, KipperError, KipperLogger, KipperParseStream, LogLevel } from "@kipper/core";
import { KipperEncodings, KipperParseFile, verifyEncoding } from "../file-stream";
import { CLIEmitHandler, defaultCliLogger } from "../logger";
import { IFlag } from "@oclif/command/lib/flags";
import { getFile } from "../compile";
import { KipperCompiler, KipperLogger, KipperParseStream, LogLevel } from "@kipper/core";
import { CLIEmitHandler } from "../logger";
import { getParseStream, KipperEncodings, verifyEncoding } from "../input/";
import { prettifiedErrors } from "../decorators";

export default class Analyse extends Command {
static override description = "Analyse a Kipper file and validate its syntax and semantic integrity.";
static override description: string = "Analyse a Kipper file and validate its syntax and semantic integrity.";

// TODO! Add examples when the command moves out of development
static override examples = [];
static override examples: Array<string> = [];

static override args = [
static override args: args.Input = [
{
name: "file",
required: false,
description: "The file that should be analysed.",
},
];

static override flags: Record<string, IFlag<any>> = {
static override flags: flags.Input<any> = {
encoding: flags.string({
char: "e",
default: "utf8",
Expand All @@ -42,37 +42,43 @@ export default class Analyse extends Command {
}),
};

public async run() {
/**
* Gets the configuration for the invocation of this command.
* @private
*/
private async getRunConfig() {
const { args, flags } = this.parse(Analyse);
const logger = new KipperLogger(CLIEmitHandler.emit, LogLevel.INFO, flags["warnings"]);
const compiler = new KipperCompiler(logger);

// Fetch the file
let file: KipperParseFile | KipperParseStream = await getFile(args, flags);
// Compilation-required
const stream: KipperParseStream = await getParseStream(args, flags);

return {
args,
flags,
config: {
stream,
},
};
}

// Compilation configuration
const parseStream = new KipperParseStream({
name: file.name,
filePath: file instanceof KipperParseFile ? file.absolutePath : file.filePath,
charStream: file.charStream,
});
@prettifiedErrors<Analyse>()
public async run() {
const { flags, config } = await this.getRunConfig();
const logger = new KipperLogger(CLIEmitHandler.emit, LogLevel.INFO, flags["warnings"]);
const compiler = new KipperCompiler(logger);

// Start timer for processing
const startTime: number = new Date().getTime();

// Analyse the file
// Actual processing by the compiler
try {
await compiler.syntaxAnalyse(parseStream);

// Finished!
const duration: number = (new Date().getTime() - startTime) / 1000;
await logger.info(`Finished code analysis in ${duration}s.`);
await compiler.syntaxAnalyse(config.stream);
} catch (e) {
// In case the error is of type KipperError, exit the program, as the logger should have already handled the
// output of the error and traceback.
if (!(e instanceof KipperError)) {
defaultCliLogger.fatal(`Encountered unexpected internal error: \n${(<Error>e).stack}`);
}
return; // Ignore the error thrown by the compiler (the logger already logged it)
}

// Finished!
const duration: number = (new Date().getTime() - startTime) / 1000;
await logger.info(`Done in ${duration}s.`);
}
}
Loading

0 comments on commit 433664d

Please sign in to comment.