breakout_parser 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/breakout_parser/lex.yy.c +720 -648
- data/ext/breakout_parser/parser.l +12 -6
- data/ext/breakout_parser/parser.tab.c +274 -215
- data/ext/breakout_parser/parser.tab.h +39 -35
- data/ext/breakout_parser/parser.y +25 -0
- data/spec/parser_spec.rb +43 -10
- metadata +2 -2
@@ -42,40 +42,44 @@
|
|
42
42
|
T_CHAR = 258,
|
43
43
|
BOLD_START = 259,
|
44
44
|
ITALIC_START = 260,
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
45
|
+
BOLD_ITALIC_START = 261,
|
46
|
+
ITALIC_BOLD_START = 262,
|
47
|
+
T_WORD = 263,
|
48
|
+
TICKET_LINK = 264,
|
49
|
+
LINK = 265,
|
50
|
+
SVN_REVISION_LINK = 266,
|
51
|
+
GIT_REVISION_LINK = 267,
|
52
|
+
WIKI_LINK = 268,
|
53
|
+
ANCHOR_LINK = 269,
|
54
|
+
URL_WITH_PROTO_LINK = 270,
|
55
|
+
URL_WITHOUT_PROTO_LINK = 271,
|
56
|
+
FILE_LINK = 272,
|
57
|
+
IMAGE_LINK = 273,
|
58
|
+
URL = 274,
|
59
|
+
EMAIL = 275,
|
60
|
+
UL = 276,
|
61
|
+
H1 = 277,
|
62
|
+
H2 = 278,
|
63
|
+
H3 = 279,
|
64
|
+
H4 = 280,
|
65
|
+
H5 = 281,
|
66
|
+
INLINE_CODE = 282,
|
67
|
+
SPACE = 283,
|
68
|
+
BR = 284,
|
69
|
+
OLI = 285,
|
70
|
+
ULI = 286,
|
71
|
+
PRE_CODE_START = 287,
|
72
|
+
PRE_CODE_END = 288,
|
73
|
+
PRE_START = 289,
|
74
|
+
PRE_END = 290,
|
75
|
+
CODE_START = 291,
|
76
|
+
CODE_END = 292,
|
77
|
+
NOTEXTILE_START = 293,
|
78
|
+
NOTEXTILE_END = 294,
|
79
|
+
BOLD_END = 295,
|
80
|
+
ITALIC_END = 296,
|
81
|
+
REVERT_BOLD = 297,
|
82
|
+
REVERT_ITALIC = 298
|
79
83
|
};
|
80
84
|
#endif
|
81
85
|
|
@@ -95,7 +99,7 @@ typedef union YYSTYPE
|
|
95
99
|
|
96
100
|
|
97
101
|
/* Line 1676 of yacc.c */
|
98
|
-
#line
|
102
|
+
#line 103 "parser.tab.h"
|
99
103
|
} YYSTYPE;
|
100
104
|
# define YYSTYPE_IS_TRIVIAL 1
|
101
105
|
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
@@ -66,6 +66,7 @@ void yyerror(const char *msg)
|
|
66
66
|
|
67
67
|
|
68
68
|
%token <ivalue> T_CHAR BOLD_START ITALIC_START
|
69
|
+
%token <ivalue> BOLD_ITALIC_START ITALIC_BOLD_START
|
69
70
|
%token <svalue> T_WORD TICKET_LINK LINK SVN_REVISION_LINK GIT_REVISION_LINK WIKI_LINK ANCHOR_LINK
|
70
71
|
%token <svalue> URL_WITH_PROTO_LINK URL_WITHOUT_PROTO_LINK
|
71
72
|
%token <svalue> FILE_LINK IMAGE_LINK
|
@@ -77,6 +78,7 @@ void yyerror(const char *msg)
|
|
77
78
|
%token PRE_CODE_START PRE_CODE_END PRE_START PRE_END CODE_START CODE_END
|
78
79
|
%token NOTEXTILE_START NOTEXTILE_END
|
79
80
|
%token BOLD_END ITALIC_END
|
81
|
+
%token REVERT_BOLD REVERT_ITALIC
|
80
82
|
|
81
83
|
//%type <dvalue> expression
|
82
84
|
//%type <dvalue> term
|
@@ -121,7 +123,11 @@ word : chars
|
|
121
123
|
| BOLD_END {concat("</strong>",9)}
|
122
124
|
| ITALIC_START {$1 ? concat(" <em>",5) : concat("<em>",4)}
|
123
125
|
| ITALIC_END {concat("</em>",5)}
|
126
|
+
| BOLD_ITALIC_START {$1 ? concat(" <strong><em>",13) : concat("<strong><em>",12)}
|
127
|
+
| ITALIC_BOLD_START {$1 ? concat(" <em><strong>",13) : concat("<em><strong>",12)}
|
124
128
|
| INLINE_CODE {process_inline_code($1)}
|
129
|
+
| REVERT_BOLD {revert_bold()}
|
130
|
+
| REVERT_ITALIC {revert_italic()}
|
125
131
|
|
126
132
|
link: TICKET_LINK {process_ticket_link($1)}
|
127
133
|
| SVN_REVISION_LINK {process_svn_link($1)}
|
@@ -421,3 +427,22 @@ process_email(const char*url){
|
|
421
427
|
process_link_tail(url,NULL,NULL);
|
422
428
|
}
|
423
429
|
|
430
|
+
revert_bold(){
|
431
|
+
char *p;
|
432
|
+
for( p=bufptr-1; p >= (buf+7) ; p--){
|
433
|
+
if( 0 == strncmp(p-7, "<strong>", 8) ){
|
434
|
+
memcpy(p-7," *",8);
|
435
|
+
break;
|
436
|
+
}
|
437
|
+
}
|
438
|
+
}
|
439
|
+
|
440
|
+
revert_italic(){
|
441
|
+
char *p;
|
442
|
+
for( p=bufptr-1; p >= (buf+3) ; p--){
|
443
|
+
if( 0 == strncmp(p-3, "<em>", 4) ){
|
444
|
+
memcpy(p-3," _",4);
|
445
|
+
break;
|
446
|
+
}
|
447
|
+
}
|
448
|
+
}
|
data/spec/parser_spec.rb
CHANGED
@@ -114,6 +114,12 @@ describe 'BreakoutParser' do
|
|
114
114
|
parse(" @code1@ @code2@ ").should == "<code>code1</code> <code>code2</code>"
|
115
115
|
parse(" @code1@ xxx @code2@ ").should == "<code>code1</code> xxx <code>code2</code>"
|
116
116
|
end
|
117
|
+
%w', .'.each do |c|
|
118
|
+
it "stops on #{c.inspect}" do
|
119
|
+
parse("@some code@#{c}").should == "<code>some code</code>#{c}"
|
120
|
+
parse("@some code@#{c} @another code@").should == "<code>some code</code>#{c} <code>another code</code>"
|
121
|
+
end
|
122
|
+
end
|
117
123
|
end
|
118
124
|
|
119
125
|
###############################################################################
|
@@ -138,13 +144,13 @@ describe 'BreakoutParser' do
|
|
138
144
|
parse("aaa * bbb").should == 'aaa * bbb'
|
139
145
|
end
|
140
146
|
it "w/o closing tag" do
|
141
|
-
parse("*bold").should == '
|
147
|
+
parse("*bold").should == '*bold'
|
142
148
|
end
|
143
149
|
it "nesting1 w/o closing tags" do
|
144
|
-
parse("*bold1 *bold2").should == '
|
150
|
+
parse("*bold1 *bold2").gsub(/ +/,' ').should == '*bold1 *bold2'
|
145
151
|
end
|
146
152
|
it "nesting2 w/o closing tags" do
|
147
|
-
parse("*bold1 *bold2").should == '
|
153
|
+
parse("*bold1 *bold2").gsub(/ +/,' ').should == '*bold1 *bold2'
|
148
154
|
end
|
149
155
|
|
150
156
|
it "not parses '*.*'" do
|
@@ -183,30 +189,57 @@ describe 'BreakoutParser' do
|
|
183
189
|
parse("aaa _ bbb").should == 'aaa _ bbb'
|
184
190
|
end
|
185
191
|
it "w/o closing tag" do
|
186
|
-
parse("_italic").should == '
|
192
|
+
parse("_italic").should == '_italic'
|
187
193
|
end
|
188
194
|
it "nesting1 w/o closing tags" do
|
189
|
-
parse("_italic1 _italic2").should == '
|
195
|
+
parse("_italic1 _italic2").gsub(/ +/,' ').should == '_italic1 _italic2'
|
190
196
|
end
|
191
197
|
it "nesting2 w/o closing tags" do
|
192
|
-
parse("_italic1 _italic2").should == '
|
198
|
+
parse("_italic1 _italic2").gsub(/ +/,' ').should == '_italic1 _italic2'
|
193
199
|
end
|
194
200
|
end
|
195
201
|
|
196
202
|
###############################################################################
|
197
203
|
|
198
204
|
describe "combinations" do
|
205
|
+
it "both bold and italic" do
|
206
|
+
s = "_*aaa bbb ccc*_"
|
207
|
+
parse(s).should == "<em><strong>aaa bbb ccc</strong></em>"
|
208
|
+
end
|
209
|
+
it "both italic and bold" do
|
210
|
+
s = "*_aaa bbb ccc_*"
|
211
|
+
parse(s).should == "<strong><em>aaa bbb ccc</em></strong>"
|
212
|
+
end
|
213
|
+
|
214
|
+
it "start b+i, end first italic then bold" do
|
215
|
+
s = "*_aaa bbb_ ccc*"
|
216
|
+
parse(s).should == "<strong><em>aaa bbb</em> ccc</strong>"
|
217
|
+
end
|
218
|
+
it "start i+b, end first bold then italic" do
|
219
|
+
s = "_*aaa bbb* ccc_"
|
220
|
+
parse(s).should == "<em><strong>aaa bbb</strong> ccc</em>"
|
221
|
+
end
|
222
|
+
|
223
|
+
it "start first italic then bold, end both" do
|
224
|
+
s = "_aaa *bbb ccc*_"
|
225
|
+
parse(s).should == "<em>aaa <strong>bbb ccc</strong></em>"
|
226
|
+
end
|
227
|
+
it "start first bold then italic, end both" do
|
228
|
+
s = "*aaa _bbb ccc_*"
|
229
|
+
parse(s).should == "<strong>aaa <em>bbb ccc</em></strong>"
|
230
|
+
end
|
231
|
+
|
199
232
|
it "bold in italic" do
|
200
233
|
s = "_aaa *bbb* ccc_"
|
201
234
|
parse(s).should == "<em>aaa <strong>bbb</strong> ccc</em>"
|
202
235
|
end
|
203
236
|
it "bold in italic - no closing1" do
|
204
237
|
s = "_aaa *bbb* ccc"
|
205
|
-
parse(s).should == "
|
238
|
+
parse(s).should == "_aaa <strong>bbb</strong> ccc"
|
206
239
|
end
|
207
240
|
it "bold in italic - no closing2" do
|
208
241
|
s = "_aaa *bbb ccc"
|
209
|
-
parse(s).should == "
|
242
|
+
parse(s).gsub(/ {2,}/,' ').should == "_aaa *bbb ccc"
|
210
243
|
end
|
211
244
|
|
212
245
|
it "italic in bold" do
|
@@ -215,11 +248,11 @@ describe 'BreakoutParser' do
|
|
215
248
|
end
|
216
249
|
it "italic in bold - no closing1" do
|
217
250
|
s = "*aaa _bbb_ ccc"
|
218
|
-
parse(s).should == "
|
251
|
+
parse(s).should == "*aaa <em>bbb</em> ccc"
|
219
252
|
end
|
220
253
|
it "italic in bold - no closing2" do
|
221
254
|
s = "*aaa _bbb ccc"
|
222
|
-
parse(s).should == "
|
255
|
+
parse(s).gsub(/ {2,}/,' ').should == "*aaa _bbb ccc"
|
223
256
|
end
|
224
257
|
|
225
258
|
{'ul' => '*', 'ol' => '#'}.each do |l,c|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: breakout_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey "Zed" Zaikin
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-03-
|
12
|
+
date: 2010-03-28 00:00:00 +05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|