breakout_parser 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/breakout_parser/lex.yy.c +517 -469
- data/ext/breakout_parser/parser.l +6 -1
- data/ext/breakout_parser/parser.tab.c +150 -145
- data/ext/breakout_parser/parser.tab.h +5 -3
- data/ext/breakout_parser/parser.y +2 -0
- data/spec/parser_spec.rb +31 -26
- metadata +2 -2
@@ -71,8 +71,10 @@
|
|
71
71
|
PRE_END = 287,
|
72
72
|
CODE_START = 288,
|
73
73
|
CODE_END = 289,
|
74
|
-
|
75
|
-
|
74
|
+
NOTEXTILE_START = 290,
|
75
|
+
NOTEXTILE_END = 291,
|
76
|
+
BOLD_END = 292,
|
77
|
+
ITALIC_END = 293
|
76
78
|
};
|
77
79
|
#endif
|
78
80
|
|
@@ -92,7 +94,7 @@ typedef union YYSTYPE
|
|
92
94
|
|
93
95
|
|
94
96
|
/* Line 1676 of yacc.c */
|
95
|
-
#line
|
97
|
+
#line 98 "parser.tab.h"
|
96
98
|
} YYSTYPE;
|
97
99
|
# define YYSTYPE_IS_TRIVIAL 1
|
98
100
|
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
@@ -75,6 +75,7 @@ void yyerror(const char *msg)
|
|
75
75
|
%token <svalue> INLINE_CODE
|
76
76
|
%token SPACE BR /*BRBR*/ OLI ULI
|
77
77
|
%token PRE_CODE_START PRE_CODE_END PRE_START PRE_END CODE_START CODE_END
|
78
|
+
%token NOTEXTILE_START NOTEXTILE_END
|
78
79
|
%token BOLD_END ITALIC_END
|
79
80
|
|
80
81
|
//%type <dvalue> expression
|
@@ -153,6 +154,7 @@ br : BR {concat("<br />",6)}
|
|
153
154
|
// | BRBR {concat("<br /><br />",12)}
|
154
155
|
|
155
156
|
code : PRE_CODE_START {concat("<pre><code>",11)} chars PRE_CODE_END {concat("</code></pre>",13)}
|
157
|
+
| NOTEXTILE_START chars NOTEXTILE_END
|
156
158
|
| PRE_START {concat("<pre>",5)} chars PRE_END {concat("</pre>",6)}
|
157
159
|
| CODE_START {concat("<code>",6)} chars CODE_END {concat("</code>",7)}
|
158
160
|
|
data/spec/parser_spec.rb
CHANGED
@@ -429,11 +429,18 @@ describe 'BreakoutParser' do
|
|
429
429
|
|
430
430
|
[
|
431
431
|
%w'<pre><code> </code></pre>',
|
432
|
-
%w'<pre> </pre>'
|
432
|
+
%w'<pre> </pre>',
|
433
|
+
%w'<notextile> </notextile>'
|
433
434
|
].each do |ot,ct|
|
434
435
|
# ot - opening tag
|
435
436
|
# ct - closing tag
|
436
437
|
|
438
|
+
if ot == '<notextile>'
|
439
|
+
ote,cte = '',''
|
440
|
+
else
|
441
|
+
ote,cte = ot,ct
|
442
|
+
end
|
443
|
+
|
437
444
|
describe "#{ot}..#{ct}" do
|
438
445
|
it "works" do
|
439
446
|
s = <<-EOF
|
@@ -443,8 +450,7 @@ describe 'BreakoutParser' do
|
|
443
450
|
|
444
451
|
EOF
|
445
452
|
|
446
|
-
parse("#{ot}#{s.strip}#{ct}").should ==
|
447
|
-
"#{ot}#{h(s.strip)}#{ct}"
|
453
|
+
parse("#{ot}#{s.strip}#{ct}").should == "#{ote}#{h(s.strip)}#{cte}"
|
448
454
|
|
449
455
|
s = <<-EOF
|
450
456
|
while ( 1 < 2 ) do
|
@@ -458,71 +464,70 @@ describe 'BreakoutParser' do
|
|
458
464
|
* ccc
|
459
465
|
|
460
466
|
EOF
|
461
|
-
parse("#{ot}#{s.strip}#{ct}").should ==
|
462
|
-
"#{ot}#{h(s.strip)}#{ct}"
|
467
|
+
parse("#{ot}#{s.strip}#{ct}").should == "#{ote}#{h(s.strip)}#{cte}"
|
463
468
|
end
|
464
469
|
it "not parses *bold*" do
|
465
470
|
s = "#{ot} *bold*#{ct}"
|
466
|
-
parse(s).should == s
|
471
|
+
parse(s).should == s.gsub(ot,ote).gsub(ct,cte).strip
|
467
472
|
end
|
468
473
|
it "not parses _italic_" do
|
469
474
|
s = "#{ot} _italic_#{ct}"
|
470
|
-
parse(s).should == s
|
475
|
+
parse(s).should == s.gsub(ot,ote).gsub(ct,cte).strip
|
471
476
|
end
|
472
477
|
it "not parses UL lists" do
|
473
478
|
s = "#{ot}\n * l1\n * l2\n * l3#{ct}"
|
474
|
-
parse(s).should == s.sub(">\n",">")
|
479
|
+
parse(s).should == s.sub(">\n",">").gsub(ot,ote).gsub(ct,cte).strip
|
475
480
|
end
|
476
481
|
it "not parses OL lists" do
|
477
482
|
s = "#{ot}\n # l1\n # l2\n # l3#{ct}"
|
478
|
-
parse(s).should == s.sub(">\n",">")
|
483
|
+
parse(s).should == s.sub(">\n",">").gsub(ot,ote).gsub(ct,cte).strip
|
479
484
|
end
|
480
485
|
it "not parses H1..H5" do
|
481
486
|
1.upto(5) do |i|
|
482
487
|
s = "#{ot}\nh#{i}. zzzzzzz\n#{ct}"
|
483
|
-
parse(s).should == "#{
|
488
|
+
parse(s).should == "#{ote}h#{i}. zzzzzzz#{cte}"
|
484
489
|
end
|
485
490
|
end
|
486
491
|
it "not parses raw text links" do
|
487
492
|
s = "#{ot}xxx http://www.ru yyy#{ct}"
|
488
|
-
parse(s).should == s
|
493
|
+
parse(s).should == s.gsub(ot,ote).gsub(ct,cte)
|
489
494
|
s = "#{ot}http://www.ru#{ct}"
|
490
|
-
parse(s).should == s
|
495
|
+
parse(s).should == s.gsub(ot,ote).gsub(ct,cte)
|
491
496
|
end
|
492
497
|
it "keeps newlines" do
|
493
498
|
s = "#{ot}aaa\nbbb#{ct}"
|
494
|
-
parse(s).should == s
|
499
|
+
parse(s).should == s.gsub(ot,ote).gsub(ct,cte)
|
495
500
|
s = "#{ot}aaa\n\nbbb\nccc#{ct}"
|
496
|
-
parse(s).should == s
|
501
|
+
parse(s).should == s.gsub(ot,ote).gsub(ct,cte)
|
497
502
|
end
|
498
503
|
|
499
504
|
it "w/o closing tags" do
|
500
505
|
s = "#{ot}aaa"
|
501
|
-
parse(s).should match(%r"#{
|
506
|
+
parse(s).should match(%r"#{ote}aaa\n?#{cte}")
|
502
507
|
end
|
503
508
|
|
504
509
|
it "in middle of text" do
|
505
510
|
s = "xxx #{ot}yyyy#{ct} jjj"
|
506
|
-
parse(s).should == s
|
511
|
+
parse(s).should == s.gsub(ot,ote).gsub(ct,cte)
|
507
512
|
end
|
508
513
|
|
509
514
|
it "with 2 instances" do
|
510
515
|
s = "xxx #{ot}yyyy#{ct} <jjj> #{ot}asdkjaslkd#{ct} END"
|
511
|
-
parse(s).should == s.sub('<jjj>','<jjj>')
|
516
|
+
parse(s).should == s.sub('<jjj>','<jjj>').gsub(ot,ote).gsub(ct,cte)
|
512
517
|
end
|
513
518
|
|
514
519
|
it "works with unicode" do
|
515
520
|
s = "привет #{ot} жжж #{ct} пока!"
|
516
|
-
parse(s).should match(%r|привет ?#{
|
521
|
+
parse(s).should match(%r|привет ?#{ote} жжж#{cte} ?пока!|)
|
517
522
|
|
518
|
-
s =
|
519
|
-
parse(s).should == s
|
523
|
+
s = "#{ot}абвгдеёжзийклмнопрстуфхцчшщьыъэюя#{ct}"
|
524
|
+
parse(s).should == s.gsub(ot,ote).gsub(ct,cte)
|
520
525
|
|
521
|
-
s =
|
522
|
-
parse(s).should == s
|
526
|
+
s = "#{ot}АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЬЫЪЭЮЯ#{ct}"
|
527
|
+
parse(s).should == s.gsub(ot,ote).gsub(ct,cte)
|
523
528
|
|
524
|
-
s =
|
525
|
-
parse(s).should == s
|
529
|
+
s = "#{ot}☸☹☺☻☼☽☾☿#{ct}"
|
530
|
+
parse(s).should == s.gsub(ot,ote).gsub(ct,cte)
|
526
531
|
end
|
527
532
|
|
528
533
|
it "should escape lone closing tags" do
|
@@ -532,12 +537,12 @@ describe 'BreakoutParser' do
|
|
532
537
|
|
533
538
|
it "should skip newlines and spaces at end" do
|
534
539
|
s = "#{ot} aaa bbb ccc \n\n\n \t\n\n\n\r\n\r\n \t #{ct}"
|
535
|
-
parse(s).should == "#{
|
540
|
+
parse(s).should == "#{ote} aaa bbb ccc#{cte}".strip
|
536
541
|
end
|
537
542
|
|
538
543
|
it "escapes html chars" do
|
539
544
|
HTML_ESCAPE.each do |k,v|
|
540
|
-
parse("#{ot}#{k}#{ct}").should == "#{
|
545
|
+
parse("#{ot}#{k}#{ct}").should == "#{ote}#{v}#{cte}"
|
541
546
|
end
|
542
547
|
end
|
543
548
|
end
|
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.7
|
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-
|
12
|
+
date: 2010-03-09 00:00:00 +05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|