mkrf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGELOG +2 -0
  2. data/MIT-LICENSE +7 -0
  3. data/README +54 -0
  4. data/Rakefile +107 -0
  5. data/lib/mkrf.rb +4 -0
  6. data/lib/mkrf/availability.rb +219 -0
  7. data/lib/mkrf/generator.rb +146 -0
  8. data/test/abstract_unit.rb +4 -0
  9. data/test/fixtures/down_a_directory/header_down_a_directory.h +1 -0
  10. data/test/fixtures/stdmkrf.h +1 -0
  11. data/test/sample_files/libtrivial/Rakefile +31 -0
  12. data/test/sample_files/libtrivial/extconf.rb +3 -0
  13. data/test/sample_files/libtrivial/lib/libtrivial.c +5 -0
  14. data/test/sample_files/libtrivial/lib/libtrivial.o +0 -0
  15. data/test/sample_files/libtrivial/libtrivial_so.bundle +0 -0
  16. data/test/sample_files/libtrivial/mkrf.log +1 -0
  17. data/test/sample_files/libxml-ruby-0.3.8/CHANGELOG +74 -0
  18. data/test/sample_files/libxml-ruby-0.3.8/LICENSE +22 -0
  19. data/test/sample_files/libxml-ruby-0.3.8/README +144 -0
  20. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/cbg.c +76 -0
  21. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/extconf.rb +49 -0
  22. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.c +86 -0
  23. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.h +82 -0
  24. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.rb +107 -0
  25. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/mkrf.log +1 -0
  26. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/old_extconf.rb +95 -0
  27. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.c +372 -0
  28. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.h +21 -0
  29. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.c +224 -0
  30. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.h +21 -0
  31. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.c +1159 -0
  32. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.h +27 -0
  33. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.c +168 -0
  34. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.h +17 -0
  35. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.c +167 -0
  36. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.h +21 -0
  37. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.c +2139 -0
  38. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.h +28 -0
  39. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.c +248 -0
  40. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.h +26 -0
  41. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.c +153 -0
  42. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.h +21 -0
  43. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.c +1417 -0
  44. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.h +31 -0
  45. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.c +715 -0
  46. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.h +22 -0
  47. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.c +426 -0
  48. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.h +52 -0
  49. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.c +142 -0
  50. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.h +16 -0
  51. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.c +43 -0
  52. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.h +12 -0
  53. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.c +20 -0
  54. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.h +13 -0
  55. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.c +363 -0
  56. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.h +24 -0
  57. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.c +125 -0
  58. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.h +24 -0
  59. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.c +100 -0
  60. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.h +27 -0
  61. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.c +21 -0
  62. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.h +18 -0
  63. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/sax_parser_callbacks.inc +202 -0
  64. data/test/sample_files/syck-0.55/CHANGELOG +186 -0
  65. data/test/sample_files/syck-0.55/COPYING +54 -0
  66. data/test/sample_files/syck-0.55/Makefile +582 -0
  67. data/test/sample_files/syck-0.55/Makefile.am +5 -0
  68. data/test/sample_files/syck-0.55/Makefile.in +582 -0
  69. data/test/sample_files/syck-0.55/README +105 -0
  70. data/test/sample_files/syck-0.55/README.BYTECODE +484 -0
  71. data/test/sample_files/syck-0.55/README.EXT +444 -0
  72. data/test/sample_files/syck-0.55/RELEASE +123 -0
  73. data/test/sample_files/syck-0.55/TODO +25 -0
  74. data/test/sample_files/syck-0.55/aclocal.m4 +883 -0
  75. data/test/sample_files/syck-0.55/bootstrap +7 -0
  76. data/test/sample_files/syck-0.55/config.h +79 -0
  77. data/test/sample_files/syck-0.55/config.h.in +78 -0
  78. data/test/sample_files/syck-0.55/config.status +1197 -0
  79. data/test/sample_files/syck-0.55/config/README +14 -0
  80. data/test/sample_files/syck-0.55/config/depcomp +529 -0
  81. data/test/sample_files/syck-0.55/config/install-sh +323 -0
  82. data/test/sample_files/syck-0.55/config/missing +357 -0
  83. data/test/sample_files/syck-0.55/configure +6728 -0
  84. data/test/sample_files/syck-0.55/configure.in +36 -0
  85. data/test/sample_files/syck-0.55/ext/ruby/CHANGELOG +303 -0
  86. data/test/sample_files/syck-0.55/ext/ruby/README +400 -0
  87. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/MANIFEST +1 -0
  88. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/bytecode.c +1170 -0
  89. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/emitter.c +1224 -0
  90. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/extconf.rb +10 -0
  91. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.c +1894 -0
  92. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.h +79 -0
  93. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/handler.c +174 -0
  94. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/implicit.c +2989 -0
  95. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/mkrf.log +1 -0
  96. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/node.c +407 -0
  97. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/rubyext.c +2385 -0
  98. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.c +504 -0
  99. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.h +458 -0
  100. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/token.c +2707 -0
  101. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yaml2byte.c +250 -0
  102. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yamlbyte.h +170 -0
  103. data/test/sample_files/syck-0.55/ext/ruby/install.rb +1022 -0
  104. data/test/sample_files/syck-0.55/ext/ruby/lib/okay.rb +161 -0
  105. data/test/sample_files/syck-0.55/ext/ruby/lib/okay/news.rb +69 -0
  106. data/test/sample_files/syck-0.55/ext/ruby/lib/okay/rpc.rb +434 -0
  107. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml.rb +436 -0
  108. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/baseemitter.rb +247 -0
  109. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/basenode.rb +216 -0
  110. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/compat.rb +26 -0
  111. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/constants.rb +45 -0
  112. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/dbm.rb +111 -0
  113. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/emitter.rb +107 -0
  114. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/encoding.rb +33 -0
  115. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/error.rb +34 -0
  116. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/rubytypes.rb +438 -0
  117. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/store.rb +29 -0
  118. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stream.rb +40 -0
  119. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb +83 -0
  120. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/syck.rb +19 -0
  121. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/tag.rb +86 -0
  122. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/types.rb +188 -0
  123. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/yamlnode.rb +54 -0
  124. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/ypath.rb +52 -0
  125. data/test/sample_files/syck-0.55/ext/ruby/lib/yod.rb +1168 -0
  126. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-modules.rb +27 -0
  127. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-sample.rb +336 -0
  128. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-validate.rb +341 -0
  129. data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-client.rb +51 -0
  130. data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-server.rb +85 -0
  131. data/test/sample_files/syck-0.55/ext/ruby/samples/yaml-sortHashKeys.rb +128 -0
  132. data/test/sample_files/syck-0.55/ext/ruby/tests/basic.rb +1653 -0
  133. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsAnchorAlias.yml +51 -0
  134. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBasicTests.yml +282 -0
  135. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockMapping.yml +78 -0
  136. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockSequence.yml +0 -0
  137. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsDocumentSeparator.yml +102 -0
  138. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsErrorTests.yml +23 -0
  139. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFlowCollections.yml +73 -0
  140. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFoldedScalars.yml +215 -0
  141. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsMapInSeq.yml +0 -0
  142. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsNullsAndEmpties.yml +66 -0
  143. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsRubyTests.yml +182 -0
  144. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsSpecificationExamples.yml +2699 -0
  145. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsTypeTransfers.yml +265 -0
  146. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsYpath.yml +221 -0
  147. data/test/sample_files/syck-0.55/ext/ruby/yts/cookbook.rb +159 -0
  148. data/test/sample_files/syck-0.55/ext/ruby/yts/index.yml +10 -0
  149. data/test/sample_files/syck-0.55/ext/ruby/yts/yts.rb +193 -0
  150. data/test/sample_files/syck-0.55/lib/Makefile +497 -0
  151. data/test/sample_files/syck-0.55/lib/Makefile.am +27 -0
  152. data/test/sample_files/syck-0.55/lib/Makefile.in +497 -0
  153. data/test/sample_files/syck-0.55/lib/bytecode.c +1170 -0
  154. data/test/sample_files/syck-0.55/lib/bytecode.re +525 -0
  155. data/test/sample_files/syck-0.55/lib/emitter.c +1224 -0
  156. data/test/sample_files/syck-0.55/lib/gram.c +1894 -0
  157. data/test/sample_files/syck-0.55/lib/gram.h +79 -0
  158. data/test/sample_files/syck-0.55/lib/gram.output +2005 -0
  159. data/test/sample_files/syck-0.55/lib/gram.y +481 -0
  160. data/test/sample_files/syck-0.55/lib/handler.c +174 -0
  161. data/test/sample_files/syck-0.55/lib/implicit.c +2989 -0
  162. data/test/sample_files/syck-0.55/lib/implicit.re +206 -0
  163. data/test/sample_files/syck-0.55/lib/node.c +407 -0
  164. data/test/sample_files/syck-0.55/lib/syck.c +504 -0
  165. data/test/sample_files/syck-0.55/lib/syck.h +458 -0
  166. data/test/sample_files/syck-0.55/lib/syck_st.c +577 -0
  167. data/test/sample_files/syck-0.55/lib/syck_st.h +46 -0
  168. data/test/sample_files/syck-0.55/lib/token.c +2707 -0
  169. data/test/sample_files/syck-0.55/lib/token.re +1139 -0
  170. data/test/sample_files/syck-0.55/lib/yaml2byte.c +250 -0
  171. data/test/sample_files/syck-0.55/lib/yamlbyte.h +170 -0
  172. data/test/sample_files/syck-0.55/stamp-h1 +1 -0
  173. data/test/sample_files/syck-0.55/tests/Basic.c +141 -0
  174. data/test/sample_files/syck-0.55/tests/CuTest.c +294 -0
  175. data/test/sample_files/syck-0.55/tests/CuTest.h +84 -0
  176. data/test/sample_files/syck-0.55/tests/Emit.c +87 -0
  177. data/test/sample_files/syck-0.55/tests/Makefile +480 -0
  178. data/test/sample_files/syck-0.55/tests/Makefile.am +13 -0
  179. data/test/sample_files/syck-0.55/tests/Makefile.in +480 -0
  180. data/test/sample_files/syck-0.55/tests/Parse.c +208 -0
  181. data/test/sample_files/syck-0.55/tests/YTS.c +2310 -0
  182. data/test/sample_files/syck-0.55/tests/YTS.c.erb +326 -0
  183. data/test/sample_files/syck-0.55/tests/YTS.c.rb +44 -0
  184. data/test/test_availability.rb +68 -0
  185. data/test/test_generator.rb +74 -0
  186. metadata +252 -0
