textpow 0.10.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. data/.travis.yml +7 -0
  2. data/Gemfile +10 -0
  3. data/Gemfile.lock +30 -0
  4. data/{History.txt → History.rdoc} +10 -0
  5. data/{README.txt → MIT-LICENSE.txt} +0 -30
  6. data/README.rdoc +82 -0
  7. data/Rakefile +42 -49
  8. data/bin/plist2syntax +0 -0
  9. data/bin/plist2yaml +0 -0
  10. data/examples/benchmark_js.rb +13 -0
  11. data/examples/jquery.js +9046 -0
  12. data/lib/textpow.rb +43 -3
  13. data/lib/textpow/debug_processor.rb +35 -35
  14. data/lib/textpow/recording_processor.rb +13 -0
  15. data/lib/textpow/score_manager.rb +60 -60
  16. data/lib/textpow/syntax.rb +303 -262
  17. data/lib/textpow/syntax/broken/markdown.syntax +519 -0
  18. data/lib/textpow/syntax/broken/php.syntax +1253 -0
  19. data/lib/textpow/syntax/buggy/nemerle.syntax +74 -0
  20. data/lib/textpow/syntax/old/YAML.yaml +160 -0
  21. data/lib/textpow/syntax/old/txt2tags.yaml +139 -0
  22. data/lib/textpow/syntax/source.actionscript.syntax +97 -0
  23. data/lib/textpow/syntax/source.active4d.library.syntax +21 -0
  24. data/lib/textpow/syntax/source.active4d.syntax +276 -0
  25. data/lib/textpow/syntax/source.ada.syntax +33 -0
  26. data/lib/textpow/syntax/source.antlr.syntax +151 -0
  27. data/lib/textpow/syntax/source.apache-config.mod_perl.syntax +50 -0
  28. data/lib/textpow/syntax/source.apache-config.syntax +191 -0
  29. data/lib/textpow/syntax/source.applescript.syntax +384 -0
  30. data/lib/textpow/syntax/source.asp.syntax +70 -0
  31. data/lib/textpow/syntax/source.asp.vb.net.syntax +129 -0
  32. data/lib/textpow/syntax/source.c++.qt.syntax +26 -0
  33. data/lib/textpow/syntax/source.c++.syntax +186 -0
  34. data/lib/textpow/syntax/source.c-sharp.syntax +59 -0
  35. data/lib/textpow/syntax/source.c.ragel.syntax +201 -0
  36. data/lib/textpow/syntax/source.c.syntax +414 -0
  37. data/lib/textpow/syntax/source.camlp4.ocaml.syntax +36 -0
  38. data/lib/textpow/syntax/source.cm.syntax +32 -0
  39. data/lib/textpow/syntax/source.coffee.syntax +216 -0
  40. data/lib/textpow/syntax/source.context-free.syntax +176 -0
  41. data/lib/textpow/syntax/source.css.beta.syntax +1925 -0
  42. data/lib/textpow/syntax/source.css.syntax +195 -0
  43. data/lib/textpow/syntax/source.d.syntax +142 -0
  44. data/lib/textpow/syntax/source.diff.syntax +81 -0
  45. data/lib/textpow/syntax/source.dot.syntax +47 -0
  46. data/lib/textpow/syntax/source.dylan.syntax +62 -0
  47. data/lib/textpow/syntax/source.eiffel.syntax +78 -0
  48. data/lib/textpow/syntax/source.erlang.syntax +922 -0
  49. data/lib/textpow/syntax/source.fortran.syntax +141 -0
  50. data/lib/textpow/syntax/source.fscript.syntax +80 -0
  51. data/lib/textpow/syntax/source.fxscript.syntax +142 -0
  52. data/lib/textpow/syntax/source.gri.syntax +83 -0
  53. data/lib/textpow/syntax/source.groovy.groovy.syntax +191 -0
  54. data/lib/textpow/syntax/source.haskell.syntax +88 -0
  55. data/lib/textpow/syntax/source.icalendar.syntax +32 -0
  56. data/lib/textpow/syntax/source.inform.syntax +48 -0
  57. data/lib/textpow/syntax/source.ini.syntax +55 -0
  58. data/lib/textpow/syntax/source.io.syntax +81 -0
  59. data/lib/textpow/syntax/source.java-props.syntax +20 -0
  60. data/lib/textpow/syntax/source.java.syntax +211 -0
  61. data/lib/textpow/syntax/source.js.greasemonkey.syntax +34 -0
  62. data/lib/textpow/syntax/source.js.jquery.syntax +114 -0
  63. data/lib/textpow/syntax/source.js.mootools.syntax +572 -0
  64. data/lib/textpow/syntax/source.js.prototype.bracketed.syntax +140 -0
  65. data/lib/textpow/syntax/source.js.prototype.syntax +72 -0
  66. data/lib/textpow/syntax/source.js.syntax +256 -0
  67. data/lib/textpow/syntax/source.js.yui.syntax +176 -0
  68. data/lib/textpow/syntax/source.json.syntax +136 -0
  69. data/lib/textpow/syntax/source.lex.syntax +219 -0
  70. data/lib/textpow/syntax/source.lighttpd-config.syntax +54 -0
  71. data/lib/textpow/syntax/source.lilypond.syntax +492 -0
  72. data/lib/textpow/syntax/source.lisp.syntax +61 -0
  73. data/lib/textpow/syntax/source.logo.syntax +29 -0
  74. data/lib/textpow/syntax/source.logtalk.syntax +152 -0
  75. data/lib/textpow/syntax/source.lua.syntax +86 -0
  76. data/lib/textpow/syntax/source.makefile.syntax +36 -0
  77. data/lib/textpow/syntax/source.matlab.syntax +142 -0
  78. data/lib/textpow/syntax/source.mel.syntax +92 -0
  79. data/lib/textpow/syntax/source.mips.syntax +66 -0
  80. data/lib/textpow/syntax/source.ml.syntax +121 -0
  81. data/lib/textpow/syntax/source.modula-3.syntax +47 -0
  82. data/lib/textpow/syntax/source.nant-build.syntax +53 -0
  83. data/lib/textpow/syntax/source.objc++.syntax +18 -0
  84. data/lib/textpow/syntax/source.objc.syntax +233 -0
  85. data/lib/textpow/syntax/source.ocaml.syntax +764 -0
  86. data/lib/textpow/syntax/source.ocamllex.syntax +167 -0
  87. data/lib/textpow/syntax/source.ocamlyacc.syntax +184 -0
  88. data/lib/textpow/syntax/source.open-gl.syntax +14 -0
  89. data/lib/textpow/syntax/source.pascal.syntax +77 -0
  90. data/lib/textpow/syntax/source.pascal.vectorscript.syntax +57 -0
  91. data/lib/textpow/syntax/source.perl.syntax +1113 -0
  92. data/lib/textpow/syntax/source.php.cake.syntax +55 -0
  93. data/lib/textpow/syntax/source.plist.tm-grammar.syntax +708 -0
  94. data/lib/textpow/syntax/source.postscript.syntax +114 -0
  95. data/lib/textpow/syntax/source.processing.syntax +106 -0
  96. data/lib/textpow/syntax/source.prolog.syntax +40 -0
  97. data/lib/textpow/syntax/source.python.django.syntax +21 -0
  98. data/lib/textpow/syntax/source.python.syntax +868 -0
  99. data/lib/textpow/syntax/source.qmake.syntax +114 -0
  100. data/lib/textpow/syntax/source.quake-config.syntax +32 -0
  101. data/lib/textpow/syntax/source.r-console.syntax +16 -0
  102. data/lib/textpow/syntax/source.r.syntax +81 -0
  103. data/lib/textpow/syntax/source.regexp.oniguruma.syntax +107 -0
  104. data/lib/textpow/syntax/source.regexp.python.syntax +109 -0
  105. data/lib/textpow/syntax/source.regexp.syntax +50 -0
  106. data/lib/textpow/syntax/source.remind.syntax +253 -0
  107. data/lib/textpow/syntax/source.rez.syntax +80 -0
  108. data/lib/textpow/syntax/source.ruby.experimental.syntax +145 -0
  109. data/lib/textpow/syntax/source.ruby.rails.syntax +88 -0
  110. data/lib/textpow/syntax/source.ruby.syntax +1035 -0
  111. data/lib/textpow/syntax/source.s5.syntax +69 -0
  112. data/lib/textpow/syntax/source.sass.syntax +45 -0
  113. data/lib/textpow/syntax/source.scheme.syntax +347 -0
  114. data/lib/textpow/syntax/source.scilab.syntax +41 -0
  115. data/lib/textpow/syntax/source.scss.syntax +527 -0
  116. data/lib/textpow/syntax/source.shell.syntax +384 -0
  117. data/lib/textpow/syntax/source.slate.syntax +149 -0
  118. data/lib/textpow/syntax/source.smarty.syntax +63 -0
  119. data/lib/textpow/syntax/source.sql.ruby.syntax +18 -0
  120. data/lib/textpow/syntax/source.sql.syntax +237 -0
  121. data/lib/textpow/syntax/source.ssh-config.syntax +33 -0
  122. data/lib/textpow/syntax/source.strings.syntax +39 -0
  123. data/lib/textpow/syntax/source.swig.syntax +57 -0
  124. data/lib/textpow/syntax/source.tcl.macports.syntax +163 -0
  125. data/lib/textpow/syntax/source.tcl.syntax +152 -0
  126. data/lib/textpow/syntax/source.yaml.syntax +160 -0
  127. data/lib/textpow/syntax/text.active4d-ini.syntax +50 -0
  128. data/lib/textpow/syntax/text.bbcode.syntax +287 -0
  129. data/lib/textpow/syntax/text.bibtex.syntax +151 -0
  130. data/lib/textpow/syntax/text.blog.html.syntax +41 -0
  131. data/lib/textpow/syntax/text.blog.markdown.syntax +42 -0
  132. data/lib/textpow/syntax/text.blog.syntax +27 -0
  133. data/lib/textpow/syntax/text.blog.textile.syntax +27 -0
  134. data/lib/textpow/syntax/text.gtdalt.syntax +143 -0
  135. data/lib/textpow/syntax/text.haml.syntax +88 -0
  136. data/lib/textpow/syntax/text.html.asp.net.syntax +424 -0
  137. data/lib/textpow/syntax/text.html.asp.syntax +27 -0
  138. data/lib/textpow/syntax/text.html.basic.syntax +362 -0
  139. data/lib/textpow/syntax/text.html.cfm.syntax +119 -0
  140. data/lib/textpow/syntax/text.html.django.syntax +36 -0
  141. data/lib/textpow/syntax/text.html.dokuwiki.syntax +204 -0
  142. data/lib/textpow/syntax/text.html.doxygen.syntax +43 -0
  143. data/lib/textpow/syntax/text.html.markdown.multimarkdown.syntax +39 -0
  144. data/lib/textpow/syntax/text.html.mason.syntax +119 -0
  145. data/lib/textpow/syntax/text.html.mediawiki.syntax +567 -0
  146. data/lib/textpow/syntax/text.html.mt.syntax +162 -0
  147. data/lib/textpow/syntax/text.html.ruby.syntax +40 -0
  148. data/lib/textpow/syntax/text.html.strict.active4d.syntax +311 -0
  149. data/lib/textpow/syntax/text.html.tcl.syntax +26 -0
  150. data/lib/textpow/syntax/text.html.textile.syntax +215 -0
  151. data/lib/textpow/syntax/text.html.tt.syntax +121 -0
  152. data/lib/textpow/syntax/text.html.twiki.syntax +241 -0
  153. data/lib/textpow/syntax/text.html.xhtml.1-strict.syntax +4027 -0
  154. data/lib/textpow/syntax/text.log.latex.syntax +50 -0
  155. data/lib/textpow/syntax/text.mail.markdown.syntax +118 -0
  156. data/lib/textpow/syntax/text.man.syntax +17 -0
  157. data/lib/textpow/syntax/text.moinmoin.syntax +189 -0
  158. data/lib/textpow/syntax/text.plain.gtd.syntax +22 -0
  159. data/lib/textpow/syntax/text.plain.release-notes.syntax +46 -0
  160. data/lib/textpow/syntax/text.plain.syntax +32 -0
  161. data/lib/textpow/syntax/text.plist.syntax +635 -0
  162. data/lib/textpow/syntax/text.pmwiki.syntax +113 -0
  163. data/lib/textpow/syntax/text.restructuredtext.syntax +250 -0
  164. data/lib/textpow/syntax/text.setext.syntax +147 -0
  165. data/lib/textpow/syntax/text.subversion-commit.syntax +36 -0
  166. data/lib/textpow/syntax/text.tabular.csv.syntax +68 -0
  167. data/lib/textpow/syntax/text.tabular.tsv.syntax +50 -0
  168. data/lib/textpow/syntax/text.tex.latex.beamer.syntax +41 -0
  169. data/lib/textpow/syntax/text.tex.latex.haskell.syntax +24 -0
  170. data/lib/textpow/syntax/text.tex.latex.memoir.syntax +64 -0
  171. data/lib/textpow/syntax/text.tex.latex.rd.syntax +91 -0
  172. data/lib/textpow/syntax/text.tex.latex.sweave.syntax +84 -0
  173. data/lib/textpow/syntax/text.tex.latex.syntax +566 -0
  174. data/lib/textpow/syntax/text.tex.math.syntax +49 -0
  175. data/lib/textpow/syntax/text.tex.syntax +86 -0
  176. data/lib/textpow/syntax/text.txt2tags.syntax +79 -0
  177. data/lib/textpow/syntax/text.xml.apple-dist.syntax +77 -0
  178. data/lib/textpow/syntax/text.xml.strict.syntax +92 -0
  179. data/lib/textpow/syntax/text.xml.syntax +180 -0
  180. data/lib/textpow/syntax/text.xml.xsl.syntax +60 -0
  181. data/lib/textpow/version.rb +3 -0
  182. data/spec/fixtures/objeck.plist +107 -0
  183. data/spec/fixtures/utf8.txt +1 -0
  184. data/spec/spec_helper.rb +2 -0
  185. data/spec/textpow/score_manager_spec.rb +20 -0
  186. data/spec/textpow/syntax_files_spec.rb +26 -0
  187. data/spec/textpow/syntax_spec.rb +225 -0
  188. data/spec/textpow_spec.rb +57 -0
  189. data/textpow.gemspec +19 -0
  190. metadata +246 -68
  191. data/Manifest.txt +0 -13
  192. data/mm/manual.mm +0 -266
  193. data/test/test_textpow.rb +0 -25
