eleanor 1.0.0

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.
@@ -0,0 +1,166 @@
1
+ # Copyright (c) 2008 chiisaitsu <chiisaitsu@gmail.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+ #
21
+ # ---
22
+ #
23
+ # This is Eleanor's parser. Its job is to define the private Screenplay#parse_!
24
+ # method, which takes the name of a plain text screenplay file.
25
+ #
26
+ # This implementation uses Ragel[http://research.cs.queensu.ca/~thurston/ragel/],
27
+ # a state machine compiler. Run it through Ragel with:
28
+ #
29
+ # ragel -R -o lib/eleanor/parser.rb src/ragel/parser.rl
30
+
31
+ =begin
32
+ # This is commented out so rdoc doesn't barf. Ragel doesn't mind.
33
+
34
+ %%{
35
+
36
+ machine parser;
37
+
38
+ char = any - space ;
39
+ hspace = [ \t] ;
40
+ schar = char | hspace ;
41
+ nline = '\r\n' | '\n' ;
42
+ trailer = hspace* nline ;
43
+
44
+ aktion = (char schar* nline trailer)
45
+ @{ classes= [Action]; consume= true }
46
+ @err{ error.call('Action') };
47
+
48
+ character_cue = hspace+ schar+ nline
49
+ @{ classes << CharacterCue }
50
+ @err{ error.call('Action') };
51
+
52
+ dialog = (hspace+ (char - '(') schar* nline)
53
+ @{ classes << Dialog }
54
+ @err{ error.call('Dialog') };
55
+
56
+ insert = (hspace+ schar+ nline trailer)
57
+ @{ classes= [Insert]; consume= true }
58
+ @err{ error.call('Insert') };
59
+
60
+ montage_item = ([A-Z] ') ' schar* nline trailer)
61
+ @{ classes= [MontageItem]; consume= true }
62
+ @err{ error.call('MontageItem') };
63
+
64
+ montage_heading = (('MONTAGE' | 'SERIES OF SHOTS') schar* nline trailer)
65
+ @{ classes= [MontageHeading]; consume= true }
66
+ @err{ error.call('MontageHeading') };
67
+
68
+ parenthetical = (hspace+ '(' schar+ ')' trailer)
69
+ @{ classes << Parenthetical }
70
+ @err{ error.call('Parenthetical') };
71
+
72
+ scene_heading = (char schar* nline trailer)
73
+ @{ classes= [SceneHeading]; consume= true }
74
+ @err{ error.call('SceneHeading') };
75
+
76
+ slug_line = ([A-Z] [A-Z0-9!-/:-@[-`{-~ ]* trailer trailer)
77
+ @{ classes= [SlugLine]; consume= true }
78
+ @err{ error.call('SlugLine') };
79
+
80
+ transition = (hspace+ [A-Z] ([A-Z ]* [A-Z])? [:.] trailer trailer)
81
+ @{ classes= [Transition]; consume= true }
82
+ @err{ error.call('Transition') };
83
+
84
+ tp_line = hspace+ char schar* nline ;
85
+
86
+ title_page = (tp_line (tp_line tp_line*)? trailer+)
87
+ @{ classes= [TitlePage]; consume= true }
88
+ @err{ error.call('TitlePage') };
89
+
90
+ character = (character_cue (dialog | (dialog? (parenthetical dialog)+))
91
+ trailer)
92
+ >{ classes= [] }
93
+ @{ consume= true } ;
94
+
95
+ montage = montage_heading montage_item+ transition? trailer+ ;
96
+
97
+ scene = scene_heading aktion (aktion | character | slug_line | insert)*
98
+ transition? trailer+ ;
99
+
100
+ main := trailer* title_page* (transition trailer*)? (scene | montage)* ;
101
+
102
+ write data;
103
+
104
+ }%%
105
+ =end
106
+
107
+ module Eleanor
108
+
109
+ class Screenplay
110
+
111
+ def parse_! filename
112
+ lines= []
113
+ last_char_cue= nil
114
+ classes= nil
115
+ # these are needed by ragel
116
+ data= ''
117
+ eof= nil
118
+ %% write data;
119
+ %% write init;
120
+ File.open(filename, 'r') do |file|
121
+ file.each_line do |line|
122
+ line << "\n" * 3 if file.eof?
123
+ error= lambda do |expected|
124
+ warn "#{filename}:#{file.lineno}: parse error: expected #{expected}:"
125
+ warn " #{@paras[-2]}" if @paras.length >= 2
126
+ warn " #{@paras[-1]}" if @paras.length >= 1
127
+ warn " #{line.inspect}"
128
+ end
129
+ consume= false
130
+ # these are needed by ragel
131
+ data= line
132
+ p= 0
133
+ pe= data.length
134
+ %% write exec;
135
+ # collect lines until consume is set, i.e., we've seen a full
136
+ # paragraph, in which case classes is non-nil
137
+ lines << line
138
+ if consume
139
+ lines= lines.map { |l| l.strip }.reject { |l| l.empty? }
140
+ unless lines.empty?
141
+ if classes[0] == TitlePage
142
+ @title_pages << TitlePage.new(:title => lines[0],
143
+ :author => lines[1],
144
+ :contact => lines[2..-1])
145
+ else
146
+ lines.each_with_index do |line, i|
147
+ @paras << classes[i].new(self, line, last_char_cue)
148
+ # remember the last character cue in the current scene
149
+ if classes[i] == CharacterCue
150
+ last_char_cue= @paras.last
151
+ elsif classes[i] == SceneHeading
152
+ last_char_cue= nil
153
+ end
154
+ end
155
+ end
156
+ end
157
+ lines= []
158
+ end
159
+ end
160
+ end
161
+ cs < parser_first_final ? nil : @paras
162
+ end
163
+
164
+ end
165
+
166
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eleanor
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ""
6
+ authors:
7
+ - chiisaitsu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-05 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Eleanor is a Ruby script and accompanying library for formatting speculative screenplays. It parses plain text written in a simple format and outputs pretty PDF that conforms to standard rules of screenplay layout. Eleanor's primary goal is to create PDF that is indistinguishable from PDF produced by professional screenwriting software such as Final Draft.
17
+ email: chiisaitsu@gmail.com
18
+ executables:
19
+ - eleanor
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - CHANGELOG
24
+ - INSTALL
25
+ - LICENSE
26
+ - README
27
+ - src/ragel/parser.rl
28
+ files:
29
+ - CHANGELOG
30
+ - INSTALL
31
+ - LICENSE
32
+ - README
33
+ - Rakefile
34
+ - setup.rb
35
+ - bin/eleanor
36
+ - data/eleanor
37
+ - data/eleanor/eleanor.yaml
38
+ - examples/example.txt
39
+ - lib/eleanor
40
+ - lib/eleanor.rb
41
+ - lib/eleanor/hpdfpaper.rb
42
+ - lib/eleanor/length.rb
43
+ - lib/eleanor/parser.rb
44
+ - src/ragel
45
+ - src/ragel/parser.rl
46
+ has_rdoc: true
47
+ homepage: http://rubyforge.org/projects/eleanor
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --inline-source
51
+ - --extension
52
+ - rl=rb
53
+ - --exclude
54
+ - lib/eleanor/parser.rb
55
+ - --title
56
+ - Eleanor 1.0.0 Reference
57
+ - --main
58
+ - README
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ requirements:
74
+ - "libHaru Free PDF Library: http://libharu.org"
75
+ rubyforge_project: eleanor
76
+ rubygems_version: 0.9.5
77
+ signing_key:
78
+ specification_version: 2
79
+ summary: Formats speculative screenplays
80
+ test_files: []
81
+