@@ -0,0 +1,1139 @@
1
+ /*
2
+ * token.re
3
+ *
4
+ * $Author: why $
5
+ * $Date: 2005/04/13 06:27:54 $
6
+ *
7
+ * Copyright (C) 2003 why the lucky stiff
8
+ */
9
+ #include "syck.h"
10
+ #include "gram.h"
11
+
12
+ /*
13
+ * Allocate quoted strings in chunks
14
+ */
15
+ #define QUOTELEN 1024
16
+
17
+ /*
18
+ * They do my bidding...
19
+ */
20
+ #define YYCTYPE char
21
+ #define YYCURSOR parser->cursor
22
+ #define YYMARKER parser->marker
23
+ #define YYLIMIT parser->limit
24
+ #define YYTOKEN parser->token
25
+ #define YYTOKTMP parser->toktmp
26
+ #define YYLINEPTR parser->lineptr
27
+ #define YYLINECTPTR parser->linectptr
28
+ #define YYLINE parser->linect
29
+ #define YYFILL(n) syck_parser_read(parser)
30
+
31
+ /*
32
+ * Repositions the cursor at `n' offset from the token start.
33
+ * Only works in `Header' and `Document' sections.
34
+ */
35
+ #define YYPOS(n) YYCURSOR = YYTOKEN + n
36
+
37
+ /*
38
+ * Track line numbers
39
+ */
40
+ #define NEWLINE(ptr) YYLINEPTR = ptr + newline_len(ptr); if ( YYLINEPTR > YYLINECTPTR ) { YYLINE++; YYLINECTPTR = YYLINEPTR; }
41
+
42
+ /*
43
+ * I like seeing the level operations as macros...
44
+ */
45
+ #define ADD_LEVEL(len, status) syck_parser_add_level( parser, len, status )
46
+ #define POP_LEVEL() syck_parser_pop_level( parser )
47
+ #define CURRENT_LEVEL() syck_parser_current_level( parser )
48
+
49
+ /*
50
+ * Force a token next time around sycklex()
51
+ */
52
+ #define FORCE_NEXT_TOKEN(tok) parser->force_token = tok;
53
+
54
+ /*
55
+ * Nice little macro to ensure we're YAML_IOPENed to the current level.
56
+ * * Only use this macro in the "Document" section *
57
+ */
58
+ #define ENSURE_YAML_IOPEN(last_lvl, to_len, reset) \
59
+ if ( last_lvl->spaces < to_len ) \
60
+ { \
61
+ if ( last_lvl->status == syck_lvl_iseq || last_lvl->status == syck_lvl_imap ) \
62
+ { \
63
+ goto Document; \
64
+ } \
65
+ else \
66
+ { \
67
+ ADD_LEVEL( to_len, syck_lvl_doc ); \
68
+ if ( reset == 1 ) YYPOS(0); \
69
+ return YAML_IOPEN; \
70
+ } \
71
+ }
72
+
73
+ /*
74
+ * Nice little macro to ensure closure of levels.
75
+ * * Only use this macro in the "Document" section *
76
+ */
77
+ #define ENSURE_YAML_IEND(last_lvl, to_len) \
78
+ if ( last_lvl->spaces > to_len ) \
79
+ { \
80
+ syck_parser_pop_level( parser ); \
81
+ YYPOS(0); \
82
+ return YAML_IEND; \
83
+ }
84
+
85
+ /*
86
+ * Concatenates quoted string items and manages allocation
87
+ * to the quoted string
88
+ */
89
+ #define QUOTECAT(s, c, i, l) \
90
+ { \
91
+ if ( i + 1 >= c ) \
92
+ { \
93
+ c += QUOTELEN; \
94
+ S_REALLOC_N( s, char, c ); \
95
+ } \
96
+ s[i++] = l; \
97
+ s[i] = '\0'; \
98
+ }
99
+
100
+ #define QUOTECATS(s, c, i, cs, cl) \
101
+ { \
102
+ while ( i + cl >= c ) \
103
+ { \
104
+ c += QUOTELEN; \
105
+ S_REALLOC_N( s, char, c ); \
106
+ } \
107
+ S_MEMCPY( s + i, cs, char, cl ); \
108
+ i += cl; \
109
+ s[i] = '\0'; \
110
+ }
111
+
112
+ /*
113
+ * Tags a plain scalar with a transfer method
114
+ * * Use only in "Plain" section *
115
+ */
116
+ #define RETURN_IMPLICIT() \
117
+ { \
118
+ SyckNode *n = syck_alloc_str(); \
119
+ YYCURSOR = YYTOKEN; \
120
+ n->data.str->ptr = qstr; \
121
+ n->data.str->len = qidx; \
122
+ n->data.str->style = scalar_plain; \
123
+ sycklval->nodeData = n; \
124
+ if ( parser->implicit_typing == 1 ) \
125
+ { \
126
+ try_tag_implicit( sycklval->nodeData, parser->taguri_expansion ); \
127
+ } \
128
+ return YAML_PLAIN; \
129
+ }
130
+
131
+ /* concat the inline characters to the plain scalar */
132
+ #define PLAIN_NOT_INL() \
133
+ if ( *(YYCURSOR - 1) == ' ' || is_newline( YYCURSOR - 1 ) ) \
134
+ { \
135
+ YYCURSOR--; \
136
+ } \
137
+ QUOTECATS(qstr, qcapa, qidx, YYTOKEN, YYCURSOR - YYTOKEN); \
138
+ goto Plain2;
139
+
140
+ /* trim spaces off the end in case of indent */
141
+ #define PLAIN_IS_INL() \
142
+ char *walker = qstr + qidx - 1; \
143
+ while ( walker > qstr && ( *walker == '\n' || *walker == ' ' ) ) \
144
+ { \
145
+ qidx--; \
146
+ walker[0] = '\0'; \
147
+ walker--; \
148
+ }
149
+
150
+ /*
151
+ * Keep or chomp block?
152
+ * * Use only in "ScalarBlock" section *
153
+ */
154
+ #define RETURN_YAML_BLOCK() \
155
+ { \
156
+ SyckNode *n = syck_alloc_str(); \
157
+ if ( ((SyckParser *)parser)->taguri_expansion == 1 ) \
158
+ { \
159
+ n->type_id = syck_taguri( YAML_DOMAIN, "str", 3 ); \
160
+ } \
161
+ else \
162
+ { \
163
+ n->type_id = syck_strndup( "str", 3 ); \
164
+ } \
165
+ n->data.str->ptr = qstr; \
166
+ n->data.str->len = qidx; \
167
+ if ( blockType == BLOCK_LIT ) { \
168
+ n->data.str->style = scalar_literal; \
169
+ } else { \
170
+ n->data.str->style = scalar_fold; \
171
+ } \
172
+ if ( qidx > 0 ) \
173
+ { \
174
+ if ( nlDoWhat != NL_KEEP ) \
175
+ { \
176
+ char *fc = n->data.str->ptr + n->data.str->len - 1; \
177
+ while ( is_newline( fc ) ) fc--; \
178
+ if ( nlDoWhat != NL_CHOMP && fc < n->data.str->ptr + n->data.str->len - 1 ) \
179
+ fc += 1; \
180
+ n->data.str->len = fc - n->data.str->ptr + 1; \
181
+ } \
182
+ } \
183
+ sycklval->nodeData = n; \
184
+ return YAML_BLOCK; \
185
+ }
186
+
187
+ /*
188
+ * Handles newlines, calculates indent
189
+ */
190
+ #define GOBBLE_UP_YAML_INDENT( ict, start ) \
191
+ char *indent = start; \
192
+ NEWLINE(indent); \
193
+ while ( indent < YYCURSOR ) \
194
+ { \
195
+ if ( is_newline( ++indent ) ) \
196
+ { \
197
+ NEWLINE(indent); \
198
+ } \
199
+ } \
200
+ ict = 0; \
201
+ if ( *YYCURSOR == '\0' ) \
202
+ { \
203
+ ict = -1; \
204
+ start = YYCURSOR - 1; \
205
+ } \
206
+ else if ( *YYLINEPTR == ' ' ) \
207
+ { \
208
+ ict = YYCURSOR - YYLINEPTR; \
209
+ }
210
+
211
+ /*
212
+ * If an indent exists at the current level, back up.
213
+ */
214
+ #define GET_TRUE_YAML_INDENT(indt_len) \
215
+ { \
216
+ SyckLevel *lvl_deep = CURRENT_LEVEL(); \
217
+ indt_len = lvl_deep->spaces; \
218
+ if ( indt_len == YYTOKEN - YYLINEPTR ) \
219
+ { \
220
+ SyckLevel *lvl_over; \
221
+ parser->lvl_idx--; \
222
+ lvl_over = CURRENT_LEVEL(); \
223
+ indt_len = lvl_over->spaces; \
224
+ parser->lvl_idx++; \
225
+ } \
226
+ }
227
+
228
+ /*
229
+ * Argjh! I hate globals! Here for syckerror() only!
230
+ */
231
+ SyckParser *syck_parser_ptr = NULL;
232
+
233
+ /*
234
+ * Accessory funcs later in this file.
235
+ */
236
+ void eat_comments( SyckParser * );
237
+ char escape_seq( char );
238
+ int is_newline( char *ptr );
239
+ int newline_len( char *ptr );
240
+ int sycklex_yaml_utf8( YYSTYPE *, SyckParser * );
241
+ int sycklex_bytecode_utf8( YYSTYPE *, SyckParser * );
242
+ int syckwrap();
243
+
244
+ /*
245
+ * My own re-entrant sycklex() using re2c.
246
+ * You really get used to the limited regexp.
247
+ * It's really nice to not rely on backtracking and such.
248
+ */
249
+ int
250
+ sycklex( YYSTYPE *sycklval, SyckParser *parser )
251
+ {
252
+ switch ( parser->input_type )
253
+ {
254
+ case syck_yaml_utf8:
255
+ return sycklex_yaml_utf8( sycklval, parser );
256
+
257
+ case syck_yaml_utf16:
258
+ syckerror( "UTF-16 is not currently supported in Syck.\nPlease contribute code to help this happen!" );
259
+ break;
260
+
261
+ case syck_yaml_utf32:
262
+ syckerror( "UTF-32 is not currently supported in Syck.\nPlease contribute code to help this happen!" );
263
+ break;
264
+
265
+ case syck_bytecode_utf8:
266
+ return sycklex_bytecode_utf8( sycklval, parser );
267
+ }
268
+ }
269
+
270
+ /*
271
+ * Parser for standard YAML [UTF-8]
272
+ */
273
+ int
274
+ sycklex_yaml_utf8( YYSTYPE *sycklval, SyckParser *parser )
275
+ {
276
+ int doc_level = 0;
277
+ syck_parser_ptr = parser;
278
+ if ( YYCURSOR == NULL )
279
+ {
280
+ syck_parser_read( parser );
281
+ }
282
+
283
+ if ( parser->force_token != 0 )
284
+ {
285
+ int t = parser->force_token;
286
+ parser->force_token = 0;
287
+ return t;
288
+ }
289
+
290
+ /*!re2c
291
+
292
+ YWORDC = [A-Za-z0-9_-] ;
293
+ YWORDP = [A-Za-z0-9_-\.] ;
294
+ LF = ( "\n" | "\r\n" ) ;
295
+ SPC = " " ;
296
+ ENDSPC = ( SPC+ | LF );
297
+ YINDENT = LF ( SPC | LF )* ;
298
+ NULL = [\000] ;
299
+ ANY = [\001-\377] ;
300
+ ISEQO = "[" ;
301
+ ISEQC = "]" ;
302
+ IMAPO = "{" ;
303
+ IMAPC = "}" ;
304
+ CDELIMS = ( ISEQC | IMAPC ) ;
305
+ ICOMMA = ( "," ENDSPC ) ;
306
+ ALLX = ( ":" ENDSPC ) ;
307
+ DIR = "%" YWORDP+ ":" YWORDP+ ;
308
+ YBLOCK = [>|] [-+0-9]* ENDSPC ;
309
+ HEX = [0-9A-Fa-f] ;
310
+ ESCSEQ = ["\\abefnrtv0] ;
311
+
312
+ */
313
+
314
+ if ( YYLINEPTR != YYCURSOR )
315
+ {
316
+ goto Document;
317
+ }
318
+
319
+ Header:
320
+
321
+ YYTOKEN = YYCURSOR;
322
+
323
+ /*!re2c
324
+
325
+ "---" ENDSPC { SyckLevel *lvl = CURRENT_LEVEL();
326
+ if ( lvl->status == syck_lvl_header )
327
+ {
328
+ YYPOS(3);
329
+ goto Directive;
330
+ }
331
+ else
332
+ {
333
+ ENSURE_YAML_IEND(lvl, -1);
334
+ YYPOS(0);
335
+ return 0;
336
+ }
337
+ }
338
+
339
+ "..." ENDSPC { SyckLevel *lvl = CURRENT_LEVEL();
340
+ if ( lvl->status == syck_lvl_header )
341
+ {
342
+ goto Header;
343
+ }
344
+ else
345
+ {
346
+ ENSURE_YAML_IEND(lvl, -1);
347
+ YYPOS(0);
348
+ return 0;
349
+ }
350
+ return 0;
351
+ }
352
+
353
+ "#" { eat_comments( parser );
354
+ goto Header;
355
+ }
356
+
357
+ NULL { SyckLevel *lvl = CURRENT_LEVEL();
358
+ ENSURE_YAML_IEND(lvl, -1);
359
+ YYPOS(0);
360
+ return 0;
361
+ }
362
+
363
+ YINDENT { GOBBLE_UP_YAML_INDENT( doc_level, YYTOKEN );
364
+ goto Header;
365
+ }
366
+
367
+ SPC+ { doc_level = YYCURSOR - YYLINEPTR;
368
+ goto Header;
369
+ }
370
+
371
+ ANY { YYPOS(0);
372
+ goto Document;
373
+ }
374
+
375
+ */
376
+
377
+ Document:
378
+ {
379
+ SyckLevel *lvl = CURRENT_LEVEL();
380
+ if ( lvl->status == syck_lvl_header )
381
+ {
382
+ lvl->status = syck_lvl_doc;
383
+ }
384
+
385
+ YYTOKEN = YYCURSOR;
386
+
387
+ /*!re2c
388
+
389
+ YINDENT { /* Isolate spaces */
390
+ int indt_len;
391
+ GOBBLE_UP_YAML_INDENT( indt_len, YYTOKEN );
392
+ lvl = CURRENT_LEVEL();
393
+ doc_level = 0;
394
+
395
+ /* XXX: Comment lookahead */
396
+ if ( *YYCURSOR == '#' )
397
+ {
398
+ goto Document;
399
+ }
400
+
401
+ /* Ignore indentation inside inlines */
402
+ if ( lvl->status == syck_lvl_iseq || lvl->status == syck_lvl_imap )
403
+ {
404
+ goto Document;
405
+ }
406
+
407
+ /* Check for open indent */
408
+ ENSURE_YAML_IEND(lvl, indt_len);
409
+ ENSURE_YAML_IOPEN(lvl, indt_len, 0);
410
+ if ( indt_len == -1 )
411
+ {
412
+ return 0;
413
+ }
414
+ return YAML_INDENT;
415
+ }
416
+
417
+ ISEQO { ENSURE_YAML_IOPEN(lvl, doc_level, 1);
418
+ lvl = CURRENT_LEVEL();
419
+ ADD_LEVEL(lvl->spaces + 1, syck_lvl_iseq);
420
+ return YYTOKEN[0];
421
+ }
422
+
423
+ IMAPO { ENSURE_YAML_IOPEN(lvl, doc_level, 1);
424
+ lvl = CURRENT_LEVEL();
425
+ ADD_LEVEL(lvl->spaces + 1, syck_lvl_imap);
426
+ return YYTOKEN[0];
427
+ }
428
+
429
+ CDELIMS { POP_LEVEL();
430
+ return YYTOKEN[0];
431
+ }
432
+
433
+ [:,] ENDSPC { YYPOS(1);
434
+ return YYTOKEN[0];
435
+ }
436
+
437
+ [-?] ENDSPC { ENSURE_YAML_IOPEN(lvl, YYTOKEN - YYLINEPTR, 1);
438
+ FORCE_NEXT_TOKEN(YAML_IOPEN);
439
+ if ( *YYCURSOR == '#' || is_newline( YYCURSOR ) || is_newline( YYCURSOR - 1 ) )
440
+ {
441
+ YYCURSOR--;
442
+ ADD_LEVEL((YYTOKEN + 1) - YYLINEPTR, syck_lvl_doc);
443
+ }
444
+ else /* spaces followed by content uses the space as indentation */
445
+ {
446
+ ADD_LEVEL(YYCURSOR - YYLINEPTR, syck_lvl_doc);
447
+ }
448
+ return YYTOKEN[0];
449
+ }
450
+
451
+ "&" YWORDC+ { sycklval->name = syck_strndup( YYTOKEN + 1, YYCURSOR - YYTOKEN - 1 );
452
+
453
+ /*
454
+ * Remove previous anchors of the same name. Since the parser will likely
455
+ * construct deeper nodes first, we want those nodes to be placed in the
456
+ * queue for matching at a higher level of indentation.
457
+ */
458
+ syck_hdlr_remove_anchor(parser, sycklval->name);
459
+ return YAML_ANCHOR;
460
+ }
461
+
462
+ "*" YWORDC+ { ENSURE_YAML_IOPEN(lvl, doc_level, 1);
463
+ sycklval->name = syck_strndup( YYTOKEN + 1, YYCURSOR - YYTOKEN - 1 );
464
+ return YAML_ALIAS;
465
+ }
466
+
467
+ "!" { goto TransferMethod; }
468
+
469
+ "'" { ENSURE_YAML_IOPEN(lvl, doc_level, 1);
470
+ goto SingleQuote; }
471
+
472
+ "\"" { ENSURE_YAML_IOPEN(lvl, doc_level, 1);
473
+ goto DoubleQuote; }
474
+
475
+ YBLOCK { if ( is_newline( YYCURSOR - 1 ) )
476
+ {
477
+ YYCURSOR--;
478
+ }
479
+ goto ScalarBlock;
480
+ }
481
+
482
+ "#" { eat_comments( parser );
483
+ goto Document;
484
+ }
485
+
486
+ SPC+ { goto Document; }
487
+
488
+ NULL { ENSURE_YAML_IEND(lvl, -1);
489
+ YYPOS(0);
490
+ return 0;
491
+ }
492
+
493
+ ANY { ENSURE_YAML_IOPEN(lvl, doc_level, 1);
494
+ goto Plain;
495
+ }
496
+
497
+ */
498
+ }
499
+
500
+ Directive:
501
+ {
502
+ YYTOKTMP = YYCURSOR;
503
+
504
+ /*!re2c
505
+
506
+ DIR { goto Directive; }
507
+
508
+ SPC+ { goto Directive; }
509
+
510
+ ANY { YYCURSOR = YYTOKTMP;
511
+ return YAML_DOCSEP;
512
+ }
513
+ */
514
+
515
+ }
516
+
517
+ Plain:
518
+ {
519
+ int qidx = 0;
520
+ int qcapa = 100;
521
+ char *qstr = S_ALLOC_N( char, qcapa );
522
+ SyckLevel *plvl;
523
+ int parentIndent;
524
+
525
+ YYCURSOR = YYTOKEN;
526
+ plvl = CURRENT_LEVEL();
527
+ GET_TRUE_YAML_INDENT(parentIndent);
528
+
529
+ Plain2:
530
+ YYTOKEN = YYCURSOR;
531
+
532
+ Plain3:
533
+
534
+ /*!re2c
535
+
536
+ YINDENT { int indt_len, nl_count = 0;
537
+ SyckLevel *lvl;
538
+ char *tok = YYTOKEN;
539
+ GOBBLE_UP_YAML_INDENT( indt_len, tok );
540
+ lvl = CURRENT_LEVEL();
541
+
542
+ if ( indt_len <= parentIndent )
543
+ {
544
+ RETURN_IMPLICIT();
545
+ }
546
+
547
+ while ( YYTOKEN < YYCURSOR )
548
+ {
549
+ int nl_len = 0;
550
+ if ( nl_len = newline_len( YYTOKEN++ ) )
551
+ {
552
+ nl_count++;
553
+ YYTOKEN += nl_len - 1;
554
+ }
555
+ }
556
+ if ( nl_count <= 1 )
557
+ {
558
+ QUOTECAT(qstr, qcapa, qidx, ' ');
559
+ }
560
+ else
561
+ {
562
+ int i;
563
+ for ( i = 0; i < nl_count - 1; i++ )
564
+ {
565
+ QUOTECAT(qstr, qcapa, qidx, '\n');
566
+ }
567
+ }
568
+
569
+ goto Plain2;
570
+ }
571
+
572
+ ALLX { RETURN_IMPLICIT(); }
573
+
574
+ ICOMMA { if ( plvl->status != syck_lvl_iseq && plvl->status != syck_lvl_imap )
575
+ {
576
+ PLAIN_NOT_INL();
577
+ }
578
+ else
579
+ {
580
+ PLAIN_IS_INL();
581
+ }
582
+ RETURN_IMPLICIT();
583
+ }
584
+
585
+ IMAPC { if ( plvl->status != syck_lvl_imap )
586
+ {
587
+ PLAIN_NOT_INL();
588
+ }
589
+ else
590
+ {
591
+ PLAIN_IS_INL();
592
+ }
593
+ RETURN_IMPLICIT();
594
+ }
595
+
596
+ ISEQC { if ( plvl->status != syck_lvl_iseq )
597
+ {
598
+ PLAIN_NOT_INL();
599
+ }
600
+ else
601
+ {
602
+ PLAIN_IS_INL();
603
+ }
604
+ RETURN_IMPLICIT();
605
+ }
606
+
607
+ " #" { eat_comments( parser );
608
+ RETURN_IMPLICIT();
609
+ }
610
+
611
+ NULL { RETURN_IMPLICIT(); }
612
+
613
+ SPC { goto Plain3; }
614
+
615
+ ANY { QUOTECATS(qstr, qcapa, qidx, YYTOKEN, YYCURSOR - YYTOKEN);
616
+ goto Plain2;
617
+ }
618
+
619
+ */
620
+ }
621
+
622
+ SingleQuote:
623
+ {
624
+ int qidx = 0;
625
+ int qcapa = 100;
626
+ char *qstr = S_ALLOC_N( char, qcapa );
627
+
628
+ SingleQuote2:
629
+ YYTOKEN = YYCURSOR;
630
+
631
+ /*!re2c
632
+
633
+ YINDENT { int indt_len;
634
+ int nl_count = 0;
635
+ SyckLevel *lvl;
636
+ GOBBLE_UP_YAML_INDENT( indt_len, YYTOKEN );
637
+ lvl = CURRENT_LEVEL();
638
+
639
+ if ( lvl->status != syck_lvl_str )
640
+ {
641
+ ADD_LEVEL( indt_len, syck_lvl_str );
642
+ }
643
+ else if ( indt_len < lvl->spaces )
644
+ {
645
+ /* Error! */
646
+ }
647
+
648
+ while ( YYTOKEN < YYCURSOR )
649
+ {
650
+ int nl_len = 0;
651
+ if ( nl_len = newline_len( YYTOKEN++ ) )
652
+ {
653
+ nl_count++;
654
+ YYTOKEN += nl_len - 1;
655
+ }
656
+ }
657
+ if ( nl_count <= 1 )
658
+ {
659
+ QUOTECAT(qstr, qcapa, qidx, ' ');
660
+ }
661
+ else
662
+ {
663
+ int i;
664
+ for ( i = 0; i < nl_count - 1; i++ )
665
+ {
666
+ QUOTECAT(qstr, qcapa, qidx, '\n');
667
+ }
668
+ }
669
+
670
+ goto SingleQuote2;
671
+ }
672
+
673
+ "''" { QUOTECAT(qstr, qcapa, qidx, '\'');
674
+ goto SingleQuote2;
675
+ }
676
+
677
+ ( "'" | NULL ) { SyckLevel *lvl;
678
+ SyckNode *n = syck_alloc_str();
679
+ lvl = CURRENT_LEVEL();
680
+
681
+ if ( lvl->status == syck_lvl_str )
682
+ {
683
+ POP_LEVEL();
684
+ }
685
+ if ( ((SyckParser *)parser)->taguri_expansion == 1 )
686
+ {
687
+ n->type_id = syck_taguri( YAML_DOMAIN, "str", 3 );
688
+ }
689
+ else
690
+ {
691
+ n->type_id = syck_strndup( "str", 3 );
692
+ }
693
+ n->data.str->ptr = qstr;
694
+ n->data.str->len = qidx;
695
+ n->data.str->style = scalar_1quote;
696
+ sycklval->nodeData = n;
697
+ return YAML_PLAIN;
698
+ }
699
+
700
+ ANY { QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1));
701
+ goto SingleQuote2;
702
+ }
703
+
704
+ */
705
+
706
+ }
707
+
708
+
709
+ DoubleQuote:
710
+ {
711
+ int keep_nl = 1;
712
+ int qidx = 0;
713
+ int qcapa = 100;
714
+ char *qstr = S_ALLOC_N( char, qcapa );
715
+
716
+ DoubleQuote2:
717
+ YYTOKEN = YYCURSOR;
718
+
719
+
720
+ /*!re2c
721
+
722
+ YINDENT { int indt_len;
723
+ int nl_count = 0;
724
+ SyckLevel *lvl;
725
+ GOBBLE_UP_YAML_INDENT( indt_len, YYTOKEN );
726
+ lvl = CURRENT_LEVEL();
727
+
728
+ if ( lvl->status != syck_lvl_str )
729
+ {
730
+ ADD_LEVEL( indt_len, syck_lvl_str );
731
+ }
732
+ else if ( indt_len < lvl->spaces )
733
+ {
734
+ /* FIXME */
735
+ }
736
+
737
+ if ( keep_nl == 1 )
738
+ {
739
+ while ( YYTOKEN < YYCURSOR )
740
+ {
741
+ int nl_len = 0;
742
+ if ( nl_len = newline_len( YYTOKEN++ ) )
743
+ {
744
+ nl_count++;
745
+ YYTOKEN += nl_len - 1;
746
+ }
747
+ }
748
+ if ( nl_count <= 1 )
749
+ {
750
+ QUOTECAT(qstr, qcapa, qidx, ' ');
751
+ }
752
+ else
753
+ {
754
+ int i;
755
+ for ( i = 0; i < nl_count - 1; i++ )
756
+ {
757
+ QUOTECAT(qstr, qcapa, qidx, '\n');
758
+ }
759
+ }
760
+ }
761
+
762
+ keep_nl = 1;
763
+ goto DoubleQuote2;
764
+ }
765
+
766
+ "\\" ESCSEQ { char ch = *( YYCURSOR - 1 );
767
+ QUOTECAT(qstr, qcapa, qidx, escape_seq( ch ));
768
+ goto DoubleQuote2;
769
+ }
770
+
771
+ "\\x" HEX HEX { long ch;
772
+ char *chr_text = syck_strndup( YYTOKEN, 4 );
773
+ chr_text[0] = '0';
774
+ ch = strtol( chr_text, NULL, 16 );
775
+ free( chr_text );
776
+ QUOTECAT(qstr, qcapa, qidx, ch);
777
+ goto DoubleQuote2;
778
+ }
779
+
780
+ "\\" SPC* LF { keep_nl = 0;
781
+ YYCURSOR--;
782
+ goto DoubleQuote2;
783
+ }
784
+
785
+ ( "\"" | NULL ) { SyckLevel *lvl;
786
+ SyckNode *n = syck_alloc_str();
787
+ lvl = CURRENT_LEVEL();
788
+
789
+ if ( lvl->status == syck_lvl_str )
790
+ {
791
+ POP_LEVEL();
792
+ }
793
+ if ( ((SyckParser *)parser)->taguri_expansion == 1 )
794
+ {
795
+ n->type_id = syck_taguri( YAML_DOMAIN, "str", 3 );
796
+ }
797
+ else
798
+ {
799
+ n->type_id = syck_strndup( "str", 3 );
800
+ }
801
+ n->data.str->ptr = qstr;
802
+ n->data.str->len = qidx;
803
+ n->data.str->style = scalar_2quote;
804
+ sycklval->nodeData = n;
805
+ return YAML_PLAIN;
806
+ }
807
+
808
+ ANY { QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1));
809
+ goto DoubleQuote2;
810
+ }
811
+
812
+ */
813
+ }
814
+
815
+ TransferMethod:
816
+ {
817
+ int qidx = 0;
818
+ int qcapa = 100;
819
+ char *qstr = S_ALLOC_N( char, qcapa );
820
+
821
+ TransferMethod2:
822
+ YYTOKTMP = YYCURSOR;
823
+
824
+ /*!re2c
825
+
826
+ ( ENDSPC | NULL ) { SyckLevel *lvl;
827
+ YYCURSOR = YYTOKTMP;
828
+ if ( YYCURSOR == YYTOKEN + 1 )
829
+ {
830
+ free( qstr );
831
+ return YAML_ITRANSFER;
832
+ }
833
+
834
+ lvl = CURRENT_LEVEL();
835
+
836
+ /*
837
+ * URL Prefixing
838
+ */
839
+ if ( *qstr == '^' )
840
+ {
841
+ sycklval->name = S_ALLOC_N( char, qidx + strlen( lvl->domain ) );
842
+ sycklval->name[0] = '\0';
843
+ strcat( sycklval->name, lvl->domain );
844
+ strncat( sycklval->name, qstr + 1, qidx - 1 );
845
+ free( qstr );
846
+ }
847
+ else
848
+ {
849
+ char *carat = qstr;
850
+ char *qend = qstr + qidx;
851
+ while ( (++carat) < qend )
852
+ {
853
+ if ( *carat == '^' )
854
+ break;
855
+ }
856
+
857
+ if ( carat < qend )
858
+ {
859
+ free( lvl->domain );
860
+ lvl->domain = syck_strndup( qstr, carat - qstr );
861
+ sycklval->name = S_ALLOC_N( char, ( qend - carat ) + strlen( lvl->domain ) );
862
+ sycklval->name[0] = '\0';
863
+ strcat( sycklval->name, lvl->domain );
864
+ strncat( sycklval->name, carat + 1, ( qend - carat ) - 1 );
865
+ free( qstr );
866
+ }
867
+ else
868
+ {
869
+ sycklval->name = qstr;
870
+ }
871
+ }
872
+
873
+ return YAML_TRANSFER;
874
+ }
875
+
876
+ /*
877
+ * URL Escapes
878
+ */
879
+ "\\" ESCSEQ { char ch = *( YYCURSOR - 1 );
880
+ QUOTECAT(qstr, qcapa, qidx, escape_seq( ch ));
881
+ goto TransferMethod2;
882
+ }
883
+
884
+ "\\x" HEX HEX { long ch;
885
+ char *chr_text = syck_strndup( YYTOKTMP, 4 );
886
+ chr_text[0] = '0';
887
+ ch = strtol( chr_text, NULL, 16 );
888
+ free( chr_text );
889
+ QUOTECAT(qstr, qcapa, qidx, ch);
890
+ goto TransferMethod2;
891
+ }
892
+
893
+ ANY { QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1));
894
+ goto TransferMethod2;
895
+ }
896
+
897
+
898
+ */
899
+ }
900
+
901
+ ScalarBlock:
902
+ {
903
+ int qidx = 0;
904
+ int qcapa = 100;
905
+ char *qstr = S_ALLOC_N( char, qcapa );
906
+ int blockType = 0;
907
+ int nlDoWhat = 0;
908
+ int lastIndent = 0;
909
+ int forceIndent = -1;
910
+ char *yyt = YYTOKEN;
911
+ SyckLevel *lvl = CURRENT_LEVEL();
912
+ int parentIndent;
913
+ GET_TRUE_YAML_INDENT(parentIndent);
914
+
915
+ switch ( *yyt )
916
+ {
917
+ case '|': blockType = BLOCK_LIT; break;
918
+ case '>': blockType = BLOCK_FOLD; break;
919
+ }
920
+
921
+ while ( ++yyt <= YYCURSOR )
922
+ {
923
+ if ( *yyt == '-' )
924
+ {
925
+ nlDoWhat = NL_CHOMP;
926
+ }
927
+ else if ( *yyt == '+' )
928
+ {
929
+ nlDoWhat = NL_KEEP;
930
+ }
931
+ else if ( isdigit( *yyt ) )
932
+ {
933
+ forceIndent = strtol( yyt, NULL, 10 ) + parentIndent;
934
+ }
935
+ }
936
+
937
+ qstr[0] = '\0';
938
+ YYTOKEN = YYCURSOR;
939
+
940
+ ScalarBlock2:
941
+ YYTOKEN = YYCURSOR;
942
+
943
+ /*!re2c
944
+
945
+ YINDENT { char *pacer;
946
+ char *tok = YYTOKEN;
947
+ int indt_len = 0, nl_count = 0, fold_nl = 0, nl_begin = 0;
948
+ GOBBLE_UP_YAML_INDENT( indt_len, tok );
949
+ lvl = CURRENT_LEVEL();
950
+
951
+ if ( indt_len > parentIndent && lvl->status != syck_lvl_block )
952
+ {
953
+ int new_spaces = forceIndent > 0 ? forceIndent : indt_len;
954
+ ADD_LEVEL( new_spaces, syck_lvl_block );
955
+ lastIndent = indt_len - new_spaces;
956
+ nl_begin = 1;
957
+ lvl = CURRENT_LEVEL();
958
+ }
959
+ else if ( lvl->status != syck_lvl_block )
960
+ {
961
+ YYCURSOR = YYTOKEN;
962
+ RETURN_YAML_BLOCK();
963
+ }
964
+
965
+ /*
966
+ * Fold only in the event of two lines being on the leftmost
967
+ * indentation.
968
+ */
969
+ if ( blockType == BLOCK_FOLD && lastIndent == 0 && ( indt_len - lvl->spaces ) == 0 )
970
+ {
971
+ fold_nl = 1;
972
+ }
973
+
974
+ pacer = YYTOKEN;
975
+ while ( pacer < YYCURSOR )
976
+ {
977
+ int nl_len = 0;
978
+ if ( nl_len = newline_len( pacer++ ) )
979
+ {
980
+ nl_count++;
981
+ pacer += nl_len - 1;
982
+ }
983
+ }
984
+
985
+ if ( fold_nl == 1 || nl_begin == 1 )
986
+ {
987
+ nl_count--;
988
+ }
989
+
990
+ if ( nl_count < 1 && nl_begin == 0 )
991
+ {
992
+ QUOTECAT(qstr, qcapa, qidx, ' ');
993
+ }
994
+ else
995
+ {
996
+ int i;
997
+ for ( i = 0; i < nl_count; i++ )
998
+ {
999
+ QUOTECAT(qstr, qcapa, qidx, '\n');
1000
+ }
1001
+ }
1002
+
1003
+ lastIndent = indt_len - lvl->spaces;
1004
+ YYCURSOR -= lastIndent;
1005
+
1006
+ if ( indt_len < lvl->spaces )
1007
+ {
1008
+ POP_LEVEL();
1009
+ YYCURSOR = YYTOKEN;
1010
+ RETURN_YAML_BLOCK();
1011
+ }
1012
+ goto ScalarBlock2;
1013
+ }
1014
+
1015
+
1016
+ "#" { lvl = CURRENT_LEVEL();
1017
+ if ( lvl->status != syck_lvl_block )
1018
+ {
1019
+ eat_comments( parser );
1020
+ YYTOKEN = YYCURSOR;
1021
+ }
1022
+ else
1023
+ {
1024
+ QUOTECAT(qstr, qcapa, qidx, *YYTOKEN);
1025
+ }
1026
+ goto ScalarBlock2;
1027
+ }
1028
+
1029
+
1030
+ NULL { YYCURSOR--;
1031
+ POP_LEVEL();
1032
+ RETURN_YAML_BLOCK();
1033
+ }
1034
+
1035
+ "---" ENDSPC { if ( YYTOKEN == YYLINEPTR )
1036
+ {
1037
+ if ( blockType == BLOCK_FOLD && qidx > 0 )
1038
+ {
1039
+ qidx -= 1;
1040
+ }
1041
+ QUOTECAT(qstr, qcapa, qidx, '\n');
1042
+ POP_LEVEL();
1043
+ YYCURSOR = YYTOKEN;
1044
+ RETURN_YAML_BLOCK();
1045
+ }
1046
+ else
1047
+ {
1048
+ QUOTECAT(qstr, qcapa, qidx, *YYTOKEN);
1049
+ YYCURSOR = YYTOKEN + 1;
1050
+ goto ScalarBlock2;
1051
+ }
1052
+ }
1053
+
1054
+ ANY { QUOTECAT(qstr, qcapa, qidx, *YYTOKEN);
1055
+ goto ScalarBlock2;
1056
+ }
1057
+
1058
+
1059
+ */
1060
+ }
1061
+
1062
+ return 0;
1063
+
1064
+ }
1065
+
1066
+ void
1067
+ eat_comments( SyckParser *parser )
1068
+ {
1069
+ Comment:
1070
+ {
1071
+ YYTOKEN = YYCURSOR;
1072
+
1073
+ /*!re2c
1074
+
1075
+ ( LF+ | NULL ) { YYCURSOR = YYTOKEN;
1076
+ return;
1077
+ }
1078
+
1079
+ ANY { goto Comment;
1080
+ }
1081
+
1082
+ */
1083
+
1084
+ }
1085
+
1086
+ }
1087
+
1088
+ char
1089
+ escape_seq( char ch )
1090
+ {
1091
+ switch ( ch )
1092
+ {
1093
+ case '0': return '\0';
1094
+ case 'a': return 7;
1095
+ case 'b': return '\010';
1096
+ case 'e': return '\033';
1097
+ case 'f': return '\014';
1098
+ case 'n': return '\n';
1099
+ case 'r': return '\015';
1100
+ case 't': return '\t';
1101
+ case 'v': return '\013';
1102
+ default: return ch;
1103
+ }
1104
+ }
1105
+
1106
+ int
1107
+ is_newline( char *ptr )
1108
+ {
1109
+ return newline_len( ptr );
1110
+ }
1111
+
1112
+ int
1113
+ newline_len( char *ptr )
1114
+ {
1115
+ if ( *ptr == '\n' )
1116
+ return 1;
1117
+
1118
+ if ( *ptr == '\r' && *( ptr + 1 ) == '\n' )
1119
+ return 2;
1120
+
1121
+ return 0;
1122
+ }
1123
+
1124
+ int
1125
+ syckwrap()
1126
+ {
1127
+ return 1;
1128
+ }
1129
+
1130
+ void
1131
+ syckerror( char *msg )
1132
+ {
1133
+ if ( syck_parser_ptr->error_handler == NULL )
1134
+ syck_parser_ptr->error_handler = syck_default_error_handler;
1135
+
1136
+ syck_parser_ptr->root = syck_parser_ptr->root_on_error;
1137
+ (syck_parser_ptr->error_handler)(syck_parser_ptr, msg);
1138
+ }
1139
+