typeruby 0.1.0 → 0.1.1

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: 0c052303d712735defd42407f4c9564ca278ed8e68f5e656e356db8245cbdf1c
4
+ data.tar.gz: 1a9bb383e7162f87aafc93a459cc87ff9bc7b942d49cb4fd0b6f63b3b9e7f563
5
5
  SHA512:
6
- metadata.gz: 971dd33749f19c9f0e1964368bb3f2208fdd935ca1d43f33b19586267390982da92cd03e40637d4bfc6eb412f50022a0ca2a91f1e7872867337c6027f744b624
7
- data.tar.gz: dbe670476d0d48bd1a544cbf855a7b7a5914bac73c8d367042fe7c8e21f3d818eabca871eaf69dba546fc7947db41c18abf5d9576c521086039e7c277e47661b
6
+ metadata.gz: ad9c25fc81b8e3c1978bd5286bd47c78673c8ba2f794668660f5d2582b0e5f9ce7a46814d9efe691baa258ebdb1b5e5e77dec0edaab0ebc8873ed47ed72dd63a
7
+ data.tar.gz: e05a530783deafa55d22776f9bca6c4f9e4a1dcabcb0cfb231fca95d4b88b440eaac520de664b5f7be1c14c45a8f76c4b2729ca3a3e17a7592c3794b8ceed506
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.1'
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/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.1
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: {}