typeruby 0.1.0 → 0.1.2
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 +4 -4
- data/bin/typeruby +0 -0
- data/bin/typeruby-mac +0 -0
- data/bin/typeruby.exe +0 -0
- data/bin/typeruby.gemspec +7 -6
- data/compile.js +10 -0
- data/compile.ts +10 -0
- data/index.js +11 -0
- data/index.ts +13 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 269079e8b10c5ba5a07c5233855e69fe8ca04afd9dbb1ccf2c6c066c655541ac
|
|
4
|
+
data.tar.gz: 5c20b3989759ebe16e2bcc620294bc40366c9568b2960db9a7e51883dcedc300
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 74ef2179bb156014d79aa5a6c7246bb31737bd88e7d9399508bedbfd5a62f2621ac9d5f89a8019e73c741895cf449c5a36791bdf50af405a3df9df92e64057ac
|
|
7
|
+
data.tar.gz: f8d6f9c2ff3774321a86b0acdfc905b8f5f87afedd9dbb2690e4bef0f176b7bed4035caf3ec6e47772a77e2f0b120f0a8169ba33e10454130135063ece6386b6
|
data/bin/typeruby
CHANGED
|
Binary file
|
data/bin/typeruby-mac
CHANGED
|
Binary file
|
data/bin/typeruby.exe
CHANGED
|
Binary file
|
data/bin/typeruby.gemspec
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = 'typeruby'
|
|
3
|
-
s.version = '0.1.
|
|
3
|
+
s.version = '0.1.2'
|
|
4
4
|
s.summary = 'Typeruby CLI (TypeScript-powered) for Ruby'
|
|
5
5
|
s.description = 'Reads .trb files, checks type annotations, and generates pure Ruby.'
|
|
6
6
|
s.authors = ["yangycl"]
|
|
7
7
|
s.email = 'yangyangyclee@gmail.com'
|
|
8
|
+
s.homepage = 'https://github.com/yangycl/typeruby'
|
|
9
|
+
s.license = 'MIT'
|
|
8
10
|
|
|
9
|
-
# 包含 bin 裡的執行檔 +
|
|
10
|
-
s.files = Dir['bin/*'] + Dir['*.*'].reject { |f| f =~ /(typeruby\.gemspec|typeruby-.*\.gem)/ }
|
|
11
|
+
# 包含 bin 裡的執行檔 + 根目錄源碼,但排除 gemspec、gem、node_modules 和隱藏檔
|
|
12
|
+
s.files = Dir['bin/*'] + Dir['*.*'].reject { |f| f =~ /(typeruby\.gemspec|typeruby-.*\.gem|node_modules|\.gitignore)/ }
|
|
11
13
|
|
|
12
|
-
#
|
|
14
|
+
# 指定 bin 執行檔
|
|
13
15
|
s.executables = Dir['bin/*'].map { |f| File.basename(f) }
|
|
14
16
|
|
|
15
|
-
#
|
|
17
|
+
# 目前源碼在根目錄
|
|
16
18
|
s.require_paths = ['.']
|
|
17
|
-
s.license = 'MIT'
|
|
18
19
|
end
|
data/compile.js
CHANGED
|
@@ -28,6 +28,16 @@ function typeChecking(value, type) {
|
|
|
28
28
|
isError: !(/\{.*\}/.test(value)),
|
|
29
29
|
type: type
|
|
30
30
|
};
|
|
31
|
+
case "[]":
|
|
32
|
+
return {
|
|
33
|
+
isError: !(/\[.*\]/.test(value)),
|
|
34
|
+
type: type
|
|
35
|
+
};
|
|
36
|
+
case "{}":
|
|
37
|
+
return {
|
|
38
|
+
isError: !(/\{.*\}/.test(value)),
|
|
39
|
+
type: type
|
|
40
|
+
};
|
|
31
41
|
default:
|
|
32
42
|
return {
|
|
33
43
|
isError: true,
|
data/compile.ts
CHANGED
|
@@ -29,6 +29,16 @@ function typeChecking(value:string, type:string):typeCheck{
|
|
|
29
29
|
isError:!(/\{.*\}/.test(value)),
|
|
30
30
|
type:type
|
|
31
31
|
}
|
|
32
|
+
case "[]":
|
|
33
|
+
return{
|
|
34
|
+
isError:!(/\[.*\]/.test(value)),
|
|
35
|
+
type:type
|
|
36
|
+
}
|
|
37
|
+
case "{}":
|
|
38
|
+
return{
|
|
39
|
+
isError:!(/\{.*\}/.test(value)),
|
|
40
|
+
type:type
|
|
41
|
+
}
|
|
32
42
|
default:
|
|
33
43
|
return{
|
|
34
44
|
isError:true,
|
data/index.js
CHANGED
|
@@ -6,18 +6,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const fs_1 = __importDefault(require("fs"));
|
|
7
7
|
var code = fs_1.default.readFileSync(process.argv[2], 'utf8');
|
|
8
8
|
const compile_1 = require("./compile");
|
|
9
|
+
var varreble = {};
|
|
9
10
|
function analyzeCode(code) {
|
|
10
11
|
const lines = code.split('\n');
|
|
11
12
|
lines.forEach((line, index) => {
|
|
12
13
|
const parts = line.split(/:?\s+/);
|
|
13
14
|
if (parts.length === 3) {
|
|
14
15
|
const [varName, varType, varValue] = parts;
|
|
16
|
+
varreble[line.replace(/:[A-z]|[a-z]\s*=\s*.*/, "")] = varType;
|
|
15
17
|
const result = (0, compile_1.typeChecking)(varValue, varType);
|
|
16
18
|
if (result.isError) {
|
|
17
19
|
throw new Error(`Type error on line ${index + 1}: Expected ${varType} but got value ${varValue}`);
|
|
18
20
|
}
|
|
19
21
|
lines[index] = `${varName} = ${varValue}`;
|
|
20
22
|
}
|
|
23
|
+
else if (Object.keys(varreble).includes(line.replace(/\s*=\s*.*/, ""))) {
|
|
24
|
+
const name = line.replace(/\s*=\s*.*/, "").trim();
|
|
25
|
+
const value = (line.match(/\s*=\s*.*/)?.[0] ?? "").replace("=", "").trim();
|
|
26
|
+
const type = varreble[name].trim();
|
|
27
|
+
const result = (0, compile_1.typeChecking)(value, type);
|
|
28
|
+
if (result.isError) {
|
|
29
|
+
throw new Error(`Type error on line ${index + 1}: Expected ${type} but got value ${value}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
21
32
|
});
|
|
22
33
|
return lines.join("\n");
|
|
23
34
|
}
|
data/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
var code:string = fs.readFileSync(process.argv[2], 'utf8');
|
|
3
3
|
import {typeChecking} from './compile';
|
|
4
|
+
var varreble:Record<string, string> = {}
|
|
4
5
|
|
|
5
6
|
function analyzeCode(code:string):string{
|
|
6
7
|
const lines = code.split('\n');
|
|
@@ -8,12 +9,23 @@ function analyzeCode(code:string):string{
|
|
|
8
9
|
const parts = line.split(/:?\s+/);
|
|
9
10
|
if(parts.length === 3){
|
|
10
11
|
const [varName, varType, varValue] = parts;
|
|
12
|
+
varreble[line.replace(/:[A-z]|[a-z]\s*=\s*.*/, "")] = varType
|
|
13
|
+
|
|
11
14
|
const result = typeChecking(varValue, varType);
|
|
12
15
|
if(result.isError){
|
|
13
16
|
throw new Error(`Type error on line ${index + 1}: Expected ${varType} but got value ${varValue}`);
|
|
14
17
|
}
|
|
15
18
|
lines[index] = `${varName} = ${varValue}`
|
|
16
|
-
}
|
|
19
|
+
}else if(Object.keys(varreble).includes(line.replace(/\s*=\s*.*/, ""))){
|
|
20
|
+
const name = line.replace(/\s*=\s*.*/, "").trim()
|
|
21
|
+
const value = (line.match(/\s*=\s*.*/)?.[0] ?? "").replace("=", "").trim();
|
|
22
|
+
const type = varreble[name].trim()
|
|
23
|
+
const result = typeChecking(value, type)
|
|
24
|
+
if(result.isError){
|
|
25
|
+
throw new Error(`Type error on line ${index + 1}: Expected ${type} but got value ${value}`)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
17
29
|
});
|
|
18
30
|
return lines.join("\n")
|
|
19
31
|
}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: typeruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- yangycl
|
|
@@ -31,6 +31,7 @@ files:
|
|
|
31
31
|
- package.json
|
|
32
32
|
- test.py
|
|
33
33
|
- tsconfig.json
|
|
34
|
+
homepage: https://github.com/yangycl/typeruby
|
|
34
35
|
licenses:
|
|
35
36
|
- MIT
|
|
36
37
|
metadata: {}
|