lscript 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/lscript.rb +60 -35
  3. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b62edc8871de0457c6b6f0cb245721d49f826d18
4
- data.tar.gz: f160abe32923ed4d7551d33869bcbd4a3aedc001
3
+ metadata.gz: 257b087618522e6af59e4307b05b16d35f660884
4
+ data.tar.gz: ccc53082f5821ca0645278e56c7f14bdab306156
5
5
  SHA512:
6
- metadata.gz: 602e999106400a3b2bf788a68429a88dfdd91208232e15e3b1a86ac2e27399b3e809118941be406d7126b192e8e992552cb0cfbe1be1385f6704fd1c4987cd82
7
- data.tar.gz: 205e15602347ee8fd14d30b441cf688d21d6909cc9aadf53f957e441e1e5b099a2602bed7e0d84034fbbfed394226c66dbbaae5fcbf0dfd26e5184c9c3d4cc8d
6
+ metadata.gz: 2279ceb693871d0815e768b28e35d1e979f6744b2297059cf393dc69447fbba7e2b151233437691548595496255be852a0db86fc99133c44c9b90559a997af7d
7
+ data.tar.gz: f1eaaa3605af44bebe67161af7d7f05482364c530ce09ece12c3cf6c5ea00cb9cd1d1edfd526b0f48a1fbafdb72da477713c8f11dad94ac27e2e42b6ec822651
@@ -1,35 +1,41 @@
1
1
  def lscript(string)
2
- variabels = Hash.new
2
+ variables = Hash.new
3
3
  while true
4
4
  case string.slice!(0)
5
- when 'g'
6
- variabels[string.slice!(0)] = gets
7
- when 'p'
8
- puts variabels[string.slice!(0)]
9
- when 'r'
10
- variabels[string.slice!(0)] = lread(string)
11
- when 'i'
12
- #if true the code after runs, if false it gets eaten
13
- if variabels[string.slice!(0)] == variabels[string.slice!(0)]
14
- else
15
- lread(string)
16
- end
17
- when '+'
18
- variabels[string.slice!(0)] = variabels[string.slice!(0)] + variabels[string.slice!(0)]
19
- when '-'
20
- variabels[string.slice!(0)] = variabels[string.slice!(0)] - variabels[string.slice!(0)]
21
- when nil
22
- break
23
- else
5
+ when 'g'
6
+ variables[string.slice!(0)] = gets.chomp
7
+ when 'p'
8
+ puts lread(string,variables)
9
+ when 'r'
10
+ variables[string.slice!(0)] = lread(string,variables)
11
+ when 'i'
12
+ #if true the code after runs, if false it gets eaten
13
+ if !(variables[string.slice!(0)] == variables[string.slice!(0)])
14
+ lread(string,variables)
15
+ end
16
+ when 'e'
17
+ return variables[string.slice!(0)]
18
+ when '+'
19
+ variables[string.slice!(0)] = variables[string.slice!(0)] + variables[string.slice!(0)]
20
+ when '-'
21
+ variables[string.slice!(0)] = variables[string.slice!(0)] - variables[string.slice!(0)]
22
+ when nil
23
+ return variables
24
+ else
24
25
  end
25
26
  end
26
27
  end
27
- def lread(string)
28
- ret = ""
29
- until (s=string.slice!(0)) == ';'
30
- ret += s
28
+ def lread(string,variables)
29
+ x = string.slice!(0)
30
+ if x == '{'
31
+ ret = ""
32
+ until (s=string.slice!(0)) == '}'
33
+ ret += s
34
+ end
35
+ return ret
36
+ else
37
+ return variables[x]
31
38
  end
32
- return ret
33
39
  end
34
40
 
35
41
  =begin
@@ -40,19 +46,38 @@ $ = single character variabel, a-z are recommended. 0-9 aswell as other characte
40
46
  _ text or code to read or run
41
47
  ; defines end of text or code to read
42
48
  g$ gets user input and stores in variabel $
43
- p$ puts $
44
- r$_; puts _; string into $
45
- i$$_; if $ == $ runs _;
49
+ p$ puts $ to console
50
+ p{_} puts _ string to console
51
+ r${_} puts _ string into $
52
+ i$${_} if $ == $ runs _
46
53
  +$$$ combines second and third varaible into first
47
54
  -$$$ subtracts second and third varaible into first, works best with numbers
55
+ e$ stops the code and returns the variable
48
56
 
49
57
  Lets run trough an example
50
- lscript("raWhat is your name?; pa rbHello ; gc +dbc pd")
51
- raWhat is your name?; This will read[r] into variabel[a] the string[What is your name?] and stop reading at [;]
52
- pa this will puts to console[p] the varaible[a]
53
- rbHello ; this will read[r] into[b] the string[Hello ] and stop at [;] (notice the space after Hello, it is important for formating later)
54
- gc this will gets[g] user input into the varaibel[c]
55
- +dbc this will add[+] into varable[d] the other 2 variabels [b] and [c]
56
- pd finally this will puts[p] the combined variable[d]
58
+ lscript("p{What is your name?} ra{Hello } gb +cab pc")
59
+ p{What is your name?} this will puts to console[p] the string[What is your name?] and stop reading at [}]
60
+ ra{Hello } this will read[r] into variable[a] the string[Hello ] and stop at [}] (notice the space after Hello, it is important for formating later)
61
+ gb this will gets[g] user input into the varaibel[b]
62
+ +cab this will add[+] into varable[c] the other 2 variabels [a] and [b]
63
+ pc finally this will puts[p] the combined variable[c] to console
64
+
65
+ CHANGELOG
66
+ 0.0.1
67
+ Initial release
68
+
69
+ 0.0.2
70
+ When the code is finished return the variables hash incase the user needs it
71
+ Added command e$, allows user to exit the code and return a specific variable
72
+ Extended text read fucntionallity
73
+ p command can now read text directly
74
+ strings are noted as {_} now instead of _; for both clarity and for the extended fucntions
75
+ updated example code to reflect changes
76
+ g command now uses .chomp to remove new line character
77
+
78
+ Planed additions:
79
+ Possibly remodell into an object, allowing for continuing the same run with multiple run calls
80
+ Make - command acutally work, and try to convert string into numbers
81
+ Make both + and - use new string reading system, so you wont have to save text to a varibale before useing
57
82
  =end
58
83
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lscript
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leddy231
@@ -10,7 +10,9 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2016-07-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Very basic as it is, will be expanded more. Just for fun really
13
+ description: A simple scripting language that reads a single string and executes commands.
14
+ Variables, ifs and +/- operations supported. Very basic as it is, will be expanded
15
+ more. Read the lscript.rb for changelog and instructions
14
16
  email:
15
17
  executables: []
16
18
  extensions: []