@@ -0,0 +1,60 @@
1
+ ---
2
+ name: XSL
3
+ fileTypes:
4
+ - xsl
5
+ - xslt
6
+ scopeName: text.xml.xsl
7
+ repository:
8
+ singlequotedString:
9
+ name: string.quoted.single.xml
10
+ endCaptures:
11
+ "0":
12
+ name: punctuation.definition.string.end.xml
13
+ begin: "'"
14
+ beginCaptures:
15
+ "0":
16
+ name: punctuation.definition.string.begin.xml
17
+ end: "'"
18
+ doublequotedString:
19
+ name: string.quoted.double.xml
20
+ endCaptures:
21
+ "0":
22
+ name: punctuation.definition.string.end.xml
23
+ begin: "\""
24
+ beginCaptures:
25
+ "0":
26
+ name: punctuation.definition.string.begin.xml
27
+ end: "\""
28
+ uuid: DB8033A1-6D8E-4D80-B8A2-8768AAC6125D
29
+ foldingStartMarker: ^\s*(<[^!?%/](?!.+?(/>|</.+?>))|<[!%]--(?!.+?--%?>)|<%[!]?(?!.+?%>))
30
+ patterns:
31
+ - name: meta.tag.xml.template
32
+ captures:
33
+ "1":
34
+ name: punctuation.definition.tag.xml
35
+ "2":
36
+ name: entity.name.tag.namespace.xml
37
+ "3":
38
+ name: entity.name.tag.xml
39
+ "4":
40
+ name: punctuation.separator.namespace.xml
41
+ "5":
42
+ name: entity.name.tag.localname.xml
43
+ begin: (<)(xsl)((:))(template)
44
+ end: (>)
45
+ patterns:
46
+ - captures:
47
+ "1":
48
+ name: entity.other.attribute-name.namespace.xml
49
+ "2":
50
+ name: entity.other.attribute-name.xml
51
+ "3":
52
+ name: punctuation.separator.namespace.xml
53
+ "4":
54
+ name: entity.other.attribute-name.localname.xml
55
+ match: " (?:([-_a-zA-Z0-9]+)((:)))?([a-zA-Z-]+)"
56
+ - include: "#doublequotedString"
57
+ - include: "#singlequotedString"
58
+ - include: text.xml
59
+ foldingStopMarker: ^\s*(</[^>]+>|[/%]>|-->)\s*$
60
+ keyEquivalent: ^~X
@@ -0,0 +1,3 @@
1
+ module Textpow
2
+ VERSION = Version = "1.3.0"
3
+ end
@@ -0,0 +1,107 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>BBEditDocumentType</key>
6
+ <string>CodelessLanguageModule</string>
7
+ <key>BBLMColorsSyntax</key>
8
+ <true/>
9
+ <key>BBLMIsCaseSensitive</key>
10
+ <true/>
11
+ <key>BBLMKeywordList</key>
12
+ <array>
13
+ <string>and</string>
14
+ <string>or</string>
15
+ <string>xor</string>
16
+ <string>virtual</string>
17
+ <string>if</string>
18
+ <string>else</string>
19
+ <string>do</string>
20
+ <string>while</string>
21
+ <string>use</string>
22
+ <string>bundle</string>
23
+ <string>native</string>
24
+ <string>static</string>
25
+ <string>public</string>
26
+ <string>private</string>
27
+ <string>class</string>
28
+ <string>interface</string>
29
+ <string>select</string>
30
+ <string>other</string>
31
+ <string>enum</string>
32
+ <string>for</string>
33
+ <string>each</string>
34
+ <string>label</string>
35
+ <string>return</string>
36
+ <string>Byte</string>
37
+ <string>Int</string>
38
+ <string>Parent</string>
39
+ <string>from</string>
40
+ <string>Float</string>
41
+ <string>Char</string>
42
+ <string>Bool</string>
43
+ <string>String</string>
44
+ <string>Nil</string>
45
+ <string>true</string>
46
+ <string>false</string>
47
+ <string>function</string>
48
+ <string>method</string>
49
+ </array>
50
+ <key>BBLMLanguageCode</key>
51
+ <string>LSL</string>
52
+ <key>BBLMLanguageDisplayName</key>
53
+ <string>Objeck</string>
54
+ <key>BBLMScansFunctions</key>
55
+ <true/>
56
+ <key>BBLMSuffixMap</key>
57
+ <array>
58
+ <dict>
59
+ <key>BBLMLanguageSuffix</key>
60
+ <string>.obs</string>
61
+ </dict>
62
+ </array>
63
+ <key>Language Features</key>
64
+ <dict>
65
+ <key>Close Block Comments</key>
66
+ <string>~#</string>
67
+ <key>Close Parameter Lists</key>
68
+ <string>)</string>
69
+ <key>Close Statement Blocks</key>
70
+ <string>}</string>
71
+ <key>Close Strings 1</key>
72
+ <string>&quot;</string>
73
+ <key>Close Strings 2</key>
74
+ <string>&apos;</string>
75
+ <key>End-of-line Ends Strings 1</key>
76
+ <false/>
77
+ <key>End-of-line Ends Strings 2</key>
78
+ <false/>
79
+ <key>Escape Char in Strings 1</key>
80
+ <string>\</string>
81
+ <key>Escape Char in Strings 2</key>
82
+ <string>\</string>
83
+ <key>Identifier and Keyword Characters</key>
84
+ <string>@0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz</string>
85
+ <key>Open Block Comments</key>
86
+ <string>#~</string>
87
+ <key>Open Line Comments</key>
88
+ <string>#</string>
89
+ <key>Open Parameter Lists</key>
90
+ <string>(</string>
91
+ <key>Open Statement Blocks</key>
92
+ <string>{</string>
93
+ <key>Open Strings 1</key>
94
+ <string>&quot;</string>
95
+ <key>Open Strings 2</key>
96
+ <string>&apos;</string>
97
+ <key>Prefix for Functions</key>
98
+ <string></string>
99
+ <key>Prefix for Procedures</key>
100
+ <string></string>
101
+ <key>Terminator for Prototypes 1</key>
102
+ <string></string>
103
+ <key>Terminator for Prototypes 2</key>
104
+ <string></string>
105
+ </dict>
106
+ </dict>
107
+ </plist>
@@ -0,0 +1 @@
1
+ ü
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift 'lib'
2
+ require 'textpow'
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Textpow::ScoreManager do
4
+ it "calculates scores" do
5
+ sp = Textpow::ScoreManager.new
6
+ reference_scope = 'text.html.basic source.php.embedded.html string.quoted.double.php'
7
+
8
+ sp.score('source.php string', reference_scope).should_not == 0
9
+ sp.score('text.html source.php', reference_scope).should_not == 0
10
+ sp.score('string source.php', reference_scope).should == 0
11
+ sp.score('source.php text.html', reference_scope).should == 0
12
+
13
+ sp.score('text.html source.php - string', reference_scope).should == 0
14
+ sp.score('text.html source.php - ruby', reference_scope ).should_not == 0
15
+
16
+ sp.score('string', reference_scope).should > sp.score('source.php', reference_scope)
17
+ sp.score('string.quoted', reference_scope).should > sp.score('source.php', reference_scope)
18
+ sp.score('text source string', reference_scope).should > sp.score( 'source string', reference_scope)
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe "syntax files" do
4
+ before do
5
+ STDERR.stub!(:puts)
6
+ end
7
+
8
+ it "has syntax files" do
9
+ Dir["#{Textpow.syntax_path}/*.syntax"].should_not == []
10
+ end
11
+
12
+ Dir["#{Textpow.syntax_path}/*.syntax"].each do |syntax|
13
+ it "can parse with #{syntax}" do
14
+ Textpow.syntax(syntax).parse("xxx\n1 + 1\n### xxx")
15
+ end
16
+
17
+ it "can parse UTF-8 with #{syntax}" do
18
+ Textpow.syntax(syntax).parse(File.read("spec/fixtures/utf8.txt"))
19
+ end
20
+ end
21
+
22
+ xit "parses markdown" do
23
+ node = Textpow.syntax("lib/textpow/syntax/broken/markdown.syntax")
24
+ node.parse("### xxx\nabc\n xxx\nyyy\n - abc\n - ac").stack.should_not == []
25
+ end
26
+ end
@@ -0,0 +1,225 @@
1
+ require 'spec_helper'
2
+
3
+ describe Textpow::SyntaxNode do
4
+ before do
5
+ Textpow::SyntaxNode.send(:class_variable_set, "@@syntaxes", {})
6
+ end
7
+
8
+ describe "#load" do
9
+ it "can load from xml .plist" do
10
+ Textpow::SyntaxNode.load('spec/fixtures/objeck.plist').should_not == nil
11
+ end
12
+
13
+ it "can load from yaml .syntax" do
14
+ Textpow::SyntaxNode.load('lib/textpow/syntax/source.ruby.syntax').should_not == nil
15
+ end
16
+
17
+ it "cannot load missing file" do
18
+ lambda{
19
+ Textpow::SyntaxNode.load('xxx.syntax')
20
+ }.should raise_error
21
+ end
22
+
23
+ it "cannot load missing plist file" do
24
+ lambda{
25
+ Textpow::SyntaxNode.load('xxx.plist')
26
+ }.should raise_error
27
+ end
28
+ end
29
+
30
+ describe "#new" do
31
+ it "loads strings from given hash" do
32
+ syntax = Textpow::SyntaxNode.new('content' => 'CONTENT', 'name' => 'NAME')
33
+ syntax.content.should == 'CONTENT'
34
+ syntax.name.should == 'NAME'
35
+ end
36
+
37
+ it "loads regex from given hash" do
38
+ syntax = Textpow::SyntaxNode.new('firstLineMatch' => 'aaa', 'foldingStartMarker' => 'bbb')
39
+ syntax.firstLineMatch.inspect.should == "/aaa/"
40
+ syntax.foldingStartMarker.inspect.should == "/bbb/"
41
+ end
42
+
43
+ it "raises ParsingError on invalid regex" do
44
+ lambda{
45
+ Textpow::SyntaxNode.new('firstLineMatch' => '$?)(:[/\]')
46
+ }.should raise_error(Textpow::ParsingError)
47
+ end
48
+
49
+ it "stores itself as parent" do
50
+ node = Textpow::SyntaxNode.new({})
51
+ node.syntax.should == node
52
+ end
53
+
54
+ it "stores given parent" do
55
+ node = Textpow::SyntaxNode.new({}, :syntax => 1)
56
+ node.syntax.should == 1
57
+ end
58
+
59
+ it "stores itself in global namespace under scopeName" do
60
+ node = Textpow::SyntaxNode.new("scopeName" => 'xxx')
61
+ node.syntaxes['xxx'].should == node
62
+ Textpow::SyntaxNode.new({}).syntaxes['xxx'].should == node
63
+ end
64
+
65
+ it "stores itself in scoped global namespace under scopeName" do
66
+ node = Textpow::SyntaxNode.new({"scopeName" => 'xxx'}, :name_space => 'foo')
67
+ node.syntaxes['xxx'].should == node
68
+ Textpow::SyntaxNode.new({},:name_space => 'foo').syntaxes['xxx'].should == node
69
+ Textpow::SyntaxNode.new({}).syntaxes['xxx'].should == nil
70
+ end
71
+ end
72
+
73
+ describe "#parse" do
74
+ let(:node){ Textpow.syntax('ruby') }
75
+
76
+ it "uses a RecordingProcessor by default" do
77
+ node.parse("111").stack.should == [
78
+ [:start_parsing, "source.ruby"],
79
+ [:new_line, "111"],
80
+ [:open_tag, "constant.numeric.ruby", 0],
81
+ [:close_tag, "constant.numeric.ruby", 3],
82
+ [:end_parsing, "source.ruby"]
83
+ ]
84
+ end
85
+
86
+ it "can parse with a processor" do
87
+ processor = Textpow::RecordingProcessor.new
88
+ processor.stack << 'xxx'
89
+ node.parse("111", processor).stack.should == [
90
+ "xxx",
91
+ [:start_parsing, "source.ruby"],
92
+ [:new_line, "111"],
93
+ [:open_tag, "constant.numeric.ruby", 0],
94
+ [:close_tag, "constant.numeric.ruby", 3],
95
+ [:end_parsing, "source.ruby"]
96
+ ]
97
+ end
98
+
99
+ it "can parse multiline syntax via stack" do
100
+ node.parse("=begin\n111\n=end").stack.should == [
101
+ [:start_parsing, "source.ruby"],
102
+ [:new_line, "=begin\n"],
103
+ [:open_tag, "comment.block.documentation.ruby", 0],
104
+ [:open_tag, "punctuation.definition.comment.ruby", 0],
105
+ [:close_tag, "punctuation.definition.comment.ruby", 6],
106
+ [:new_line, "111\n"],
107
+ [:new_line, "=end"],
108
+ [:open_tag, "punctuation.definition.comment.ruby", 0],
109
+ [:close_tag, "punctuation.definition.comment.ruby", 4],
110
+ [:close_tag, "comment.block.documentation.ruby", 4],
111
+ [:end_parsing, "source.ruby"]
112
+ ]
113
+ end
114
+
115
+ it "loads included syntax files" do
116
+ pending
117
+ node = Textpow.syntax('html_rails')
118
+ node.parse("<br/>")
119
+ end
120
+ end
121
+
122
+ describe "#match_first_son" do
123
+ it "returns nil when patterns are empty" do
124
+ node = Textpow::SyntaxNode.new({"scopeName" => 'xxx'})
125
+ node.send(:match_first_son, "xxx", 0).should == nil
126
+ end
127
+
128
+ it "matches a pattern" do
129
+ node = Textpow::SyntaxNode.new({"scopeName" => 'xxx', 'patterns' => [
130
+ {"match" => "xxx", "name" => "foo"}
131
+ ]})
132
+ pattern, match = node.send(:match_first_son, "xxxyy", 0)
133
+ match.to_s.should == 'xxx'
134
+ pattern.name.should == 'foo'
135
+ end
136
+
137
+ it "matches the first pattern" do
138
+ node = Textpow::SyntaxNode.new({"scopeName" => 'xxx', 'patterns' => [
139
+ {"match" => "yyy", "name" => "bar"},
140
+ {"match" => "xxx", "name" => "foo"},
141
+ {"match" => "zzz", "name" => "baz"},
142
+ ]})
143
+ pattern, match = node.send(:match_first_son, "xxxyyyzzz", 0)
144
+ match.to_s.should == 'xxx'
145
+ pattern.name.should == 'foo'
146
+ end
147
+
148
+ it "matches the first pattern for equal positions" do
149
+ node = Textpow::SyntaxNode.new({"scopeName" => 'xxx', 'patterns' => [
150
+ {"match" => "xxx", "name" => "bar"},
151
+ {"match" => "xxxyyy", "name" => "foo"},
152
+ {"match" => "xxxyy", "name" => "baz"},
153
+ ]})
154
+ pattern, match = node.send(:match_first_son, "xxxyyyzzz", 0)
155
+ match.to_s.should == 'xxx'
156
+ pattern.name.should == 'bar'
157
+ end
158
+ end
159
+
160
+ describe "proxying" do
161
+ it "cannot proxy by scopeName if syntax is missing" do
162
+ STDERR.should_not_receive(:puts)
163
+ node = Textpow::SyntaxNode.new({"scopeName" => 'xxx', 'patterns' => [{'include' => 'foo'}]})
164
+ node.parse('bar').stack.should == [
165
+ [:start_parsing, "xxx"],
166
+ [:new_line, "bar"],
167
+ [:end_parsing, "xxx"]
168
+ ]
169
+ end
170
+
171
+ it "can proxy by scopeName if syntax is available in repo" do
172
+ node = Textpow::SyntaxNode.new({"scopeName" => 'xxx', 'patterns' => [{'include' => 'source.ruby'}]})
173
+ node.parse('1').stack.should == [
174
+ [:start_parsing, "xxx"],
175
+ [:new_line, "1"],
176
+ [:open_tag, "constant.numeric.ruby", 0],
177
+ [:close_tag, "constant.numeric.ruby", 1],
178
+ [:end_parsing, "xxx"]
179
+ ]
180
+ end
181
+
182
+ it "can proxy by scopeName if syntax is loaded (even later)" do
183
+ node = Textpow::SyntaxNode.new({"scopeName" => 'xxx', 'patterns' => [{'include' => 'foo'}]})
184
+ Textpow::SyntaxNode.new({"scopeName" => 'foo', 'patterns' => [{'name' => 'foo.1', 'match' => 'bar'}]})
185
+ node.parse('bar').stack.should == [
186
+ [:start_parsing, "xxx"],
187
+ [:new_line, "bar"],
188
+ [:open_tag, "foo.1", 0],
189
+ [:close_tag, "foo.1", 3],
190
+ [:end_parsing, "xxx"]
191
+ ]
192
+ end
193
+
194
+ it "can proxy to a pattern defined in an repository" do
195
+ node = Textpow::SyntaxNode.new({"scopeName" => 'xxx',
196
+ 'repository' => {'foo' => {'name' => 'foo.1', 'match' => 'bar'}},
197
+ 'patterns' => [{'include' => '#foo'}]
198
+ })
199
+ node.parse('bar').stack.should == [
200
+ [:start_parsing, "xxx"],
201
+ [:new_line, "bar"],
202
+ [:open_tag, "foo.1", 0],
203
+ [:close_tag, "foo.1", 3],
204
+ [:end_parsing, "xxx"]
205
+ ]
206
+ end
207
+
208
+ it "can proxy to a pattern nested included in an repository" do
209
+ node = Textpow::SyntaxNode.new({"scopeName" => 'xxx',
210
+ 'repository' => {
211
+ 'baz' => {'patterns' => [{'include' => '#foo'}]},
212
+ 'foo' => {'name' => 'foo.1', 'match' => 'bar'}
213
+ },
214
+ 'patterns' => [{'include' => '#baz'}]
215
+ })
216
+ node.parse('bar').stack.should == [
217
+ [:start_parsing, "xxx"],
218
+ [:new_line, "bar"],
219
+ [:open_tag, "foo.1", 0],
220
+ [:close_tag, "foo.1", 3],
221
+ [:end_parsing, "xxx"]
222
+ ]
223
+ end
224
+ end
225
+ end