breakout_parser 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -60,18 +60,19 @@
60
60
  H3 = 276,
61
61
  H4 = 277,
62
62
  H5 = 278,
63
- SPACE = 279,
64
- BR = 280,
65
- OLI = 281,
66
- ULI = 282,
67
- PRE_CODE_START = 283,
68
- PRE_CODE_END = 284,
69
- PRE_START = 285,
70
- PRE_END = 286,
71
- CODE_START = 287,
72
- CODE_END = 288,
73
- BOLD_END = 289,
74
- ITALIC_END = 290
63
+ INLINE_CODE = 279,
64
+ SPACE = 280,
65
+ BR = 281,
66
+ OLI = 282,
67
+ ULI = 283,
68
+ PRE_CODE_START = 284,
69
+ PRE_CODE_END = 285,
70
+ PRE_START = 286,
71
+ PRE_END = 287,
72
+ CODE_START = 288,
73
+ CODE_END = 289,
74
+ BOLD_END = 290,
75
+ ITALIC_END = 291
75
76
  };
76
77
  #endif
77
78
 
@@ -91,7 +92,7 @@ typedef union YYSTYPE
91
92
 
92
93
 
93
94
  /* Line 1676 of yacc.c */
94
- #line 95 "parser.tab.h"
95
+ #line 96 "parser.tab.h"
95
96
  } YYSTYPE;
96
97
  # define YYSTYPE_IS_TRIVIAL 1
97
98
  # define yystype YYSTYPE /* obsolescent; will be withdrawn */
@@ -72,6 +72,7 @@ void yyerror(const char *msg)
72
72
  %token <svalue> URL
73
73
  %token <svalue> UL
74
74
  %token <svalue> H1 H2 H3 H4 H5
75
+ %token <svalue> INLINE_CODE
75
76
  %token SPACE BR /*BRBR*/ OLI ULI
76
77
  %token PRE_CODE_START PRE_CODE_END PRE_START PRE_END CODE_START CODE_END
77
78
  %token BOLD_END ITALIC_END
@@ -112,12 +113,13 @@ words: word
112
113
 
113
114
  word : chars
114
115
  | link
115
- | T_WORD {concat2($1)} // TODO: somehow pass T_WORD's length here
116
+ | T_WORD {concat2($1)} // TODO: somehow pass T_WORD's length here
116
117
  | URL {process_url($1)}
117
118
  | BOLD_START {$1 ? concat(" <strong>",9) : concat("<strong>",8)}
118
119
  | BOLD_END {concat("</strong>",9)}
119
120
  | ITALIC_START {$1 ? concat(" <em>",5) : concat("<em>",4)}
120
121
  | ITALIC_END {concat("</em>",5)}
122
+ | INLINE_CODE {process_inline_code($1)}
121
123
 
122
124
  link: TICKET_LINK {process_ticket_link($1)}
123
125
  | SVN_REVISION_LINK {process_svn_link($1)}
@@ -186,6 +188,20 @@ need_hex_convert(const char*p, const char*pend){
186
188
  return 0;
187
189
  }
188
190
 
