Add MessagePack support to Typescript. C# Is still unsupported

This commit is contained in:
K35 2022-01-10 20:17:25 +00:00
parent 6236a14377
commit 491e1ac052
6 changed files with 34 additions and 16 deletions

View File

@ -9876,7 +9876,7 @@ function parse(tokens, file) {
// src/ir.ts
var import_debug = __toESM(require_src());
var log = (0, import_debug.default)("app");
var builtin = ["number", "string", "boolean"];
var BUILTIN = ["number", "string", "boolean"];
var IRError = class extends Error {
constructor(statement, message) {
super("Error building IR: " + message);
@ -9885,6 +9885,7 @@ var IRError = class extends Error {
};
function get_ir(parsed) {
log("Generatie IR from parse output");
let builtin = [...BUILTIN];
let defined = [];
let types = [];
let enums = [];
@ -9936,18 +9937,18 @@ function get_ir(parsed) {
throw new IRError(statement, `Type ${statement.name} already defined!`);
}
let last = -1;
let values = statement.values.map((valueS) => {
let values = statement.values.map((values2) => {
let value = last + 1;
if (valueS.value) {
if (valueS.value <= last) {
if (values2.value) {
if (values2.value <= last) {
throw new IRError(statement, "Enum value must be larger than the previous one!");
} else {
value = valueS.value;
value = values2.value;
}
}
last = value;
return {
name: valueS.name,
name: values2.name,
value
};
});
@ -10045,6 +10046,9 @@ function get_ir(parsed) {
]);
} else if (statement.type == "define") {
options[statement.key] = statement.value;
if (statement.key == "use_messagepack" && statement.value == "true") {
builtin.push("bytes");
}
} else {
throw new IRError(statement, "Invalid statement!");
}
@ -10118,7 +10122,8 @@ var conversion = {
boolean: "boolean",
number: "number",
string: "string",
void: "void"
void: "void",
bytes: "Uint8Array"
};
function toJSType(type) {
return conversion[type] || type;
@ -10435,7 +10440,8 @@ var conversion2 = {
boolean: "bool",
number: "double",
string: "string",
void: "void"
void: "void",
bytes: ""
};
function toCSharpType(type) {
return conversion2[type] || type;
@ -10446,6 +10452,9 @@ var CSharpTarget = class extends CompileTarget {
return this.options.csharp_namespace || "JRPC";
}
start() {
if (this.options.use_messagepack == true) {
throw new Error("C# has no support for MessagePack yet!");
}
this.writeFile(this.namespace + ".csproj", this.getTemplate("CSharp/CSharp.csproj"));
const fixNS = (input) => input.replace("__NAMESPACE__", this.namespace);
const copyClass = (name) => this.writeFile(name + ".cs", fixNS(this.getTemplate(`CSharp/${name}.cs`)));

View File

@ -1,6 +1,6 @@
{
"name": "@hibas123/jrpcgen",
"version": "1.0.19",
"version": "1.0.20",
"main": "lib/index.js",
"license": "MIT",
"packageManager": "yarn@3.1.1",

View File

@ -11,7 +11,7 @@ import {
export abstract class CompileTarget<T = any> {
abstract name: string;
constructor(private outputFolder: string, protected options: T) {
constructor(private outputFolder: string, protected options: T & { use_messagepack: boolean }) {
if (!FS.existsSync(outputFolder)) {
FS.mkdirSync(outputFolder, {
recursive: true,

View File

@ -2,7 +2,7 @@ import type { Parsed, StatementNode } from "./parser";
import dbg from "debug";
const log = dbg("app");
const builtin = ["number", "string", "boolean"];
const BUILTIN = ["number", "string", "boolean"];
export class IRError extends Error {
constructor(public statement: StatementNode, message: string) {
@ -68,6 +68,7 @@ export type IR = {
export default function get_ir(parsed: Parsed): IR {
log("Generatie IR from parse output");
let builtin = [...BUILTIN];
let defined: string[] = [];
let types: string[] = [];
let enums: string[] = [];
@ -148,23 +149,23 @@ export default function get_ir(parsed: Parsed): IR {
}
let last = -1;
let values = statement.values.map<EnumValueDefinition>((valueS) => {
let values = statement.values.map<EnumValueDefinition>((values) => {
let value = last + 1;
if (valueS.value) {
if (valueS.value <= last) {
if (values.value) {
if (values.value <= last) {
throw new IRError(
statement,
"Enum value must be larger than the previous one!"
);
} else {
value = valueS.value;
value = values.value;
}
}
last = value;
return {
name: valueS.name,
name: values.name,
value,
};
});
@ -282,6 +283,9 @@ export default function get_ir(parsed: Parsed): IR {
]);
} else if(statement.type == "define") {
options[statement.key] = statement.value;
if(statement.key == "use_messagepack" && statement.value == "true") {
builtin.push("bytes");
}
} else {
throw new IRError(statement, "Invalid statement!");
}

View File

@ -15,6 +15,7 @@ const conversion = {
number: "double",
string: "string",
void: "void",
bytes: ""
};
function toCSharpType(type: string): string {
@ -29,6 +30,9 @@ export class CSharpTarget extends CompileTarget<{ csharp_namespace: string }> {
}
start(): void {
if(this.options.use_messagepack == true) {
throw new Error("C# has no support for MessagePack yet!");
}
this.writeFile(
this.namespace + ".csproj",
this.getTemplate("CSharp/CSharp.csproj")

View File

@ -16,6 +16,7 @@ const conversion = {
number: "number",
string: "string",
void: "void",
bytes: "Uint8Array"
};
function toJSType(type: string): string {