File tree Expand file tree Collapse file tree 4 files changed +44
-21
lines changed Expand file tree Collapse file tree 4 files changed +44
-21
lines changed Original file line number Diff line number Diff line change
1
+ <?rbi ?>
2
+ <%# Fractal tree example %>
3
+ <%# % nqp rubyish . nqp rubyish -examples /fractal -tree . rbi > fractal . svg %>
4
+ <?xml version = '1.0' encoding = 'utf-8' standalone = 'no' ?>
5
+ <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN'
6
+ 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' >
7
+ <svg width = '100%' height = '100%' version = '1.1'
8
+ xmlns = 'http://www.w3.org/2000/svg' >
9
+
10
+ <%#----------
11
+ @scale = 6/10
12
+ @PI = 3.1415926535
13
+
14
+ def tree(x, y, len, angle)
15
+ if len >= 1.0 then
16
+ x2 = x + len * nqp::cos_n(angle)
17
+ y2 = y + len * nqp::sin_n(angle)
18
+ puts "<line x1='# { x } ' y1=' #{y}' x2='#{x2}' y2='#{y2}' style='stroke:rgb(0,0,0);stroke-width:1'/>";
19
+ tree ( x2 , y2 , len *@scale , angle + @PI /5 ) ;
20
+ tree ( x2 , y2 , len *@scale , angle - @PI /5 ) ;
21
+ end
22
+ end
23
+
24
+ width = 1000
25
+ height = 1000
26
+ length = 400
27
+
28
+ tree ( width /2 , height , length , 3 *@PI /2 )
29
+ #-----------%>
30
+
31
+ </svg >
Original file line number Diff line number Diff line change 1
1
# eRubyish templating - see http://en.wikipedia.org/wiki/ERuby
2
2
# There are only three directives:
3
- # <% rbi> - Header; remainder of the source file is the template body
3
+ # <? rbi? > - Header; remainder of the source file is the template body
4
4
# <% ... %> - rubyish statements
5
5
# #{ ... } - inserted content
6
6
7
7
# Any arbritrary code can appear before the template. Output to stdout
8
8
# is appended to the template, both before and within the template body
9
9
10
- puts '<?xml>'
10
+ puts '<?xml version=' 1.0 ' encoding=' utf - 8 '? >'
11
11
12
- <% rbi >
12
+ <? rbi ? >
13
13
<html >
14
14
<body >
15
15
<h1 >Green Bottles ...</h1>
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ grammar Rubyish::Grammar is HLL::Grammar {
41
41
token template-content :sym <interp > { <interp > }
42
42
token template-content :sym <plain-text > { [<! before [<tmpl - esc >| '#{' | $ ]> . ]+ }
43
43
44
- token tmpl-hdr {'<% rbi>' \h * \n ? <?{ $ * IN_TEMPLATE := 1 }> }
44
+ token tmpl-hdr {'<? rbi? >' \h * \n ? <?{ $ * IN_TEMPLATE := 1 }> }
45
45
token tmpl-esc {\h * '<%'
46
46
[<?{ $ * IN_TEMPLATE }> || <.panic (' Template directive precedes "<%rbi>"' )>]
47
47
}
@@ -110,7 +110,7 @@ grammar Rubyish::Grammar is HLL::Grammar {
110
110
}
111
111
112
112
token term :sym <nqp-op > {
113
- 'nqp::' <ident > ['(' ~ ')' <call - args = .paren - args >? | <call - args >? ]
113
+ 'nqp:'':' ? <ident > ['(' ~ ')' <call - args = .paren - args >? | <call - args >? ]
114
114
}
115
115
116
116
token term :sym <quote-words > {
Original file line number Diff line number Diff line change 3
3
puts '1..10'
4
4
puts "ok 1 - statements before template"
5
5
6
- < % rbi>
6
+ < ? rbi? >
7
7
ok 2 - initial template text
8
8
< % n = 2 %>
9
- < % while n < 4 %>
10
- < % n += 1%>
11
- ok # {n} - while loop test
9
+ < % while (n+=1) < 5 %>ok #{n} - while loop test
12
10
< % end%>
13
11
ok 5 - text between statements
14
- < % if n == 4 %>
15
- ok 6 - if block (true )
16
- < % else%>
17
- nok 6 - if block (true )
12
+ < % if n == 5 %>ok 6 - if block (true)
13
+ < % else %>nok 6 - if block (true)
18
14
< % end%>
19
- < % if n == 1234 %>
20
- nok 7 - if block (false )
21
- < % elsif n == 20 %>
22
- nok 7 - if block (false )
23
- < % else%>
24
- ok 7 - if block (false )
15
+ < % if n == 1234 %>nok 7 - if block (false)
16
+ < % elsif n == 20 %>nok 7 - if block (false)
17
+ < % else %>ok 7 - if block (false)
25
18
< % end %>
26
- < % for test in [8, 9] do %>
27
- ok # {test} - for loop test
19
+ < % for test in [8, 9] do %>ok #{test} - for loop test
28
20
< % end%>
29
21
< % #puts "nok 10 - commented out directive" %>
30
22
ok 10 - final template text
You can’t perform that action at this time.
0 commit comments