diff --git a/lib/jrpc.js b/lib/jrpc.js index 3d284c8..3668e5f 100755 --- a/lib/jrpc.js +++ b/lib/jrpc.js @@ -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`))); diff --git a/package.json b/package.json index 02ffde6..d4be947 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/compile.ts b/src/compile.ts index 2014e53..76193a9 100644 --- a/src/compile.ts +++ b/src/compile.ts @@ -11,7 +11,7 @@ import { export abstract class CompileTarget { 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, diff --git a/src/ir.ts b/src/ir.ts index dc2d810..bbb1399 100644 --- a/src/ir.ts +++ b/src/ir.ts @@ -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((valueS) => { + let values = statement.values.map((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!"); } diff --git a/src/targets/csharp.ts b/src/targets/csharp.ts index 1a44a30..b21d3ab 100644 --- a/src/targets/csharp.ts +++ b/src/targets/csharp.ts @@ -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") diff --git a/src/targets/typescript.ts b/src/targets/typescript.ts index c3dbc3d..eea40c5 100644 --- a/src/targets/typescript.ts +++ b/src/targets/typescript.ts @@ -16,6 +16,7 @@ const conversion = { number: "number", string: "string", void: "void", + bytes: "Uint8Array" }; function toJSType(type: string): string {