mucgly 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.rdoc +8 -0
  3. data/LICENSE +1 -1
  4. data/README.rdoc +160 -130
  5. data/bin/mucgly +4 -217
  6. data/doc/Mucgly.html +24 -82
  7. data/doc/_index.html +5 -153
  8. data/doc/class_list.html +7 -2
  9. data/doc/css/style.css +2 -1
  10. data/doc/file.CHANGELOG.html +16 -8
  11. data/doc/file.README.html +210 -187
  12. data/doc/file_list.html +6 -1
  13. data/doc/frames.html +5 -7
  14. data/doc/index.html +210 -187
  15. data/doc/js/app.js +7 -2
  16. data/doc/js/full_list.js +9 -6
  17. data/doc/method_list.html +7 -686
  18. data/doc/top-level-namespace.html +5 -5
  19. data/ext/mucgly/extconf.rb +11 -0
  20. data/ext/mucgly/mucgly.c +2095 -0
  21. data/lib/version.rb +6 -0
  22. data/test/golden/test_basic.txt +18 -0
  23. data/test/golden/test_specials_cli.txt +11 -0
  24. data/test/golden/test_specials_cmd.txt +36 -0
  25. data/test/result/test_basic.txt +18 -0
  26. data/test/result/test_specials_cli.txt +11 -0
  27. data/test/result/test_specials_cmd.txt +36 -0
  28. data/test/result/test_specials_cmd2.txt +1 -0
  29. data/test/test_basic.rx.txt +10 -6
  30. data/test/test_mucgly.rb +4 -6
  31. data/test/test_specials_cli.rx.txt +4 -4
  32. data/test/test_specials_cmd.rx.txt +5 -5
  33. metadata +45 -63
  34. data/Rakefile +0 -29
  35. data/doc/EasyFile/InOut.html +0 -2097
  36. data/doc/EasyFile/Read.html +0 -1334
  37. data/doc/EasyFile/ReadStack.html +0 -461
  38. data/doc/EasyFile/Stacked.html +0 -411
  39. data/doc/EasyFile/String.html +0 -570
  40. data/doc/EasyFile/Write.html +0 -1084
  41. data/doc/EasyFile/WriteStack.html +0 -305
  42. data/doc/EasyFile.html +0 -155
  43. data/doc/Mucgly/Env.html +0 -1675
  44. data/doc/Mucgly/MucglyFile/ParseState.html +0 -1662
  45. data/doc/Mucgly/MucglyFile/Token.html +0 -529
  46. data/doc/Mucgly/MucglyFile.html +0 -545
  47. data/doc/Mucgly/Separators.html +0 -521
  48. data/lib/easyfile.rb +0 -720
  49. data/lib/mucgly.rb +0 -627
  50. data/test/test_multi.rx.txt +0 -4
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d438186a60f6f48bf2b68fd7090f7cc3e375cca3
4
+ data.tar.gz: 69d49907c80a1faee873a275f228090f48d930e0
5
+ SHA512:
6
+ metadata.gz: 04b142e789d684fc49819c5289070fcd324cebb199c6a732301279b3b40938356902152d4d2dad2ad171becb8b290305ac0bb70c2fe51ed616141bf125bbcea7
7
+ data.tar.gz: 96a4e3c1271542ccd0e4174ef450f1e0344ac39121c66ca5784ba65bfbe116e5fa9b73f2037f1874a10ebedb3715b79e95356146f942530671b5a2f4e6a7f204
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,13 @@
1
1
  = Version history
2
2
 
3
+ [0.1.0] C-based implementation.
4
+ 100 times faster than older versions.
5
+ Multiple command line interface and internal cmd changes.
6
+ Not fully backwards compatible with older versions.
7
+
8
+ [0.0.3] Usage typo fix (hookend).
9
+ Added version method.
10
+
3
11
  [0.0.2] Dependency to Como for Gem.
4
12
 
5
13
  [0.0.1] Initial version.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 tero.isannainen@gmail.com
1
+ Copyright (c) 2014, 2015 tero.isannainen@gmail.com
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -2,67 +2,80 @@
2
2
 
3
3
  == Introduction
4
4
 
5
- Mucgly is a macro expander for inline macros that exist in the middle of
6
- body text. The macros are mostly regular Ruby code, but a few special
7
- commands is also provided.
5
+ Mucgly is a macro expander for inline macros that exist in the middle
6
+ of body text. The macros are expected to be mostly regular Ruby code,
7
+ but a few special commands are also available.
8
8
 
