broomhlda 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +201 -0
  3. data/lib/hl/define.ay +131 -0
  4. data/lib/hl/formatters/html.ay +26 -0
  5. data/lib/hl/lexer.ay +99 -0
  6. data/lib/hl/lexers/atomy.ay +122 -0
  7. data/lib/hl/lexers/haskell.ay +89 -0
  8. data/lib/hl/lexers/imported/abap.ay +43 -0
  9. data/lib/hl/lexers/imported/actionscript.ay +31 -0
  10. data/lib/hl/lexers/imported/actionscript3.ay +47 -0
  11. data/lib/hl/lexers/imported/ada.ay +107 -0
  12. data/lib/hl/lexers/imported/antlr.ay +95 -0
  13. data/lib/hl/lexers/imported/apacheconf.ay +29 -0
  14. data/lib/hl/lexers/imported/applescript.ay +48 -0
  15. data/lib/hl/lexers/imported/aspectj.ay +42 -0
  16. data/lib/hl/lexers/imported/asymptote.ay +64 -0
  17. data/lib/hl/lexers/imported/autohotkey.ay +76 -0
  18. data/lib/hl/lexers/imported/autoit.ay +64 -0
  19. data/lib/hl/lexers/imported/awk.ay +42 -0
  20. data/lib/hl/lexers/imported/bash.ay +63 -0
  21. data/lib/hl/lexers/imported/batch.ay +45 -0
  22. data/lib/hl/lexers/imported/bbcode.ay +23 -0
  23. data/lib/hl/lexers/imported/befunge.ay +26 -0
  24. data/lib/hl/lexers/imported/blitzmax.ay +44 -0
  25. data/lib/hl/lexers/imported/boo.ay +55 -0
  26. data/lib/hl/lexers/imported/brainfuck.ay +28 -0
  27. data/lib/hl/lexers/imported/bro.ay +57 -0
  28. data/lib/hl/lexers/imported/bugs.ay +31 -0
  29. data/lib/hl/lexers/imported/c.ay +84 -0
  30. data/lib/hl/lexers/imported/ca65.ay +26 -0
  31. data/lib/hl/lexers/imported/cbmbasicv2.ay +25 -0
  32. data/lib/hl/lexers/imported/ceylon.ay +47 -0
  33. data/lib/hl/lexers/imported/cfengine3.ay +50 -0
  34. data/lib/hl/lexers/imported/clojure.ay +32 -0
  35. data/lib/hl/lexers/imported/cmake.ay +38 -0
  36. data/lib/hl/lexers/imported/cobol.ay +44 -0
  37. data/lib/hl/lexers/imported/coffeescript.ay +79 -0
  38. data/lib/hl/lexers/imported/coldfusion.ay +36 -0
  39. data/lib/hl/lexers/imported/commonlisp.ay +65 -0
  40. data/lib/hl/lexers/imported/coq.ay +59 -0
  41. data/lib/hl/lexers/imported/croc.ay +37 -0
  42. data/lib/hl/lexers/imported/css.ay +55 -0
  43. data/lib/hl/lexers/imported/cuda.ay +84 -0
  44. data/lib/hl/lexers/imported/cython.ay +128 -0
  45. data/lib/hl/lexers/imported/d.ay +102 -0
  46. data/lib/hl/lexers/imported/darcspatch.ay +45 -0
  47. data/lib/hl/lexers/imported/dart.ay +84 -0
  48. data/lib/hl/lexers/imported/debiancontrol.ay +51 -0
  49. data/lib/hl/lexers/imported/dg.ay +61 -0
  50. data/lib/hl/lexers/imported/diff.ay +22 -0
  51. data/lib/hl/lexers/imported/django.ay +46 -0
  52. data/lib/hl/lexers/imported/dtd.ay +62 -0
  53. data/lib/hl/lexers/imported/dylan.ay +60 -0
  54. data/lib/hl/lexers/imported/dylanlid.ay +17 -0
  55. data/lib/hl/lexers/imported/ecl.ay +57 -0
  56. data/lib/hl/lexers/imported/elixir.ay +93 -0
  57. data/lib/hl/lexers/imported/erlang.ay +47 -0
  58. data/lib/hl/lexers/imported/factor.ay +89 -0
  59. data/lib/hl/lexers/imported/fancy.ay +54 -0
  60. data/lib/hl/lexers/imported/fantom.ay +149 -0
  61. data/lib/hl/lexers/imported/felix.ay +140 -0
  62. data/lib/hl/lexers/imported/fortran.ay +39 -0
  63. data/lib/hl/lexers/imported/foxpro.ay +37 -0
  64. data/lib/hl/lexers/imported/fsharp.ay +61 -0
  65. data/lib/hl/lexers/imported/gas.ay +51 -0
  66. data/lib/hl/lexers/imported/gettext.ay +21 -0
  67. data/lib/hl/lexers/imported/gherkin.ay +97 -0
  68. data/lib/hl/lexers/imported/glshader.ay +31 -0
  69. data/lib/hl/lexers/imported/gnuplot.ay +111 -0
  70. data/lib/hl/lexers/imported/go.ay +40 -0
  71. data/lib/hl/lexers/imported/gooddatacl.ay +33 -0
  72. data/lib/hl/lexers/imported/gosu.ay +58 -0
  73. data/lib/hl/lexers/imported/groff.ay +38 -0
  74. data/lib/hl/lexers/imported/groovy.ay +45 -0
  75. data/lib/hl/lexers/imported/haskell.ay +89 -0
  76. data/lib/hl/lexers/imported/haxe.ay +186 -0
  77. data/lib/hl/lexers/imported/hxml.ay +22 -0
  78. data/lib/hl/lexers/imported/hybris.ay +42 -0
  79. data/lib/hl/lexers/imported/idl.ay +23 -0
  80. data/lib/hl/lexers/imported/ini.ay +18 -0
  81. data/lib/hl/lexers/imported/io.ay +34 -0
  82. data/lib/hl/lexers/imported/ioke.ay +88 -0
  83. data/lib/hl/lexers/imported/irclogs.ay +24 -0
  84. data/lib/hl/lexers/imported/jags.ay +36 -0
  85. data/lib/hl/lexers/imported/java.ay +42 -0
  86. data/lib/hl/lexers/imported/javascript.ay +45 -0
  87. data/lib/hl/lexers/imported/json.ay +47 -0
  88. data/lib/hl/lexers/imported/julia.ay +60 -0
  89. data/lib/hl/lexers/imported/kconfig.ay +71 -0
  90. data/lib/hl/lexers/imported/koka.ay +104 -0
  91. data/lib/hl/lexers/imported/lasso.ay +143 -0
  92. data/lib/hl/lexers/imported/lighttpdconf.ay +24 -0
  93. data/lib/hl/lexers/imported/livescript.ay +82 -0
  94. data/lib/hl/lexers/imported/llvm.ay +36 -0
  95. data/lib/hl/lexers/imported/logtalk.ay +133 -0
  96. data/lib/hl/lexers/imported/lua.ay +56 -0
  97. data/lib/hl/lexers/imported/maql.ay +32 -0
  98. data/lib/hl/lexers/imported/matlab.ay +43 -0
  99. data/lib/hl/lexers/imported/minid.ay +37 -0
  100. data/lib/hl/lexers/imported/modula2.ay +63 -0
  101. data/lib/hl/lexers/imported/moinwiki.ay +33 -0
  102. data/lib/hl/lexers/imported/monkey.ay +84 -0
  103. data/lib/hl/lexers/imported/moocode.ay +26 -0
  104. data/lib/hl/lexers/imported/moonscript.ay +52 -0
  105. data/lib/hl/lexers/imported/mscgen.ay +35 -0
  106. data/lib/hl/lexers/imported/mupad.ay +36 -0
  107. data/lib/hl/lexers/imported/mysql.ay +37 -0
  108. data/lib/hl/lexers/imported/nasm.ay +52 -0
  109. data/lib/hl/lexers/imported/newlisp.ay +34 -0
  110. data/lib/hl/lexers/imported/newspeak.ay +49 -0
  111. data/lib/hl/lexers/imported/nginxconf.ay +41 -0
  112. data/lib/hl/lexers/imported/nimrod.ay +84 -0
  113. data/lib/hl/lexers/imported/nsis.ay +55 -0
  114. data/lib/hl/lexers/imported/numpy.ay +116 -0
  115. data/lib/hl/lexers/imported/objectivej.ay +120 -0
  116. data/lib/hl/lexers/imported/ocaml.ay +59 -0
  117. data/lib/hl/lexers/imported/octave.ay +39 -0
  118. data/lib/hl/lexers/imported/ooc.ay +45 -0
  119. data/lib/hl/lexers/imported/opa.ay +153 -0
  120. data/lib/hl/lexers/imported/openedge.ay +40 -0
  121. data/lib/hl/lexers/imported/perl.ay +130 -0
  122. data/lib/hl/lexers/imported/php.ay +63 -0
  123. data/lib/hl/lexers/imported/postscript.ay +39 -0
  124. data/lib/hl/lexers/imported/povray.ay +28 -0
  125. data/lib/hl/lexers/imported/powershell.ay +49 -0
  126. data/lib/hl/lexers/imported/prolog.ay +39 -0
  127. data/lib/hl/lexers/imported/properties.ay +17 -0
  128. data/lib/hl/lexers/imported/protobuf.ay +43 -0
  129. data/lib/hl/lexers/imported/puppet.ay +50 -0
  130. data/lib/hl/lexers/imported/pypylog.ay +44 -0
  131. data/lib/hl/lexers/imported/python.ay +116 -0
  132. data/lib/hl/lexers/imported/python3.ay +113 -0
  133. data/lib/hl/lexers/imported/qml.ay +47 -0
  134. data/lib/hl/lexers/imported/racket.ay +62 -0
  135. data/lib/hl/lexers/imported/ragel.ay +70 -0
  136. data/lib/hl/lexers/imported/rd.ay +22 -0
  137. data/lib/hl/lexers/imported/redcode.ay +23 -0
  138. data/lib/hl/lexers/imported/regedit.ay +25 -0
  139. data/lib/hl/lexers/imported/rpmspec.ay +57 -0
  140. data/lib/hl/lexers/imported/rust.ay +56 -0
  141. data/lib/hl/lexers/imported/s.ay +61 -0
  142. data/lib/hl/lexers/imported/scala.ay +72 -0
  143. data/lib/hl/lexers/imported/scheme.ay +31 -0
  144. data/lib/hl/lexers/imported/scilab.ay +37 -0
  145. data/lib/hl/lexers/imported/scss.ay +115 -0
  146. data/lib/hl/lexers/imported/smali.ay +71 -0
  147. data/lib/hl/lexers/imported/smalltalk.ay +93 -0
  148. data/lib/hl/lexers/imported/snobol.ay +42 -0
  149. data/lib/hl/lexers/imported/sourcepawn.ay +58 -0
  150. data/lib/hl/lexers/imported/sourceslist.ay +37 -0
  151. data/lib/hl/lexers/imported/sql.ay +31 -0
  152. data/lib/hl/lexers/imported/squidconf.ay +29 -0
  153. data/lib/hl/lexers/imported/stan.ay +38 -0
  154. data/lib/hl/lexers/imported/systemverilog.ay +65 -0
  155. data/lib/hl/lexers/imported/tcl.ay +110 -0
  156. data/lib/hl/lexers/imported/tcsh.ay +52 -0
  157. data/lib/hl/lexers/imported/tex.ay +49 -0
  158. data/lib/hl/lexers/imported/typescript.ay +51 -0
  159. data/lib/hl/lexers/imported/vala.ay +70 -0
  160. data/lib/hl/lexers/imported/vbnet.ay +62 -0
  161. data/lib/hl/lexers/imported/velocity.ay +50 -0
  162. data/lib/hl/lexers/imported/verilog.ay +61 -0
  163. data/lib/hl/lexers/imported/vgl.ay +25 -0
  164. data/lib/hl/lexers/imported/vhdl.ay +54 -0
  165. data/lib/hl/lexers/imported/vim.ay +28 -0
  166. data/lib/hl/lexers/imported/xml.ay +38 -0
  167. data/lib/hl/lexers/imported/xslt.ay +38 -0
  168. data/lib/hl/lexers/imported/xtend.ay +48 -0
  169. data/lib/hl/lexers/ruby.ay +238 -0
  170. data/lib/hl/state.ay +31 -0
  171. data/lib/hl/token.ay +8 -0
  172. data/lib/hl.ay +17 -0
  173. metadata +244 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b531cf8a1deb12865af0da4152652846aa41d4b8
