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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56b52010757983802dba9d2213e38112849be84200f305500d19b32b52fccb13
4
- data.tar.gz: 9284e4728bc6a3a392086905fec96564ab9caf9518e082b7c0b614d5c4f3520c
3
+ metadata.gz: 269079e8b10c5ba5a07c5233855e69fe8ca04afd9dbb1ccf2c6c066c655541ac
4
+ data.tar.gz: 5c20b3989759ebe16e2bcc620294bc40366c9568b2960db9a7e51883dcedc300
5
5
  SHA512:
6
- metadata.gz: 971dd33749f19c9f0e1964368bb3f2208fdd935ca1d43f33b19586267390982da92cd03e40637d4bfc6eb412f50022a0ca2a91f1e7872867337c6027f744b624
7
- data.tar.gz: dbe670476d0d48bd1a544cbf855a7b7a5914bac73c8d367042fe7c8e21f3d818eabca871eaf69dba546fc7947db41c18abf5d9576c521086039e7c277e47661b
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.0'
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 裡的執行檔 + 根目錄所有源碼,但排除 gemspecgem
10
- s.files = Dir['bin/*'] + Dir['*.*'].reject { |f| f =~ /(typeruby\.gemspec|typeruby-.*\.gem)/ }
11
+ # 包含 bin 裡的執行檔 + 根目錄源碼,但排除 gemspecgem、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
- # 這裡因為源碼在根目錄,所以 require_paths 設為 ['.']
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.0
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: {}