9
9
  A very simple example:
10
- Adding 1 + 3 results: -<write (1+3).to_s>-
10
+ Adding 1 + 3 results to: -<.1+3>-
11
11
 
12
12
  After macro expansion the results is:
13
- Adding 1 + 3 results: 4
13
+ Adding 1 + 3 results to: 4
14
14
 
15
15
  By default macro starts with "-<" and ends with ">-". These limiters
16
- are called hooks, hookbeg and hookend respectively. The code between
17
- hooks is regular Ruby code. The "write" call writes to selected IO
18
- stream.
16
+ are called hooks, hookbeg and hookend, respectively. The code between
17
+ hooks is mostly regular Ruby code. The first character is special
18
+ syntax and the rest is pure Ruby code. The special character (command)
19
+ "." is used to print the Ruby code evaluation value to current output
20
+ file (stream).
19
21
 
20
- Ruby code is executed within a class instance reserved for this
21
- purpose. The instance is called the Execution Environment. It enables
22
- values from one macro to be visible in others.
22
+ Sample session to execute the example above:
23
+ shell> mucgly
24
+ Adding 1 + 3 results to: -<.1+3>-
25
+ Adding 1 + 3 results to: 4
26
+ <Ctrl-D>
27
+ shell>
28
+
29
+
30
+ Ruby code is always executed in the Ruby interpreters "<main>" scope.
23
31
 
24
32
  Previous example with multiple macros:
25
33
  -<@a = 1>--<@b = 3>-\
26
- Adding 1 + 3 results: -<write (@a+@b).to_s>-
34
+ Adding 1 + 3 results to: -<Mucgly.write(@a+@b)>-
27
35
 
28
- Result is exactly the same as in the previous execution. The first
29
- macro "-<@a = 1>-" produces no output, it just sets the variable "@a"
30
- to "1". Second macro is similar. The default "escape" character is
36
+ Result is exactly the same as in the previous execution, but the Ruby
37
+ code is distributed into multiple segments. The first macro "-<@a =
38
+ 1>-" produces no output, it just sets the variable "@a" to "1". Second
39
+ macro is similar. The default "escape" character (hookesc) is
31
40
  "\\". When placed before newline character, it "eats" the newline and
32
41
  nothing is output. Thus the first line outputs nothing.
33
42
 
34
- The second line refers to settings from previous macros. Instance
35
- variables has to be used to maintain the data between macro calls (due
36
- to instance evaluation).
43
+ The macro on the second line refers to settings from previous
44
+ macros. Instance variables has to be used to share data between macro
45
+ calls (due to "<main>" evaluation). Local variables are not persistent
46
+ enough. Mucgly module method, "Mucgly.write", is used to write out the
47
+ calculation result. Mucgly module is defined within Mucgly utility.
37
48
 
38
49
 
39
50
  == Features
40
51
 
41
52
  * User settable hooks to define macro boundaries. Can be set from
42
- command line, configuration files, or from macro file.
53
+ command line, configuration files, or from macro input file.
43
54
 
44
55
  * Multiple sources for configuration: default config, environment
45
56
  variable, command line.
46
57
 
47
- * Multiple passes for macro file.
48
-
49
- * Convention based output file naming.
58
+ * Multipass support.
50
59
 
51
60
  * Multiple convenience functions for macros to use.
52
61
 
53
- * Macro file introspection: line number, file name
62
+ * Macro file introspection: line number, file name.
54
63
 
55
- * Output stream de-muxing.
64
+ * Output stream redirection (de-muxing).
56
65
 
57
66
  * Many special commands: include, source, etc...
58
67
 
68
+ * Fast C-language based macro file processing.
69
+
59
70
 
60
71
 
61
72
  == Applications
62
73
 
63
74
  * Replacement for M4 macro processor.
64
75
 
65
- * Code generation.
76
+ * Ruby pre-processor.
77
+
78
+ * General purpose code generation.
66
79
 
67
80
  * Document formatting.
68
81
 
@@ -75,169 +88,178 @@ to instance evaluation).
75
88
  === Hooks
76
89
 
77
90
  Hooks start and end the macro definition. By default hookbeg is "-<"
78
- and hookend is ">-". These values are not easily conflicting with the
79
- macro file body text.
91
+ and hookend is ">-". These values are not easily conflicting with
92
+ typical macro file body text.
80
93
 