4
+ data.tar.gz: 940fb9d11c3ed725af5e32c92b6d6988d3edc275
5
+ SHA512:
6
+ metadata.gz: c747b4053c1bc6b035f49207fcf5262d6b77f3634d79ec9dd46877f0ae28e35e4068c3afadbc8e088314ea51ffb18c791db5c209749497f2e7d4e27f12095c97
7
+ data.tar.gz: 4a1095545987f373e2a6a807db9d927569fb57985d32db51e854c8eee6dbbdd344e36d24b6533cc03cfa017db0fda818236ba39c09f5888eb02c6355fee6fd38
data/LICENSE.md ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/lib/hl/define.ay ADDED
@@ -0,0 +1,131 @@
1
+ use(require("atomy"))
2
+
3
+ lexer = require(File expand-path("../lexer", __FILE__))
4
+
5
+ const-set(.Lexer, lexer Lexer)
6
+ Lexer const-set(.Matcher, lexer Matcher)
7
+ Lexer const-set(.State, require(File expand-path("../state", __FILE__)))
8
+ Lexer const-set(.Token, require(File expand-path("../token", __FILE__)))
9
+
10
+ macro(lexer: ~*body):
11
+ `(Lexer class:
12
+ @matchers = Hash new
13
+ @info = Hash new
14
+
15
+ ~*body)
16
+
17
+ def(short-name(["name", "constant"])): "no"
18
+ def(short-name(["name", "entity"])): "ni"
19
+ def(short-name(["name", "property"])): "py"
20
+ def(short-name(["literal", b])): short-name([b])
21
+ def(short-name([a, "other"])): short-name([a]) + "x"
22
+ def(short-name([a, "error"])): short-name([a]) + "r"
23
+ def(short-name([a, "single"])): short-name([a]) + "1"
24
+ def(short-name([a, "double"])): short-name([a]) + "2"
25
+ def(short-name([a, b])): short-name([a]) + short-name([b])
26
+ def(short-name(["error"])): "err"
27
+ def(short-name(["number"])): "m"
28
+ def(short-name([x])): x slice(0, 1)
29
+ def(short-name(_ . xs)): short-name(xs)
30
+
31
+ fn(str(x)): Atomy Grammar AST StringLiteral new(x)
32
+
33
+ def(type-from(x & Atomy Grammar AST Word)):
34
+ `(Token Tagged new(~str(short-name([x text to-s]))))
35
+
36
+ def(type-from(`((~a). ~(b)))):
37
+ tag = short-name([
38
+ a text to-s
39
+ b text to-s])
40
+ `(Token Tagged new(~str(tag)))
41
+
42
+ def(type-from(`(~_ (~a). ~(b)))):
43
+ tag = short-name([
44
+ a text to-s
45
+ b text to-s])
46
+ `(Token Tagged new(~str(tag)))
47
+
48
+ def(type-from(`(by-groups(~*args)))):
49
+ `(Token ByGroups new([~*(args collect [a]: type-from(a))]))
50
+
51
+ def(type-from(`(using(~who)))):
52
+ `(Token Using new(~who))
53
+
54
+ def(type-from(x)): raise("unknown match type: " + x inspect)
55
+
56
+ def(regexp-from(x, regexps)):
57
+ regexps <<
58
+ `([x]: Regexp new(
59
+ x source
60
+ x options | @info fetch(.flags)
61
+ ); call(~x))
62
+
63
+ `(regexps[~(Atomy Grammar AST Number new(regexps size - 1))])
64
+
65
+ def(state-from('pop)): '(State Pop new)
66
+ def(state-from(`(pop(~n)))): `(State PopNum new(~n))
67
+ def(state-from('push)): '(State Push new)
68
+ def(state-from(`(do-all(~*args)))):
69
+ `(State DoAll new([~*(args collect [a]: state-from(a))]))
70
+ def(state-from(`(combined(~*args)))):
71
+ all = args reverse collect [a]:
72
+ `(@matchers fetch(.~a))
73
+
74
+ `(State Combined new([~*all]))
75
+ def(state-from(`(go-to(~n)))):
76
+ `(State GoTo new(@matchers, .~n))
77
+ def(state-from(x)):
78
+ raise("unknown state: " + x inspect)
79
+
80
+
81
+ macro(lex(~name): ~*tokens):
82
+ `(lex(~name) []: ~*tokens)
83
+
84
+ macro(lex(~name) [~*args]: ~*tokens):
85
+ branches = []
86
+
87
+ body = []
88
+
89
+ regexps = []
90
+
91
+ tokens each [c]:
92
+ c match:
93
+ -- implicit continue state
94
+ `(~x is(~y)):
95
+ branches <<
96
+ `(Matcher new(
97
+ ~(regexp-from(x, regexps))
98
+ ~(type-from(y))
99
+ State Continue new
100
+ ))
101
+
102
+ -- specifying a state
103
+ `(~x is(~y) -> ~z):
104
+ branches <<
105
+ `(Matcher new(
106
+ ~(regexp-from(x, regexps))
107
+ ~(type-from(y))
108
+ ~(state-from(z))
109
+ ))
110
+
111
+ -- goto shortcut
112
+ `(~x is(~y) => ~z):
113
+ branches <<
114
+ `(Matcher new(
115
+ ~(regexp-from(x, regexps))
116
+ ~(type-from(y))
117
+ State GoTo new(@matchers, .~z)
118
+ ))
119
+
120
+ `(any-of(~any)):
121
+ branches <<
122
+ `(@matchers fetch(.~any) call) -- TODO: parameterization?
123
+
124
+ _:
125
+ body << c
126
+
127
+ body << `([~*branches] flatten)
128
+
129
+ `([regexps] {
130
+ @matchers[.~name] = proc [~*args]: ~*body
131
+ } call([~*regexps]))
@@ -0,0 +1,26 @@
1
+ -- TODO: use my li'l html lib from anatomy (extract to gem)
2
+ use(require("atomy"))
3
+
4
+ require("rubygems")
5
+ require("nokogiri")
6
+
7
+ formatter = class:
8
+ def(initialize(@tokens, @line-numbers = false)):
9
+ .ok
10
+
11
+ def(format(builder = Nokogiri XML Builder new)):
12
+ builder
13
+ div(#{ .class: "highlight" }) [d]:
14
+ d pre [p]:
15
+ format-tokens(p)
16
+
17
+ builder doc children first serialize(#{ .save-with: 0 })
18
+
19
+ def(format-tokens(to)):
20
+ @tokens each [t]:
21
+ to span(#{ .class: t type tag }) [s]:
22
+ s text(t contents)
23
+
24
+ to
25
+
26
+ const-set(.Formatter, formatter)
data/lib/hl/lexer.ay ADDED
@@ -0,0 +1,99 @@
1
+ use(require("atomy"))
2
+
3
+ token = require(File expand-path("../token", __FILE__))
4
+
5
+
6
+ Error data(NoMatchFor(@input))
7
+
8
+ def(NoMatchFor(input) message):
9
+ "no matchers succeeded for: " +
10
+ (input slice(0, 50) inspect + " [...]")
11
+
12
+
13
+ data(Matcher(@regexp, @type, @next))
14
+
15
+ -- TODO: Using
16
+ fn(tokens(data, gs & token ByGroups)):
17
+ gs types zip(data to-a drop(1)) [t, d]:
18
+ when(t nil? || d nil?):
19
+ return(nil)
20
+
21
+ @lexed << token Token new(t, d)
22
+
23
+ fn(tokens(data, t & token Tagged)):
24
+ @lexed << token Token new(t, data to-s)
25
+
26
+ -- go through matchers until one matches the immediate
27
+ -- next input. if none match, try again, but allowing
28
+ -- matches past the start.
29
+ fn(try-all(matchers)):
30
+ closest = nil
31
+ worked = nil
32
+
33
+ matchers each [m]:
34
+ d = m regexp match(@input)
35
+ when(d && (!closest || (d pre-match size < closest pre-match size))):
36
+ &closest = d
37
+ &worked = m
38
+
39
+ when(closest pre-match empty?):
40
+ break
41
+
42
+ unless(closest):
43
+ /error(NoMatchFor new(@input))
44
+
45
+ skipped = closest pre-match
46
+ @input = closest post-match
47
+
48
+ worked next apply(@state, closest)
49
+
50
+ unless(skipped empty?):
51
+ @lexed <<
52
+ token Token new(
53
+ token Tagged new("err")
54
+ skipped)
55
+
56
+ tokens(closest, worked type)
57
+
58
+ lexer = class:
59
+ def(initialize(input)):
60
+ @input = input dup
61
+
62
+ @state = [
63
+ class matchers[class info[.start]][]
64
+ ] -- [Matcher]
65
+
66
+ @lexed = [] -- [Token]
67
+
68
+ -- run the lexer until the input is empty, yielding
69
+ -- the lexed tokens
70
+ def(run):
71
+ until(@input empty?):
72
+ try-all(@state last)
73
+
74
+ @lexed
75
+
76
+ singleton:
77
+ attr-accessor(.matchers, .info)
78
+
79
+ def(lex(x)): new(x) run
80
+
81
+ def(name &x):
82
+ @info[.name] = x call
83
+
84
+ def(aliases &x):
85
+ @info[.aliases] = x call
86
+
87
+ def(extensions &x):
88
+ @info[.extensions] = x call
89
+
90
+ def(mimetypes &x):
91
+ @info[.mimetypes] = x call
92
+
93
+ def(start &x):
94
+ @info[.start] = x call
95
+
96
+ def(flags &x):
97
+ @info[.flags] = x call
98
+
99
+ const-set(.Lexer, lexer)
@@ -0,0 +1,122 @@
1
+ use(require("atomy"))
2
+ use(require("hl/define"))
3
+
4
+ lexer = lexer:
5
+ name: "Atomy"
6
+ aliases: "atomy"
7
+ extensions: [".ay"]
8
+ mimetypes: "text/x-atomy"
9
+ start: .root
10
+ flags: Regexp MULTILINE
11
+
12
+ @@ident-char = raw"[\p{L}\d\-_]"
13
+ @@identifier = r"[\p{Ll}_]#{@@ident-char}*"
14
+
15
+ @@op-char = raw"[\p{S}!@#%&*\-\\.\/\?]"
16
+ @@operator = r"(?!~`):?#{@@op-char}+"
17
+
18
+ @@ascii = [
19
+ "NUL","SOH","[SE]TX","EOT","ENQ","ACK",
20
+ "BEL","BS","HT","LF","VT","FF","CR","S[OI]","DLE",
21
+ "DC[1-4]","NAK","SYN","ETB","CAN",
22
+ "EM","SUB","ESC","[FGRU]S","SP","DEL"
23
+ ]
24
+
25
+
26
+ fn(word(reg)):
27
+ r"(?<!#{@@op-char}|#{@@ident-char})#{reg}(?!#{@@op-char}|#{@@ident-char})"
28
+
29
+
30
+ -- starting point for lexing
31
+ lex(root):
32
+ -- comments
33
+ r"--.*?$" is(comment.single)
34
+ r"{-" is(comment.multiline) => in-comment
35
+
36
+ -- primitive constants
37
+ word(r"true|false|nil|undefined") is(keyword.constant)
38
+ word(r"self") is(name.builtin.pseudo)
39
+
40
+ -- constants
41
+ r"[A-Z][a-zA-Z0-9_]*" is(name.constant)
42
+
43
+ -- floats
44
+ r"[\+\-]?\d+[eE][\+\-]?\d+" is(number.float)
45
+ r"[\+\-]?\d+\.\d+([eE][\+\-]?\d+)?" is(number.float)
46
+
47
+ -- integers
48
+ r"[\+\-]?0[oO][0-7]+" is(number.octal)
49
+ r"[\+\-]?0[xX][\da-fA-F]+" is(number.hexadecimal)
50
+ r"[\+\-]?\d+" is(number.integer)
51
+
52
+ -- reserved words
53
+ word(r"#language") is(keyword.reserved)
54
+
55
+ -- special variables
56
+ r"@@#{@@identifier}" is(name.variable.class)
57
+ r"\$#{@@identifier}" is(name.variable.global)
58
+ r"@#{@@identifier}" is(name.variable.instance)
59
+
60
+ -- particles
61
+ r"\.#{@@identifier}" is(string.symbol)
62
+
63
+ -- quoting expressions
64
+ r"['`]#{@@identifier}" is(string.symbol)
65
+ r"['`]" is(string.symbol)
66
+
67
+ -- unquote
68
+ r"~#{@@identifier}" is(string.interpolate)
69
+ r"~" is(string.interpolate)
70
+
71
+ -- macro-quotes
72
+ r"(#{@@identifier})(\")" is(by-groups(name, string)) => macro-quote
73
+
74
+ -- identifiers
75
+ @@identifier is(name)
76
+
77
+ -- operators
78
+ @@operator is(operator)
79
+
80
+ -- strings
81
+ r"\"" is(string) => in-string
82
+
83
+ -- whitespace
84
+ r"\s+" is(text)
85
+
86
+ -- punctuation
87
+ r"[\[\](),:;{}|]" is(punctuation)
88
+
89
+
90
+ -- inside of a block comment; handle nesting
91
+ lex(in-comment):
92
+ r"[^\-\{\}]+" is(comment.multiline)
93
+ r"{-" is(comment.multiline) -> push
94
+ r"-}" is(comment.multiline) -> pop
95
+ r"[-{}]" is(comment.mutline)
96
+
97
+
98
+ -- inside of a string; contain escapes
99
+ lex(in-string):
100
+ r"[^\\\"]+" is(string)
101
+ r"\\" is(string.escape) => escape
102
+ r"\"" is(string) -> pop
103
+
104
+
105
+ -- match delimiters in a macro-quote, skipping escapes
106
+ lex(macro-quote) [d]:
107
+ r"[^\\\"]" is(string)
108
+ r"\\." is(string)
109
+ r"\"" is(string) -> pop
110
+
111
+
112
+ -- all of our character escapes
113
+ lex(escape):
114
+ r"[nsrtvfbae\\\"]" is(string.escape) -> pop
115
+ r"\^[\]\[A-Z@\^_]" is(string.escape) -> pop
116
+ Regexp new(@@ascii join("|")) is(string.escape) -> pop
117
+ r"o[0-7]+" is(string.escape) -> pop
118
+ r"x[\da-fA-F]+" is(string.escape) -> pop
119
+ r"\d+" is(string.escape) -> pop
120
+ r"\s+\\" is(string.escape) -> pop
121
+
122
+ const-set(.Lexer, lexer)
@@ -0,0 +1,89 @@
1
+ use(require("atomy"))
2
+ use(require("hl/define"))
3
+
4
+ lexer = lexer:
5
+ name: "Haskell"
6
+ aliases: ["haskell", "hs"]
7
+ extensions: [".hs"]
8
+ mimetypes: ["text/x-haskell"]
9
+ start: .root
10
+ flags: Regexp MULTILINE
11
+
12
+ lex(comment):
13
+ Regexp new("[^-{}]+") is(comment.multiline)
14
+ Regexp new("{-") is(comment.multiline) -> push
15
+ Regexp new("-}") is(comment.multiline) -> pop
16
+ Regexp new("[-{}]") is(comment.multiline)
17
+
18
+ lex(funclist):
19
+ Regexp new("\\s+") is(text)
20
+ Regexp new("[A-Z][a-zA-Z0-9_]*") is(keyword.type)
21
+ Regexp new("(_[\\w']+|[a-z][\\w']*)") is(name.function)
22
+ Regexp new("--.*$") is(comment.single)
23
+ Regexp new("{-") is(comment.multiline) -> go-to(comment)
24
+ Regexp new(",") is(punctuation)
25
+ Regexp new("[:!#$%&*+.\\\\/<=>?@^|\126-]+") is(operator)
26
+ Regexp new("\\(") is(punctuation) -> do-all(go-to(funclist), go-to(funclist))
27
+ Regexp new("\\)") is(punctuation) -> pop(2)
28
+
29
+ lex(string):
30
+ Regexp new("[^\\\\\"]+") is(literal.string)
31
+ Regexp new("\\\\") is(literal.string.escape) -> go-to(escape)
32
+ Regexp new("\"") is(literal.string) -> pop
33
+
34
+ lex(import):
35
+ Regexp new("\\s+") is(text)
36
+ Regexp new("\"") is(literal.string) -> go-to(string)
37
+ Regexp new("\\)") is(punctuation) -> pop
38
+ Regexp new("qualified\\b(?!')") is(keyword)
39
+ Regexp new("([A-Z][a-zA-Z0-9_.]*)(\\s+)(as)(\\s+)([A-Z][a-zA-Z0-9_.]*)") is(by-groups(name.namespace, text, keyword, text, name)) -> pop
40
+ Regexp new("([A-Z][a-zA-Z0-9_.]*)(\\s+)(hiding)(\\s+)(\\()") is(by-groups(name.namespace, text, keyword, text, punctuation)) -> go-to(funclist)
41
+ Regexp new("([A-Z][a-zA-Z0-9_.]*)(\\s+)(\\()") is(by-groups(name.namespace, text, punctuation)) -> go-to(funclist)
42
+ Regexp new("[a-zA-Z0-9_.]+") is(name.namespace) -> pop
43
+
44
+ lex(escape):
45
+ Regexp new("[abfnrtv\"\\'&\\\\]") is(literal.string.escape) -> pop
46
+ Regexp new("\\^[\\]\\[A-Z@\\^_]") is(literal.string.escape) -> pop
47
+ Regexp new("NUL|SOH|[SE]TX|EOT|ENQ|ACK|BEL|BS|HT|LF|VT|FF|CR|S[OI]|DLE|DC[1-4]|NAK|SYN|ETB|CAN|EM|SUB|ESC|[FGRU]S|SP|DEL") is(literal.string.escape) -> pop
48
+ Regexp new("o[0-7]+") is(literal.string.escape) -> pop
49
+ Regexp new("x[\\da-fA-F]+") is(literal.string.escape) -> pop
50
+ Regexp new("\\d+") is(literal.string.escape) -> pop
51
+ Regexp new("\\s+\\\\") is(literal.string.escape) -> pop
52
+
53
+ lex(root):
54
+ Regexp new("\\s+") is(text)
55
+ Regexp new("--(?![!#$%&*+./<=>?@\\^|_\126]).*?$") is(comment.single)
56
+ Regexp new("{-") is(comment.multiline) -> go-to(comment)
57
+ Regexp new("\\bimport(?!\\')\\b") is(keyword.reserved) -> go-to(import)
58
+ Regexp new("\\bmodule(?!\\')\\b") is(keyword.reserved) -> go-to(module)
59
+ Regexp new("\\berror(?!\\')\\b") is(name.exception)
60
+ Regexp new("\\b(case|class|data|default|deriving|do|else|if|in|infix[lr]?|instance|let|newtype|of|then|type|where|_)(?!\\')\\b") is(keyword.reserved)
61
+ Regexp new("^[_a-z][\\w\\']*") is(name.function)
62
+ Regexp new("[_a-z][\\w\\']*") is(name)
63
+ Regexp new("[A-Z][\\w\\']*") is(keyword.type)
64
+ Regexp new("\\\\(?![:!#$%&*+.\\\\/<=>?@^|\126-]+)") is(name.function)
65
+ Regexp new("(<-|::|->|=>|=)(?![:!#$%&*+.\\\\/<=>?@^|\126-]+)") is(operator.word)
66
+ Regexp new(":[:!#$%&*+.\\\\/<=>?@^|\126-]*") is(keyword.type)
67
+ Regexp new("[:!#$%&*+.\\\\/<=>?@^|\126-]+") is(operator)
68
+ Regexp new("\\d+[eE][+-]?\\d+") is(literal.number.float)
69
+ Regexp new("\\d+\\.\\d+([eE][+-]?\\d+)?") is(literal.number.float)
70
+ Regexp new("0[oO][0-7]+") is(literal.number.oct)
71
+ Regexp new("0[xX][\\da-fA-F]+") is(literal.number.hex)
72
+ Regexp new("\\d+") is(literal.number.integer)
73
+ Regexp new("'") is(literal.string.char) -> go-to(character)
74
+ Regexp new("\"") is(literal.string) -> go-to(string)
75
+ Regexp new("\\[\\]") is(keyword.type)
76
+ Regexp new("\\(\\)") is(name.builtin)
77
+ Regexp new("[\\]\\[(),;`{}]") is(punctuation)
78
+
79
+ lex(module):
80
+ Regexp new("\\s+") is(text)
81
+ Regexp new("([A-Z][a-zA-Z0-9_.]*)(\\s+)(\\()") is(by-groups(name.namespace, text, punctuation)) -> go-to(funclist)
82
+ Regexp new("[A-Z][a-zA-Z0-9_.]*") is(name.namespace) -> pop
83
+
84
+ lex(character):
85
+ Regexp new("[^\\\\']") is(literal.string.char)
86
+ Regexp new("\\\\") is(literal.string.escape) -> go-to(escape)
87
+ Regexp new("'") is(literal.string.char) -> pop
88
+
89
+ const-set(.Lexer, lexer)