slashcode 0.0.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 +7 -0
- data/bin/slash +5 -0
- data/config/slashcode.toml +29 -0
- data/lib/cli.rb +45 -0
- data/lib/compile.rb +81 -0
- data/lib/translator.rb +15 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 723dfa3d023940ebefb592af8db296a1971524e15db3e8f09196d2ac9527e90d
|
4
|
+
data.tar.gz: 1608fdd5cfc4956a1fad5464b7d422027508848323187b25cf4719db13761160
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 329926811086745ba5fffcf86f2c13b863ca5492df1f3547a24b291a30ec1ed22db5e5efd023aa39ca76cfe04602350b5b4a9500b0b1411fad736552515035f3
|
7
|
+
data.tar.gz: 10b705d99fc7262bca8b357db18a45a9094b677c91918366d956a8d84c467b4b1be04c8c8b1ba8ab20a059c200a04ae65b7aa5a5a84cad086fbb0646cb01c138
|
data/bin/slash
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# ------------------------
|
2
|
+
# | SLASHCODE FUNCTIONS.TOML
|
3
|
+
# |-- This file contains all translations for slashcode functions into Ruby.
|
4
|
+
|
5
|
+
[init]
|
6
|
+
version = "dev-2"
|
7
|
+
enableimports = false
|
8
|
+
imports = ["slashcodeutils", ]
|
9
|
+
|
10
|
+
|
11
|
+
[translations]
|
12
|
+
# functions.toml: something = "do $1 $2"
|
13
|
+
# execution in SC: /something A B
|
14
|
+
# translation into Ruby: do A B
|
15
|
+
# each parameter/argument is marked by $1, $2, $3, and so on, all arguments can be selected using $0
|
16
|
+
print = "puts $0"
|
17
|
+
translate = "translator = ScTranslator.new('$1, $2'); translator.translate"
|
18
|
+
|
19
|
+
#! WARNING: Function Groups are still not functional! Do not edit this section!
|
20
|
+
#// [functiongroups]
|
21
|
+
|
22
|
+
#// [functiongroups.file]
|
23
|
+
#// select = "# | WIP |-- /file/select $0"
|
24
|
+
#// rename = "# | WIP |-- /file/rename $0"
|
25
|
+
#// upload = "# | WIP |-- /file/upload $0"
|
26
|
+
#// remove = "# | WIP |-- /file/remove $0"
|
27
|
+
|
28
|
+
[misc]
|
29
|
+
experimental = ["translate"]
|
data/lib/cli.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# ---------------
|
2
|
+
# | SLASHCODE CLI
|
3
|
+
# |-- version: dev-2
|
4
|
+
|
5
|
+
require 'thor'
|
6
|
+
require_relative "./compile.rb"
|
7
|
+
|
8
|
+
module SlashCLI
|
9
|
+
class CLI < Thor
|
10
|
+
desc "| compile <filename> <output>", "|-- Compile a slashcode file"
|
11
|
+
def compile(file: "main.slash", output: "output.rb")
|
12
|
+
puts ""
|
13
|
+
puts "Preparing compiler..."
|
14
|
+
functions_file = File.expand_path("../../config/slashcode.toml", __FILE__)
|
15
|
+
compiler = Compiler::Compiler.new(file, functions_file, output)
|
16
|
+
puts "Compiling #{file}..."
|
17
|
+
compiler.compile
|
18
|
+
puts "#{file} has been compiled to #{output}!"
|
19
|
+
puts ""
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "| help", "|-- Show help information"
|
23
|
+
def help
|
24
|
+
puts ""
|
25
|
+
puts "| Help information for the slashcode CLI:"
|
26
|
+
puts "|----------------------------------------"
|
27
|
+
puts "|"
|
28
|
+
puts "| help"
|
29
|
+
puts "|-- Show this help text"
|
30
|
+
puts "|"
|
31
|
+
puts "| compile <filename>"
|
32
|
+
puts "|-- Compile a slahscode file"
|
33
|
+
puts "|"
|
34
|
+
puts "|----------------------------------------"
|
35
|
+
puts ""
|
36
|
+
end
|
37
|
+
|
38
|
+
def method_missing(command, *args)
|
39
|
+
puts ""
|
40
|
+
puts "| Unknown subcommand: #{command}."
|
41
|
+
puts "|-- Use 'slash help' for available commands."
|
42
|
+
puts ""
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/compile.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# ---------------
|
2
|
+
# | SLASHCODE COMPILER
|
3
|
+
# |-- version: dev-1
|
4
|
+
|
5
|
+
require 'toml'
|
6
|
+
|
7
|
+
module Compiler
|
8
|
+
class Compiler
|
9
|
+
def initialize(sc_file, functions_file, output_file)
|
10
|
+
@sc_file = sc_file
|
11
|
+
@functions_file = functions_file
|
12
|
+
@output_file = output_file
|
13
|
+
end
|
14
|
+
|
15
|
+
def compile
|
16
|
+
load_functions
|
17
|
+
|
18
|
+
File.open(@output_file, 'w') do |output|
|
19
|
+
write_comments(output)
|
20
|
+
write_imports(output)
|
21
|
+
|
22
|
+
File.open(@sc_file, 'r') do |file|
|
23
|
+
file.each_line do |line|
|
24
|
+
output.puts translate_command(line) # Write the translated Ruby code to the output file
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def load_functions
|
33
|
+
@functions = TOML.load_file(@functions_file)
|
34
|
+
end
|
35
|
+
|
36
|
+
def write_comments(output)
|
37
|
+
version = @functions['init']['version']
|
38
|
+
output.puts "# ----------------------"
|
39
|
+
output.puts "# | COMPILED SLASHCODE"
|
40
|
+
output.puts "# |-- version: #{version}"
|
41
|
+
output.puts "# |"
|
42
|
+
output.puts "# | Generated by ScCompiler"
|
43
|
+
output.puts "# | Do not modify this file manually"
|
44
|
+
output.puts ""
|
45
|
+
end
|
46
|
+
|
47
|
+
def write_imports(output)
|
48
|
+
enableimports = @functions['init']['enableimports']
|
49
|
+
imports = @functions['init']['imports']
|
50
|
+
|
51
|
+
return unless enableimports == true && imports && imports.any?
|
52
|
+
|
53
|
+
imports.each do |gem_name|
|
54
|
+
output.puts "require '#{gem_name}'"
|
55
|
+
end
|
56
|
+
output.puts "" # Add a newline after imports
|
57
|
+
end
|
58
|
+
|
59
|
+
def translate_command(line)
|
60
|
+
parts = line.strip.split(' ')
|
61
|
+
command = parts.shift[1..] # Remove the leading '/'
|
62
|
+
|
63
|
+
if @functions['translations'].key?(command)
|
64
|
+
translation = @functions['translations'][command].strip # Get the translation string from functions.toml
|
65
|
+
|
66
|
+
# Join all parts with spaces
|
67
|
+
args = parts.join(' ')
|
68
|
+
|
69
|
+
# Replace $0 with all arguments joined with spaces
|
70
|
+
translated_command = translation.gsub(/\$0/, args)
|
71
|
+
|
72
|
+
# Replace placeholders $1, $2, etc. with the corresponding argument
|
73
|
+
translated_command = translated_command.gsub(/\$(\d+)/) { |match| parts[match[1].to_i - 1] }
|
74
|
+
|
75
|
+
translated_command # Return the translated command
|
76
|
+
else
|
77
|
+
"# Unknown command: #{line.strip}" # Handle unknown commands
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/translator.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# ---------------
|
2
|
+
# | SLASHCODE UTILS
|
3
|
+
# |--- translator class
|
4
|
+
# |-- version: dev-2
|
5
|
+
|
6
|
+
module Utils
|
7
|
+
class ScTranslator
|
8
|
+
def translate(language, code)
|
9
|
+
puts "The translator is still not available."
|
10
|
+
puts "# /translate #{language} #{code}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slashcode
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- JunglTemple
|
8
|
+
- XxDreamXxXx
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2024-04-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.1'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.1'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: toml
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.2.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.2.0
|
42
|
+
description:
|
43
|
+
email:
|
44
|
+
executables:
|
45
|
+
- slash
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- bin/slash
|
50
|
+
- config/slashcode.toml
|
51
|
+
- lib/cli.rb
|
52
|
+
- lib/compile.rb
|
53
|
+
- lib/translator.rb
|
54
|
+
homepage: https://github.com/JunglTemple/slashcode
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubygems_version: 3.4.1
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: 'slashcode: The language based on the slash'
|
77
|
+
test_files: []
|