81
- If literal hook string is required, the escape character should be
82
- place before the hook. For example "\-<" will produce literal "-<" to
83
- the output.
94
+ If literal hook string is required in the output, the hookesc sequence
95
+ should be place before the hook. For example "\\-<" will produce
96
+ literal "-<" to the output. "\\" is the default hookesc value.
84
97
 
85
98
  User can set the hooks to whatever string value desired. The hooks can
86
99
  also have the same value. However nested macros are not possible
87
- then. Hooks can also be the same as the escape character, but this
100
+ then. Hooks can also be the same as the escape sequence, but this
88
101
  makes usage somewhat complicated.
89
102
 
90
103
  === Escape
91
104
 
92
- Default escape character is "\\". It can be used to escape hooks,
93
- cancel space (" ") output, and cancel newline ("\\n") output.
105
+ Default hookesc (escape sequence) is "\\". It can be used to escape
106
+ hooks, cancel space (" ") output, and cancel newline ("\\n") output.
94
107
 
95
- User can set the escape character to any character. Only single
96
- character value is accepted.
108
+ User can set the escape sequence to any character(s).
97
109
 
98
- === Multipass
110
+ === Single char hooks and escape
99
111
 
100
- If the macro starts with "#" character, the macro is not expanded. One
101
- "#" character is removed and the rest of the macro is output as it
102
- is. Each pass will remove one "#" character and when all are removed,
103
- the macro is evaluated. Usually two passes are enough and one "#"
104
- character is used to save a macro to the later pass.
112
+ If all hooks are single character (including hookesc) and have the
113
+ same value, there are some additional rules that are used to identify
114
+ macro boundaries and escapes. Let's assume that the selected hook char
115
+ is "|" (vertical bar).
105
116
 
106
- Multipass can be used for example to create a Table Of Contents. First
107
- pass collects information about document content and second pass will
108
- insert the Table Of Contents.
117
+ Escape is detected if "| ", "|\\n", or "||" is seen in the input, when
118
+ outside macro. Escape is detected within macro if "||" is seen in input.
119
+
120
+ Hookbeg is detected at "|" if outside macro. Hookend is detected at
121
+ "|" if inside macro. Thus if literal "|" is needed inside macro, then
122
+ "||" must be used. Also expressing multilevel macros (macro in macro)
123
+ is not possible, since hookbeg is never detected within macro. The
124
+ default hook values can be used for nested macros (if desired).
109
125
 
110
- Example, with functions (insert_toc, header...) defined elsewhere:
111
- -<#insert_toc>-
112
- -<header(1, "My header 1")>-
113
- Paragraph1
114
- -<header(2, "My header 1.1")>-
115
- Paragraph2
116
- -<header(1, "My header 2")>-
117
- Paragraph3
118
126
 
119
127
 
120
128
  == Special commands
121
129
 
122
130
  In addition to regular Ruby code the macros are allowed to include so
123
131
  called Special Commands. These commands start with the ":" characters
124
- and with ".".
132
+ or with ".".
125
133
 
126
- Example:
127
- ...
128
- -<:hook [ ]->\
134
+
135
+ === Named commands
136
+
137
+ Example for named command:
129
138
  ...
139
+ -<:hook [ ]>-\
140
+ ...
141
+
142
+ Would change the hookbeg and hookend to "[" and "]" respectively. Note
143
+ that hooks are changed only for the current input file. If for example
144
+ an included input file changes hooks, the includer file still uses the
145
+ original hooks.
130
146
 
131
- Would change the hookbeg and hookend to "[" and "]" respectively. One
132
- special command is allowed per macro and it can't be mixed normal Ruby
133
- code. Command name is separated by ":" in the beginning and by space
134
- (" ") in the end. The rest of the macro is taken as argument to the
135
- macro. Note that a command without an argument has to end with space
136
- as well.
147
+ One special command is allowed per macro and it can't be mixed normal
148
+ Ruby code. Command name is separated by ":" in the beginning and by
149
+ space (" ") in the end. The rest of the macro is taken as argument to
150
+ the command.
137
151
 
138
152
  List of ":" style special commands:
139
153
 
140
154
  [include] Include reverts the input stream to the file given in the
141
- argument. Command can be used to multiplex multiple files
142
- into one, for example.
143
-
144
- [output] Select a new output file. Use with "close" command, when the
145
- new output file is ready.
155
+ argument. Command can be used for example to multiplex
156
+ multiple files into one (example: "-<:include input.txt>-"
157
+ ).
146
158
 
147
159
  [comment] Comment is used to add comments into the macro file. No