191
+ process_inline_code(const char*p){
192
+ if( *p == ' ' || *p == 9 ){
193
+ concat_raw_char(' ');
194
+ while( *p == ' ' || *p == 9 ) p++;
195
+ }
196
+ if( *p == '@' ) p++;
197
+ concat("<code>",6);
198
+ for(; *p ; p++){
199
+ if( *p == '@' && *(p+1) == 0 ) break;
200
+ concat_escaped_char( *p );
201
+ }
202
+ concat("</code>",7);
203
+ }
204
+
189
205
  process_header(const char*title){
190
206
  const char*p,*pend;
191
207
 
@@ -19,8 +19,21 @@ extern size_t in_buf_len, bufsize, space_name_len;
19
19
 
20
20
  VALUE method_parse(VALUE self, VALUE text, VALUE r_space_name) {
21
21
  VALUE s;
22
- char *p = RSTRING(text)->ptr;
22
+ char *p;
23
+
24
+ if(!text || text == Qnil || text == Qfalse){
25
+ // NULL input string
26
+ return rb_str_new("",0);
27
+ }
28
+
29
+ p = RSTRING(text)->ptr;
23
30
  in_buf_len = RSTRING(text)->len;
31
+
32
+ if(!p || in_buf_len <= 0){
33
+ // empty input string
34
+ return rb_str_new("",0);
35
+ }
36
+
24
37
  while( in_buf_len > 0 && (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')){
25
38
  p++;
26
39
  in_buf_len--;
data/spec/parser_spec.rb CHANGED
@@ -29,6 +29,27 @@ describe 'BreakoutParser' do
29
29
  parse(s).size.should == s.strip.size
30
30
  end
31
31
 
32
+ it "handles nil & false text well" do
33
+ parse(false).should == ""
34
+ parse(false,false).should == ""
35
+ parse("",false).should == ""
36
+ parse(nil).should == ""
37
+ parse(nil,nil).should == ""
38
+ parse("",nil).should == ""
39
+ end
40
+
41
+ it "handles nil space_name well" do
42
+ lambda{
43
+ parse("#123",nil)
44
+ }.should raise_error(TypeError)
45
+ end
46
+
47
+ it "handles false space_name well" do
48
+ lambda{
49
+ parse("#123",false)
50
+ }.should raise_error(TypeError)
51
+ end
52
+
32
53
  it "strips tailing spaces and newlines" do
33
54
  parse("aaa ").should == "aaa"
34
55
  parse("aaa\t\t\t\t\t\t").should == "aaa"
@@ -59,6 +80,42 @@ describe 'BreakoutParser' do
59
80
  parse("aaa\r\n\r\n\r\nbbb").should == "aaa" + "<br />"*3 + "bbb"
60
81
  end
61
82
 
83
+ ###############################################################################
84
+
85
+ describe "@code@" do
86
+ it "only" do
87
+ parse("@smth@").should == '<code>smth</code>'
88
+ end
89
+ it "at beginning" do
90
+ parse("@smth@\nxxx").should == '<code>smth</code><br />xxx'
91
+ end
92
+ it "in the middle of text" do
93
+ parse("xxx @smth@ yyy").should == 'xxx <code>smth</code> yyy'
94
+ end
95
+ it "parses @multiline\\nsmth@" do
96
+ parse("@multiline\nsmth@").should == "@multiline<br />smth@"
97
+ end
98
+ it "not confuses" do
99
+ parse("look at @this code@ and mail me at xxx@yyy.com").should ==
100
+ 'look at <code>this code</code> and mail me at xxx@yyy.com'
101
+ end
102
+ it "w/o closing tag" do
103
+ parse("@smth").should == '@smth'
104
+ end
105
+ it "nesting1 w/o closing tags" do
106
+ parse("@smth1 @smth2").should == '@smth1 @smth2'
107
+ end
108
+ it "nesting2 w/o closing tags" do
109
+ parse("@smth1 @smth2").should == '@smth1 @smth2'
110
+ end
111
+ it "two times" do
112
+ parse("@code1@ @code2@").should == "<code>code1</code> <code>code2</code>"
113
+ parse("@code1@ @code2@").should == "<code>code1</code> <code>code2</code>"
114
+ parse(" @code1@ @code2@ ").should == "<code>code1</code> <code>code2</code>"
115
+ parse(" @code1@ xxx @code2@ ").should == "<code>code1</code> xxx <code>code2</code>"
116
+ end
117
+ end
118
+
62
119
  ###############################################################################
63
120
 
64
121
  describe "*bold*" do
@@ -662,7 +719,7 @@ describe 'BreakoutParser' do
662
719
  s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }
663
720
  end
664
721
 
665
- def parse s
666
- BreakoutParser.parse(s, "test_space").strip
722
+ def parse s, space_name = "test_space"
723
+ BreakoutParser.parse(s, space_name).strip
667
724
  end
668
725
  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.5
4
+ version: 0.0.6
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-02-05 00:00:00 +05:00
12
+ date: 2010-02-25 00:00:00 +05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency