Add MessagePack support to Typescript. C# Is still unsupported
This commit is contained in:
parent
6236a14377
commit
491e1ac052
25
lib/jrpc.js
25
lib/jrpc.js
@ -9876,7 +9876,7 @@ function parse(tokens, file) {
|
|||||||
// src/ir.ts
|
// src/ir.ts
|
||||||
var import_debug = __toESM(require_src());
|
var import_debug = __toESM(require_src());
|
||||||
var log = (0, import_debug.default)("app");
|
var log = (0, import_debug.default)("app");
|
||||||
var builtin = ["number", "string", "boolean"];
|
var BUILTIN = ["number", "string", "boolean"];
|
||||||
var IRError = class extends Error {
|
var IRError = class extends Error {
|
||||||
constructor(statement, message) {
|
constructor(statement, message) {
|
||||||
super("Error building IR: " + message);
|
super("Error building IR: " + message);
|
||||||
@ -9885,6 +9885,7 @@ var IRError = class extends Error {
|
|||||||
};
|
};
|
||||||
function get_ir(parsed) {
|
function get_ir(parsed) {
|
||||||
log("Generatie IR from parse output");
|
log("Generatie IR from parse output");
|
||||||
|
let builtin = [...BUILTIN];
|
||||||
let defined = [];
|
let defined = [];
|
||||||
let types = [];
|
let types = [];
|
||||||
let enums = [];
|
let enums = [];
|
||||||
@ -9936,18 +9937,18 @@ function get_ir(parsed) {
|
|||||||
throw new IRError(statement, `Type ${statement.name} already defined!`);
|
throw new IRError(statement, `Type ${statement.name} already defined!`);
|
||||||
}
|
}
|
||||||
let last = -1;
|
let last = -1;
|
||||||
let values = statement.values.map((valueS) => {
|
let values = statement.values.map((values2) => {
|
||||||
let value = last + 1;
|
let value = last + 1;
|
||||||
if (valueS.value) {
|
if (values2.value) {
|
||||||
if (valueS.value <= last) {
|
if (values2.value <= last) {
|
||||||
throw new IRError(statement, "Enum value must be larger than the previous one!");
|
throw new IRError(statement, "Enum value must be larger than the previous one!");
|
||||||
} else {
|
} else {
|
||||||
value = valueS.value;
|
value = values2.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
last = value;
|
last = value;
|
||||||
return {
|
return {
|
||||||
name: valueS.name,
|
name: values2.name,
|
||||||
value
|
value
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -10045,6 +10046,9 @@ function get_ir(parsed) {
|
|||||||
]);
|
]);
|
||||||
} else if (statement.type == "define") {
|
} else if (statement.type == "define") {
|
||||||
options[statement.key] = statement.value;
|
options[statement.key] = statement.value;
|
||||||
|
if (statement.key == "use_messagepack" && statement.value == "true") {
|
||||||
|
builtin.push("bytes");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new IRError(statement, "Invalid statement!");
|
throw new IRError(statement, "Invalid statement!");
|
||||||
}
|
}
|
||||||
@ -10118,7 +10122,8 @@ var conversion = {
|
|||||||
boolean: "boolean",
|
boolean: "boolean",
|
||||||
number: "number",
|
number: "number",
|
||||||
string: "string",
|
string: "string",
|
||||||
void: "void"
|
void: "void",
|
||||||
|
bytes: "Uint8Array"
|
||||||
};
|
};
|
||||||
function toJSType(type) {
|
function toJSType(type) {
|
||||||
return conversion[type] || type;
|
return conversion[type] || type;
|
||||||
@ -10435,7 +10440,8 @@ var conversion2 = {
|
|||||||
boolean: "bool",
|
boolean: "bool",
|
||||||
number: "double",
|
number: "double",
|
||||||
string: "string",
|
string: "string",
|
||||||
void: "void"
|
void: "void",
|
||||||
|
bytes: ""
|
||||||
};
|
};
|
||||||
function toCSharpType(type) {
|
function toCSharpType(type) {
|
||||||
return conversion2[type] || type;
|
return conversion2[type] || type;
|
||||||
@ -10446,6 +10452,9 @@ var CSharpTarget = class extends CompileTarget {
|
|||||||
return this.options.csharp_namespace || "JRPC";
|
return this.options.csharp_namespace || "JRPC";
|
||||||
}
|
}
|
||||||
start() {
|
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"));
|
this.writeFile(this.namespace + ".csproj", this.getTemplate("CSharp/CSharp.csproj"));
|
||||||
const fixNS = (input) => input.replace("__NAMESPACE__", this.namespace);
|
const fixNS = (input) => input.replace("__NAMESPACE__", this.namespace);
|
||||||
const copyClass = (name) => this.writeFile(name + ".cs", fixNS(this.getTemplate(`CSharp/${name}.cs`)));
|
const copyClass = (name) => this.writeFile(name + ".cs", fixNS(this.getTemplate(`CSharp/${name}.cs`)));
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hibas123/jrpcgen",
|
"name": "@hibas123/jrpcgen",
|
||||||
"version": "1.0.19",
|
"version": "1.0.20",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"packageManager": "yarn@3.1.1",
|
"packageManager": "yarn@3.1.1",
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
|
|
||||||
export abstract class CompileTarget<T = any> {
|
export abstract class CompileTarget<T = any> {
|
||||||
abstract name: string;
|
abstract name: string;
|
||||||
constructor(private outputFolder: string, protected options: T) {
|
constructor(private outputFolder: string, protected options: T & { use_messagepack: boolean }) {
|
||||||
if (!FS.existsSync(outputFolder)) {
|
if (!FS.existsSync(outputFolder)) {
|
||||||
FS.mkdirSync(outputFolder, {
|
FS.mkdirSync(outputFolder, {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
|
16
src/ir.ts
16
src/ir.ts
@ -2,7 +2,7 @@ import type { Parsed, StatementNode } from "./parser";
|
|||||||
import dbg from "debug";
|
import dbg from "debug";
|
||||||
const log = dbg("app");
|
const log = dbg("app");
|
||||||
|
|
||||||
const builtin = ["number", "string", "boolean"];
|
const BUILTIN = ["number", "string", "boolean"];
|
||||||
|
|
||||||
export class IRError extends Error {
|
export class IRError extends Error {
|
||||||
constructor(public statement: StatementNode, message: string) {
|
constructor(public statement: StatementNode, message: string) {
|
||||||
@ -68,6 +68,7 @@ export type IR = {
|
|||||||
|
|
||||||
export default function get_ir(parsed: Parsed): IR {
|
export default function get_ir(parsed: Parsed): IR {
|
||||||
log("Generatie IR from parse output");
|
log("Generatie IR from parse output");
|
||||||
|
let builtin = [...BUILTIN];
|
||||||
let defined: string[] = [];
|
let defined: string[] = [];
|
||||||
let types: string[] = [];
|
let types: string[] = [];
|
||||||
let enums: string[] = [];
|
let enums: string[] = [];
|
||||||
@ -148,23 +149,23 @@ export default function get_ir(parsed: Parsed): IR {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let last = -1;
|
let last = -1;
|
||||||
let values = statement.values.map<EnumValueDefinition>((valueS) => {
|
let values = statement.values.map<EnumValueDefinition>((values) => {
|
||||||
let value = last + 1;
|
let value = last + 1;
|
||||||
if (valueS.value) {
|
if (values.value) {
|
||||||
if (valueS.value <= last) {
|
if (values.value <= last) {
|
||||||
throw new IRError(
|
throw new IRError(
|
||||||
statement,
|
statement,
|
||||||
"Enum value must be larger than the previous one!"
|
"Enum value must be larger than the previous one!"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
value = valueS.value;
|
value = values.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
last = value;
|
last = value;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: valueS.name,
|
name: values.name,
|
||||||
value,
|
value,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -282,6 +283,9 @@ export default function get_ir(parsed: Parsed): IR {
|
|||||||
]);
|
]);
|
||||||
} else if(statement.type == "define") {
|
} else if(statement.type == "define") {
|
||||||
options[statement.key] = statement.value;
|
options[statement.key] = statement.value;
|
||||||
|
if(statement.key == "use_messagepack" && statement.value == "true") {
|
||||||
|
builtin.push("bytes");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new IRError(statement, "Invalid statement!");
|
throw new IRError(statement, "Invalid statement!");
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ const conversion = {
|
|||||||
number: "double",
|
number: "double",
|
||||||
string: "string",
|
string: "string",
|
||||||
void: "void",
|
void: "void",
|
||||||
|
bytes: ""
|
||||||
};
|
};
|
||||||
|
|
||||||
function toCSharpType(type: string): string {
|
function toCSharpType(type: string): string {
|
||||||
@ -29,6 +30,9 @@ export class CSharpTarget extends CompileTarget<{ csharp_namespace: string }> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
start(): void {
|
start(): void {
|
||||||
|
if(this.options.use_messagepack == true) {
|
||||||
|
throw new Error("C# has no support for MessagePack yet!");
|
||||||
|
}
|
||||||
this.writeFile(
|
this.writeFile(
|
||||||
this.namespace + ".csproj",
|
this.namespace + ".csproj",
|
||||||
this.getTemplate("CSharp/CSharp.csproj")
|
this.getTemplate("CSharp/CSharp.csproj")
|
||||||
|
@ -16,6 +16,7 @@ const conversion = {
|
|||||||
number: "number",
|
number: "number",
|
||||||
string: "string",
|
string: "string",
|
||||||
void: "void",
|
void: "void",
|
||||||
|
bytes: "Uint8Array"
|
||||||
};
|
};
|
||||||
|
|
||||||
function toJSType(type: string): string {
|
function toJSType(type: string): string {
|
||||||
|
Loading…
Reference in New Issue
Block a user