148
160
  output is produced from comment macros.
149
161
 
150
162
  [source] Source reads a plain Ruby file into the Execution Environment.
151
163
 
152
- [hook] Sets both hookbeg and hookend to values separated by space. The
153
- new hook values are valid immediately after the enclosing
154
- macro.
164
+ [hook] Sets both hookbeg and hookend to values separated by
165
+ space. Without space hookbeg and hookend are set to same value.
155
166
 
156
167
  [hookbeg] Sets hookbeg.
157
168
 
158
169
  [hookend] Sets hookend.
159
170
 
160
- [escape] Sets escape character.
171
+ [hookesc] Sets escape sequence.
172
+
173
+ [hookall] Sets hookbeg, hookend, and hookesc to same value.
161
174
 
162
- [exit] Aborts the macro file.
175
+ [exit] Aborts the macro processing (file).
163
176
 
164
- Variable value reference command starts with "." and is followed by
165
- the (instance) variable name.
177
+
178
+ === Quick commands
179
+
180
+ Special write command starts with "." and is followed by the Ruby
181
+ value.
166
182
 
167
183
  For example:
168
- ... -<.my_name>- ...
184
+ ... -<.@my_name>- ...
169
185
 
170
186
  Would write out the value of the "@my_name" variable, thus it is equal
171
187
  to writing:
172
- ... -<write @my_name>- ...
188
+ ... -<Mucgly.write @my_name>- ...
173
189
 
190
+ The special character "/" can also be used for comment macro, i.e. "/"
191
+ is same as ":comment ".
174
192
 
175
193
 
176
- == API methods
194
+ === Multipass
177
195
 
178
- API methods are instance methods of the Execution Environment,
179
- i.e. they are predefined and visible for the macro code. These methods
180
- are organized into two categories: Published and Hidden.
196
+ If the macro starts with "#" character, the macro is not excuted. The
197
+ macro content is output with "#" removed from the output, including
198
+ the current macro hooks. If 3 passes are needed, then "##" can be
199
+ placed to the initial macro file. Multipass macro files are processes
200
+ by (shell) piping the output of Mucgly to another Mucgly process.
181
201
 
182
- === Published methods
202
+ Multipass can be used for example to create a Table Of Contents. First
203
+ pass collects information about document content and second pass will
204
+ insert the Table Of Contents for a document.
183
205
 
184
- Published methods are the most commonly used methods in macros. These are:
206
+ Example, with functions (insert_toc, header...) defined elsewhere:
207
+ -<#insert_toc>-
208
+ -<header(1, "My header 1")>-
209
+ Paragraph1
210
+ -<header(2, "My header 1.1")>-
211
+ Paragraph2
212
+ -<header(1, "My header 2")>-
213
+ Paragraph3
214
+
215
+
216
+ == Mucgly module methods
185
217
 
186
- [write] Writes string into selected output IO.
187
- [puts] Writes string (+newline) into selected output IO.
188
- [source] Sources a plain Ruby file.
218
+ Ruby Mucgly module includes methods that are used to interact with
219
+ Mucgly program internals.
189
220
 
221
+ Methods "write", "puts" produce output to current output file
222
+ stream. Hook-commands change the current hook values.
190
223
 
191
- === Hidden methods
192
224
 
193
- Hidded methods start with underscore ("_"). The naming is used to
194
- prevent poluting the Execution Environment's namespace.
225
+ Complete list of Mucgly module methods:
195
226
 
196
- [_processFilePair] Process a pair of files. First half is input file
197
- and second is output file. File pair argument is an
198
- Array of two ([<fileI>, <fileO>]).
227
+ [write] Write string to current output file without newline.
199
228
 
200
- [_processFilePairs] Uses "_processFilePair" to process a list of file pairs.
229
+ [puts] Write string to current output file with newline.
201
230
 
202
- [_openInput] Sets input stream to given file. When this file is
203
- closed, the input stream is reverted to the original
204
- file.
231
+ [hookbeg] Get hookbeg value.
205
232
 
206
- [_openOutput] Sets output stream to given file. When this file is
207
- closed, the input stream is reverted to the original
208
- file.
233
+ [hookend] Get hookend value.
209
234
 
210
- [_openString] Open a StringIO file for output.
235
+ [hookesc] Get hookesc value.
211
236
 
212
- [_pushInput] Makes given file as top input stream. When this stream is
213
- closed, the input stream is reverted to the original
214
- file.
237
+ [sethookbeg] Set hookbeg value.
215
238
 
216
- [_pushOutput] Makes given file as top output stream. When this stream
217
- is closed, the output stream is reverted to the original
218
- file.
239
+ [sethookend] Set hookend value.
219
240
 
220
- [_closeInput] Close input stream.
241
+ [sethookesc] Set hookesc value.
221
242
 
222
- [_closeOutput] Close output stream.
243
+ [ifilename] Input file name as String.
223
244
 
224
- [_ofilename] Output file name as String.
245
+ [ilinenumber] Input file line number.
225
246
 
226
- [_olinenumber] Output file line number.
247
+ [ofilename] Output file name as String.
227
248
 
228
- [_ifilename] Input file name as String.
249
+ [olinenumber] Output file line number.
229
250
 
230
- [_ilinenumber] Input file line number.
251
+ [pushinput] Makes given file as current input stream. When this stream
252
+ is runs out (EOF) or is closed (with closeinput), the
253
+ input stream is reverted to previous input file.
231
254
 
232
- [_eval] Perform instance_eval on the given argument.
255
+ [closeinput] Close output stream (before EOF is encountered).
233
256
 
234
- [_inIO] Handle to input stream (get/set).
257
+ [pushoutput] Makes given file as top output stream. When this stream
258
+ is closed (with closeoutput), the output stream is
259
+ reverted to previous output file.
235
260
 
236
- [_outIO] Handle to output stream (get/set).
261
+ [closeoutput] Close output stream.
237
262
 
238
- [_separators] Handle to Separators object. Separotors object includes
239
- the "escapeChar", "hookBegChars", and "hookEndChars"
240
- setter and getter methods.
241
263
 
242
264
 
243
265
  == Command line interface
@@ -250,24 +272,20 @@ for an overview of the command line options.
250
272
 
251
273
  === Input and Output files
252
274
 
253
- Input files can be listed to "-i" option. The default input stream for
275
+ Input files can be listed to "-f" option. The default input stream for
254
276
  Mucgly is STDIN.
255
277
 
256
- Output files can be listed to "-o" option. The default output stream
278
+ Output file can be defined with "-o" option. The default output stream
257
279
  for Mucgly is STDOUT.
258
280
 
259
- If "-o" option is given without arguments and the input file list
260
- includes ".rx" in each name, the output file list is created by
261
- extracting ".rx" from each input file name.
281
+ If "-g" option is given, the output file list is created by extracting "-g" option argument value from each input file name.
262
282
 
263
283
  For example with:
264
- mucgly -i foo.rx.txt bar.rx.txt -o
284
+ mucgly -f foo.rx.txt -f bar.rx.txt -g .rx
265
285
 
266
286
  Two files, foo.txt and bar.txt, would be created. This holds true
267
287
  unless the output streams are manipulated with macro commands.
268
288
 
269
- If the number of input and output files match, then they are used in pairs.
270
-
271
289
 
272
290
  == Configuration
273
291
 
@@ -275,10 +293,6 @@ Mucgly checks for the existance of the "MUCGLY" environment
275
293
  variable. If the variable exists, the file in variable value is read
276
294
  in as plain Ruby.
277
295
 
278
- User configuration is searched from the users home directory:
279
- $HOME/.mucgly
280
- It is read as plain Ruby file if it exists.
281
-
282
296
  Configuration files can also be given on command line using the "-c"
283
297
  option. These settings can be used to override the settings above.
284
298
 
@@ -289,4 +303,20 @@ with "-l" option.
289
303
  == More information
290
304
 
291
305
  Check out the "test" directory within installation for detailed
292
- examples about usage.
306
+ examples about macro usage.
307
+
308
+
309
+ == Non-GEM installation
310
+
311
+ By default Mucgly is distributed as GEM. However Mucgly is by nature a
312
+ C-program. It can be compliled as "normal" C-program that just uses
313
+ Ruby Interpreter for evaluating Ruby macro content.
314
+
315
+ If Mucgly is used in C-main mode, it runs slightly faster, and with
316
+ smaller memory footprint.
317
+
318
+ Example compilation command (use in Mucgly GEM directory root):
319
+ gcc `pkg-config --cflags --libs glib-2.0` `pkg-config --cflags --libs ruby-2.1` -O2 -std=c11 -o mucgly ext/mucgly/mucgly.c
320
+
321
+ Executable file "mucgly" is created, which can be used the same way as
322
+ the GEM executable (i.e. same command line options).