sweet-lang 0.1.0 → 0.1.9

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.
Files changed (3) hide show
  1. data/lib/lexer/strings.rb +25 -3
  2. data/lib/lexer/tags.rb +19 -15
  3. metadata +2 -2
@@ -1,13 +1,35 @@
1
1
  class Strings
2
2
 
3
- def convert_string(code)
4
- strings = code.scan(/\t(\"[a-zA-Z0-9].*\")/)
3
+ def convert_string(code, indent)
4
+ strings = code.scan(/\t("[^"]+")/m)
5
5
  strings.uniq!
6
6
  strings.each do |string|
7
- new_string = "print(#{string[0]})"
7
+ original_tabs = code.scan(/((\t)+)#{string[0]}/)
8
+ original_tabs = (!original_tabs[0].nil?) ? original_tabs[0][0].count("\t") : 1
9
+ n_string = string[0].gsub( "<"," &lt;" ).gsub( ">"," &gt;" )
10
+ n_string = n_string.gsub(/\n/, "<br />")
11
+ n_string = n_string.gsub("=", "\\=")
12
+ get_tabs = n_string.scan(/((\t)+)/)
13
+ get_tabs.each do |line|
14
+ actual_tab = line[0].count("\t")
15
+ if actual_tab <= original_tabs
16
+ n_string = n_string.sub(/(\t)+/, "#{ '&nbsp;&nbsp;' * actual_tab }")
17
+ else
18
+ n_string = n_string.sub(/(\t)+/, "#{ '&nbsp;&nbsp;' * (actual_tab - original_tabs) }")
19
+ end
20
+ end
21
+ new_string = "print(#{n_string})"
8
22
  code = code.gsub(string[0], new_string)
9
23
  end
10
24
  return code
11
25
  end
12
26
 
27
+ def fix_atr(code, indent)
28
+ strings = code.scan(/print\(.*\)/m)
29
+ strings.uniq!
30
+ n_string = strings[0].gsub("\\=", "=")
31
+ code = code.gsub(strings[0], n_string)
32
+ return code
33
+ end
34
+
13
35
  end
@@ -41,11 +41,16 @@ class Tags
41
41
  atr.map {|x| x[0] + "'#{x[1]}'" }
42
42
  end
43
43
 
44
- def adding_attributes(code, tag)
44
+ def adding_attributes(code, tag, inline=false)
45
45
  _attr = [ [ "id", "#" ], [ "class", "\\." ] ]
46
46
  _attr.each do |a|
47
- orig = code.scan(/#{tag} ([.a-zA-Z0-9=-_ ]+)?(#{a[1]}([a-zA-Z0-9]+))/)
48
- orig.map! {|x| [x[1], x[2]] }
47
+ if inline
48
+ orig = code.scan(/^(\t)+?#{tag}([.a-zA-Z0-9=-_ ]+)? (#{a[1]}([a-zA-Z0-9_\-]+))/)
49
+ orig.map! {|x| [x[2], x[3]] }
50
+ else
51
+ orig = code.scan(/^#{tag}([.a-zA-Z0-9=-_ ]+)? (#{a[1]}([a-zA-Z0-9_\-]+))/)
52
+ orig.map! {|x| [x[1], x[2]] }
53
+ end
49
54
  orig.uniq!
50
55
  orig.each do |_old|
51
56
  _new = "#{a[0]}=#{_old[1]}"
@@ -57,29 +62,29 @@ class Tags
57
62
 
58
63
  def implement_tag(code, indent=1)
59
64
  new_code = []
65
+ @strings = Strings.new
60
66
  @@inline_tags.each do |tag|
61
- general = code.scan(/(^(\t)+?(#{tag}(()$| )([ #.=_\-a-zA-Z0-9]+)?((\n\t.*)+)?).*)/)
67
+ general = code.scan(/(^(\t)+?(#{tag}(()$| )([ #.=_\-a-zA-Z0-9:\/\?\+,]+)?))/)
62
68
  general.map! {|x| x[0]}
63
69
  general.each_with_index do |block, index|
64
- new_indent = general[0].split("\t").count
70
+ new_indent = block.scan(/((\t)+)[^\t]/)[0][0].count("\t") + 1
65
71
  _code_block = block
66
- code_block = adding_attributes(block, tag)
67
- strings = Strings.new
68
- code_block = strings.convert_string( code_block )
69
- atr = code_block.scan(/([a-zA-Z0-9_-]+=)'?"?([a-zA-Z0-9_-]+)'?"?/)
72
+ code_block = adding_attributes(block, tag, true)
73
+ atr = code_block.scan(/([a-zA-Z0-9_-]+=)'?"?([\.\/:a-zA-Z0-9_-]+)'?"?/)
70
74
  code_block = convert_tag( code_block , index, new_indent, tag, atr, true)
71
75
  code = code.gsub(_code_block, code_block)
72
76
  end
73
77
  end
74
78
  @@tags.each do |tag|
75
- general = code.scan(/(^(#{tag}(()$| )([ #.=_\-a-zA-Z0-9]+)?((\n\t.*)+)?).*)/)
79
+ general = code.scan(/(^(#{tag}(()$| )([ :\/\?\+#.=_\-a-zA-Z0-9]+)?((\n\t.*)+)?).*)/m)
76
80
  general.map! {|x| x[0]}
77
81
  general.each_with_index do |block, index|
78
82
  _code_block = block
79
83
  code_block = adding_attributes(block, tag)
84
+ code_block = @strings.convert_string( code_block, indent )
80
85
  @@tags.each do |r_tag|
81
- if !code_block.scan(/^(\t){#{indent}}(#{r_tag}(()$| )([a-zA-Z0-9= \t_\-#.\\'\/]+)?((\n\1{#{indent+1},})?(["#a= ()a-zA-Z0-9_.-\\'\/]+)?)+)/m).empty?
82
- r_code = code_block.scan(/^(\t){#{indent}}(#{r_tag}(()$| )([a-zA-Z0-9= \t_\-#.\\'\/]+)?((\n\1{#{indent+1},})?(["#a= ()a-zA-Z0-9_.-\\'\/]+)?)+)/m)
86
+ if !code_block.scan(/^(\t){#{indent}}(#{r_tag}(()$| )((\n)+?[a-zA-Z0-9= \t_\-#.\\'\/]+)?(((\n)+?\1{#{indent+1},})?(["#a= ()a-zA-Z0-9_.,\--\\'\/&]+)?)+)/m).empty?
87
+ r_code = code_block.scan(/^(\t){#{indent}}(#{r_tag}(()$| )((\n)+?[a-zA-Z0-9= \t_\-#.\\'\/]+)?(((\n)+?\1{#{indent+1},})?(["#a= ()a-zA-Z0-9_.,\--\\'\/&]+)?)+)/m)
83
88
  r_code.each do |r|
84
89
  new_indent = indent + 1
85
90
  new_block = implement_tag(r[1], new_indent)
@@ -87,13 +92,12 @@ class Tags
87
92
  end
88
93
  end
89
94
  end
90
- strings = Strings.new
91
- code_block = strings.convert_string( code_block )
92
- atr = code_block.scan(/([a-zA-Z0-9_-]+=)([a-zA-Z0-9_-]+)/)
95
+ atr = code_block.scan(/([a-zA-Z0-9_-]+=)([\.\/:a-zA-Z0-9_-]+)/)
93
96
  code_block = convert_tag( code_block , index, indent, tag, atr)
94
97
  code = code.gsub(_code_block, code_block)
95
98
  end
96
99
  end
100
+ code = @strings.fix_atr( code, indent )
97
101
  return code
98
102
  end
99
103
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sweet-lang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -37,7 +37,7 @@ files:
37
37
  - lib/runtime/method.rb
38
38
  - lib/runtime/object.rb
39
39
  - bin/sweet
40
- homepage: https://github.com/joaomdmoura/sweet
40
+ homepage: http://joaomdmoura.github.com/sweet/
41
41
  licenses: []
42
42
  post_install_message:
43
43
  rdoc_options: []