typeruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 56b52010757983802dba9d2213e38112849be84200f305500d19b32b52fccb13
4
+ data.tar.gz: 9284e4728bc6a3a392086905fec96564ab9caf9518e082b7c0b614d5c4f3520c
5
+ SHA512:
6
+ metadata.gz: 971dd33749f19c9f0e1964368bb3f2208fdd935ca1d43f33b19586267390982da92cd03e40637d4bfc6eb412f50022a0ca2a91f1e7872867337c6027f744b624
7
+ data.tar.gz: dbe670476d0d48bd1a544cbf855a7b7a5914bac73c8d367042fe7c8e21f3d818eabca871eaf69dba546fc7947db41c18abf5d9576c521086039e7c277e47661b
data/bin/typeruby ADDED
Binary file
data/bin/typeruby-mac ADDED
Binary file
data/bin/typeruby.exe ADDED
Binary file
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'typeruby'
3
+ s.version = '0.1.0'
4
+ s.summary = 'Typeruby CLI (TypeScript-powered) for Ruby'
5
+ s.description = 'Reads .trb files, checks type annotations, and generates pure Ruby.'
6
+ s.authors = ["yangycl"]
7
+ s.email = 'yangyangyclee@gmail.com'
8
+
9
+ # 包含 bin 裡的執行檔 + 根目錄所有源碼,但排除 gemspec 和 gem 檔
10
+ s.files = Dir['bin/*'] + Dir['*.*'].reject { |f| f =~ /(typeruby\.gemspec|typeruby-.*\.gem)/ }
11
+
12
+ # 指定執行檔
13
+ s.executables = Dir['bin/*'].map { |f| File.basename(f) }
14
+
15
+ # 這裡因為源碼在根目錄,所以 require_paths 設為 ['.']
16
+ s.require_paths = ['.']
17
+ s.license = 'MIT'
18
+ end
data/compile.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.typeChecking = typeChecking;
4
+ function typeChecking(value, type) {
5
+ switch (type) {
6
+ case "Integer":
7
+ return {
8
+ isError: !(/^\d+\.?\d*$/.test(value)),
9
+ type: type
10
+ };
11
+ case "String":
12
+ return {
13
+ isError: !(/("|').*?("|')/.test(value)),
14
+ type: type
15
+ };
16
+ case "Boolean":
17
+ return {
18
+ isError: !(/true|false/.test(value)),
19
+ type: type
20
+ };
21
+ case "Array":
22
+ return {
23
+ isError: !(/\[.*\]/.test(value)),
24
+ type: type
25
+ };
26
+ case "Hash":
27
+ return {
28
+ isError: !(/\{.*\}/.test(value)),
29
+ type: type
30
+ };
31
+ default:
32
+ return {
33
+ isError: true,
34
+ type: type
35
+ };
36
+ }
37
+ }
data/compile.ts ADDED
@@ -0,0 +1,39 @@
1
+ interface typeCheck{
2
+ isError:boolean,
3
+ type:string
4
+ }
5
+ function typeChecking(value:string, type:string):typeCheck{
6
+ switch(type){
7
+ case"Integer":
8
+ return{
9
+ isError:!(/^\d+\.?\d*$/.test(value)),
10
+ type:type
11
+ };
12
+ case"String":
13
+ return{
14
+ isError:!(/("|').*?("|')/.test(value)),
15
+ type:type
16
+ };
17
+ case"Boolean":
18
+ return{
19
+ isError:!(/true|false/.test(value)),
20
+ type:type
21
+ }
22
+ case"Array":
23
+ return{
24
+ isError:!(/\[.*\]/.test(value)),
25
+ type:type
26
+ }
27
+ case"Hash":
28
+ return{
29
+ isError:!(/\{.*\}/.test(value)),
30
+ type:type
31
+ }
32
+ default:
33
+ return{
34
+ isError:true,
35
+ type:type
36
+ };
37
+ }
38
+ }
39
+ export {typeChecking, typeCheck};
data/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = __importDefault(require("fs"));
7
+ var code = fs_1.default.readFileSync(process.argv[2], 'utf8');
8
+ const compile_1 = require("./compile");
9
+ function analyzeCode(code) {
10
+ const lines = code.split('\n');
11
+ lines.forEach((line, index) => {
12
+ const parts = line.split(/:?\s+/);
13
+ if (parts.length === 3) {
14
+ const [varName, varType, varValue] = parts;
15
+ const result = (0, compile_1.typeChecking)(varValue, varType);
16
+ if (result.isError) {
17
+ throw new Error(`Type error on line ${index + 1}: Expected ${varType} but got value ${varValue}`);
18
+ }
19
+ lines[index] = `${varName} = ${varValue}`;
20
+ }
21
+ });
22
+ return lines.join("\n");
23
+ }
24
+ let newCode = analyzeCode(code);
25
+ fs_1.default.writeFileSync(process.argv[2].replace(".trb", "rb"), newCode, { encoding: "utf-8" });
data/index.ts ADDED
@@ -0,0 +1,21 @@
1
+ import fs from 'fs';
2
+ var code:string = fs.readFileSync(process.argv[2], 'utf8');
3
+ import {typeChecking} from './compile';
4
+
5
+ function analyzeCode(code:string):string{
6
+ const lines = code.split('\n');
7
+ lines.forEach((line, index) => {
8
+ const parts = line.split(/:?\s+/);
9
+ if(parts.length === 3){
10
+ const [varName, varType, varValue] = parts;
11
+ const result = typeChecking(varValue, varType);
12
+ if(result.isError){
13
+ throw new Error(`Type error on line ${index + 1}: Expected ${varType} but got value ${varValue}`);
14
+ }
15
+ lines[index] = `${varName} = ${varValue}`
16
+ }
17
+ });
18
+ return lines.join("\n")
19
+ }
20
+ let newCode = analyzeCode(code);
21
+ fs.writeFileSync(process.argv[2].replace(".trb", "rb"), newCode, {encoding:"utf-8"})
data/package-lock.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "typepy",
3
+ "lockfileVersion": 3,
4
+ "requires": true,
5
+ "packages": {
6
+ "": {
7
+ "dependencies": {
8
+ "@types/node": "^25.1.0"
9
+ }
10
+ },
11
+ "node_modules/@types/node": {
12
+ "version": "25.1.0",
13
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-25.1.0.tgz",
14
+ "integrity": "sha512-t7frlewr6+cbx+9Ohpl0NOTKXZNV9xHRmNOvql47BFJKcEG1CxtxlPEEe+gR9uhVWM4DwhnvTF110mIL4yP9RA==",
15
+ "dependencies": {
16
+ "undici-types": "~7.16.0"
17
+ }
18
+ },
19
+ "node_modules/undici-types": {
20
+ "version": "7.16.0",
21
+ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
22
+ "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="
23
+ }
24
+ }
25
+ }
data/package.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "dependencies": {
3
+ "@types/node": "^25.1.0"
4
+ },
5
+ "scripts": {
6
+ "build": "powershell -Command \"tsc; npx pkg index.js\""
7
+ }
8
+ }
data/test.py ADDED
@@ -0,0 +1 @@
1
+ a: int = ""
data/tsconfig.json ADDED
@@ -0,0 +1,111 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig to read more about this file */
4
+
5
+ /* Projects */
6
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
+
13
+ /* Language and Environment */
14
+ "target": "esnext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
+ "lib": ["ESNext"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
17
+ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
18
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
+
27
+ /* Modules */
28
+ "module": "commonjs", /* Specify what module code is generated. */
29
+ // "rootDir": "./", /* Specify the root folder within your source files. */
30
+ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
31
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
36
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38
+ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
39
+ // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
40
+ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
41
+ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
42
+ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
43
+ // "noUncheckedSideEffectImports": true, /* Check side effect imports. */
44
+ // "resolveJsonModule": true, /* Enable importing .json files. */
45
+ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
46
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
47
+
48
+ /* JavaScript Support */
49
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
50
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
51
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
52
+
53
+ /* Emit */
54
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
55
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
56
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
57
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
58
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
59
+ // "noEmit": true, /* Disable emitting files from a compilation. */
60
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
61
+ // "outDir": "./", /* Specify an output folder for all emitted files. */
62
+ // "removeComments": true, /* Disable emitting comments. */
63
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
64
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
65
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
66
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
67
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
68
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
69
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
70
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
71
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
72
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
73
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
74
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
75
+
76
+ /* Interop Constraints */
77
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
78
+ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
79
+ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
80
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
81
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
82
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
83
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
84
+
85
+ /* Type Checking */
86
+ "strict": true, /* Enable all strict type-checking options. */
87
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
88
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
89
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
90
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
91
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
92
+ // "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
93
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
94
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
95
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
96
+ // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
97
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
98
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
99
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
100
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
101
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
102
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
103
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
104
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
105
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
106
+
107
+ /* Completeness */
108
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
109
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
110
+ }
111
+ }
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: typeruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - yangycl
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Reads .trb files, checks type annotations, and generates pure Ruby.
13
+ email: yangyangyclee@gmail.com
14
+ executables:
15
+ - typeruby
16
+ - typeruby-mac
17
+ - typeruby.exe
18
+ - typeruby.gemspec
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - bin/typeruby
23
+ - bin/typeruby-mac
24
+ - bin/typeruby.exe
25
+ - bin/typeruby.gemspec
26
+ - compile.js
27
+ - compile.ts
28
+ - index.js
29
+ - index.ts
30
+ - package-lock.json
31
+ - package.json
32
+ - test.py
33
+ - tsconfig.json
34
+ licenses:
35
+ - MIT
36
+ metadata: {}
37
+ rdoc_options: []
38
+ require_paths:
39
+ - "."
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 3.6.9
52
+ specification_version: 4
53
+ summary: Typeruby CLI (TypeScript-powered) for Ruby
54
+ test_files: []