plasma 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -0
- data/Rakefile +28 -0
- data/bin/plasma +18 -0
- data/lib/extras/plasma_view.rb +18 -0
- data/lib/plasma.rb +11 -0
- data/lib/plasma/include/core.plasma +3 -0
- data/lib/plasma/include/plasma_core.rb +27 -0
- data/lib/plasma/interpreter.rb +9 -0
- data/lib/plasma/interpreter/class_mods.rb +43 -0
- data/lib/plasma/interpreter/plasma_grammar.rb +1996 -0
- data/lib/plasma/interpreter/plasma_grammar.treetop +97 -0
- data/lib/plasma/interpreter/plasma_grammarnode.rb +331 -0
- data/lib/plasma/interpreter/plasma_interpreter.rb +104 -0
- data/lib/plasma/template.rb +3 -0
- data/lib/plasma/template/plasma_template.rb +57 -0
- data/test/import_test.plasma +26 -0
- data/test/plasmatest.rb +37 -0
- data/test/plasmic.plasma +12 -0
- metadata +83 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
module Plasma
|
2
|
+
module Template
|
3
|
+
class PlasmaTemplate
|
4
|
+
@@separator = /\|\|/
|
5
|
+
|
6
|
+
def self.parse(template)
|
7
|
+
return PlasmaTemplate.new(template)
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(template)
|
11
|
+
@template = template
|
12
|
+
@plasma = Plasma::Interpreter::PlasmaInterpreter.new
|
13
|
+
|
14
|
+
@plain = []
|
15
|
+
@plasmic = []
|
16
|
+
|
17
|
+
cursor = @template
|
18
|
+
|
19
|
+
loop do
|
20
|
+
pre = cursor.match(@@separator)
|
21
|
+
|
22
|
+
if pre.nil?
|
23
|
+
@plain << cursor
|
24
|
+
break
|
25
|
+
else
|
26
|
+
@plain << pre.pre_match
|
27
|
+
code = pre.values_at(0)[0]
|
28
|
+
post = pre.post_match.match(@@separator)
|
29
|
+
|
30
|
+
if post.nil?
|
31
|
+
@plain << pre.post_match
|
32
|
+
break
|
33
|
+
else
|
34
|
+
code += post.pre_match + post.values_at(0)[0]
|
35
|
+
cursor = post.post_match
|
36
|
+
|
37
|
+
@plasmic << @plasma.parse(code)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def render(env={})
|
44
|
+
@plasma.env.merge!(env)
|
45
|
+
evaluated = @plasmic.map{|p| @plasma.evaluate(p)}
|
46
|
+
|
47
|
+
rendered = ''
|
48
|
+
@plain.slice(0...@plain.length-1).each_with_index do |text, index|
|
49
|
+
portion = text + evaluated[index].to_s
|
50
|
+
rendered += portion
|
51
|
+
end
|
52
|
+
|
53
|
+
return rendered + @plain.last
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
|
2
|
+
|
3
|
+
(print (import "test/plasmic")) |
|
4
|
+
|
5
|
+
(defun (owlepellet z x) (peanut z (yar x))) |
|
6
|
+
(print (owlepellet yar (zooo 44))) |
|
7
|
+
|
8
|
+
(print (length [12 33 24924 zooo])) |
|
9
|
+
(print (eval '(length [12 33 24924 zooo 'uuu]))) |
|
10
|
+
(print (eval "(length [12 33 24924 zooo 1 1 1 1 1 1])")) |
|
11
|
+
|
12
|
+
(print (if false then (fun (x) (* x (+ x 3))) else 'what)) |
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
(print (map [1 4 4 5 12] (fun (a) (* a (/ a 6))))) |
|
18
|
+
(print [3 4 2 5 1 1 5 2]) |
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
data/test/plasmatest.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'lib/plasma.rb'
|
2
|
+
|
3
|
+
plasma = Plasma::Interpreter::PlasmaGrammarParser.new
|
4
|
+
|
5
|
+
decl = "| 'eiii | 1233333 | (def xxx 5) |"
|
6
|
+
declb = "xxx"
|
7
|
+
seq = "('oeheo | 238 | 11)"
|
8
|
+
quote = "'(333333)"
|
9
|
+
define = "((def a 2121212) | a)"
|
10
|
+
defun = "(defun (ff x) (* x 13))"
|
11
|
+
fun = "(fun (x c) (+ x c))"
|
12
|
+
apply1 = "(+ 11 14)"
|
13
|
+
apply2 = "((fun (x c) (+ x c)) 11 14)"
|
14
|
+
curry = "((def aaa ((fun (a b) (* a b)) 3)) | (aaa 11))"
|
15
|
+
sym = "((def tatao+ht-o*he<>i==== 555) | tatao+ht-o*he<>i====)"
|
16
|
+
hash = "{yayay:77777 rrr:111}"
|
17
|
+
list = "[11 33 449]"
|
18
|
+
date = "3409-65-22"
|
19
|
+
time = "55:32:18"
|
20
|
+
str = '"yaodui iwfhoeo"'
|
21
|
+
num = "444.22"
|
22
|
+
test = "| (def yar (fun (x) (* 3 x))) |
|
23
|
+
(def peanut (fun (y z) (/ (- y z) z))) |
|
24
|
+
(peanut (yar 66) 12) |"
|
25
|
+
bad = "(999)(888)"
|
26
|
+
env = Plasma::Interpreter::Env.new
|
27
|
+
|
28
|
+
|
29
|
+
statements = [seq, quote, define, defun, fun, apply1, apply2,
|
30
|
+
sym, hash, list, date, time, str, num, test,
|
31
|
+
decl, declb, defun, bad, curry]
|
32
|
+
statements.each do |statement|
|
33
|
+
parsed = plasma.parse(statement)
|
34
|
+
evaluated = parsed.nil? ? "does not parse" : parsed.evaluate(env).to_plasma
|
35
|
+
|
36
|
+
puts "#{statement} -> #{parsed} : #{evaluated}"
|
37
|
+
end
|
data/test/plasmic.plasma
ADDED
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: plasma
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Spangler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-04 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: treetop
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
24
|
+
description:
|
25
|
+
email: patch_work8848@yahoo.com
|
26
|
+
executables:
|
27
|
+
- plasma
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files: []
|
31
|
+
|
32
|
+
files:
|
33
|
+
- README
|
34
|
+
- Rakefile
|
35
|
+
- test/import_test.plasma
|
36
|
+
- test/plasmatest.rb
|
37
|
+
- test/plasmic.plasma
|
38
|
+
- lib/extras
|
39
|
+
- lib/extras/plasma_view.rb
|
40
|
+
- lib/plasma
|
41
|
+
- lib/plasma/include
|
42
|
+
- lib/plasma/include/core.plasma
|
43
|
+
- lib/plasma/include/plasma_core.rb
|
44
|
+
- lib/plasma/interpreter
|
45
|
+
- lib/plasma/interpreter/class_mods.rb
|
46
|
+
- lib/plasma/interpreter/plasma_grammar.rb
|
47
|
+
- lib/plasma/interpreter/plasma_grammar.treetop
|
48
|
+
- lib/plasma/interpreter/plasma_grammarnode.rb
|
49
|
+
- lib/plasma/interpreter/plasma_interpreter.rb
|
50
|
+
- lib/plasma/interpreter.rb
|
51
|
+
- lib/plasma/template
|
52
|
+
- lib/plasma/template/plasma_template.rb
|
53
|
+
- lib/plasma/template.rb
|
54
|
+
- lib/plasma.rb
|
55
|
+
- bin/plasma
|
56
|
+
has_rdoc: false
|
57
|
+
homepage: http://kaleidomedallion.com/plasma/
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project: plasma
|
78
|
+
rubygems_version: 1.0.1
|
79
|
+
signing_key:
|
80
|
+
specification_version: 2
|
81
|
+
summary: plasma --- a lightweight interpreted templating language in ruby
|
82
|
+
test_files: []
|
83
|
+
|