ss_syntax 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +16 -0
- data/README.md +68 -0
- data/bin/sssy +6 -0
- data/example/example.rb +8 -0
- data/example/example.ss +10 -0
- data/lib/ss_syntax/command_builder.rb +34 -0
- data/lib/ss_syntax/parse.rb +75 -0
- data/lib/ss_syntax/parses/character.rb +19 -0
- data/lib/ss_syntax/parses/comment.rb +14 -0
- data/lib/ss_syntax/parses/heart_voice.rb +21 -0
- data/lib/ss_syntax/parses/none.rb +13 -0
- data/lib/ss_syntax/parses/remark.rb +21 -0
- data/lib/ss_syntax/parses/type.rb +10 -0
- data/lib/ss_syntax/version.rb +3 -0
- data/lib/ss_syntax.rb +24 -0
- data/ss_syntax.gemspec +19 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5a21295288305597b7d7f978ecde67b7cdad3744
|
4
|
+
data.tar.gz: a3acc7ad07484996d309abe79275377427da853b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e525943492a19c196a238970697865a7a328c0ed909a26bc6766d3ee48e3e5887e2e48c80ec14b616649100ceaa9c2ac7b4b4108eb0cadf09929f8b40524710
|
7
|
+
data.tar.gz: 07bbcee5b069036aaf44cbd0f04f6f2a082a4c68e875d3f9cf3eac01ed0bf463c4564f78428db46254d3bbdcf745df058a00bfa2c2a165f2330240fc66b9d52b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# ss記法
|
2
|
+
|
3
|
+
## 使い方
|
4
|
+
|
5
|
+
```sh
|
6
|
+
$ sssy example/example.ss // default -t
|
7
|
+
$ sssy --html example/example.ss // puts html
|
8
|
+
```
|
9
|
+
|
10
|
+
or
|
11
|
+
|
12
|
+
```rb
|
13
|
+
require 'ss_syntax'
|
14
|
+
|
15
|
+
text = SsSyntax::SsSyntax.new(src).parse() # default :text
|
16
|
+
html = SsSyntax::SsSyntax.new(src, :html).parse()
|
17
|
+
```
|
18
|
+
|
19
|
+
## 各記法
|
20
|
+
|
21
|
+
### 登場人物名ショートカット
|
22
|
+
|
23
|
+
```
|
24
|
+
# * [ショートカット名] [名前]
|
25
|
+
# - [ショートカット名] [名前]
|
26
|
+
# これは本文には反映されない
|
27
|
+
|
28
|
+
* 1 男
|
29
|
+
* 2 女
|
30
|
+
- osana 幼 # 数字じゃなくてもいい
|
31
|
+
```
|
32
|
+
|
33
|
+
### 発言
|
34
|
+
|
35
|
+
```
|
36
|
+
* 1 男
|
37
|
+
|
38
|
+
# 以下はどちらも同じ結果になる
|
39
|
+
男: 今日は眠い
|
40
|
+
1: 今日は眠い
|
41
|
+
|
42
|
+
# 結果
|
43
|
+
# 男「今日は眠い」
|
44
|
+
```
|
45
|
+
|
46
|
+
### 心の声
|
47
|
+
|
48
|
+
```
|
49
|
+
* 1 男
|
50
|
+
|
51
|
+
1_ 女は今日も可愛いなぁ
|
52
|
+
|
53
|
+
# 結果
|
54
|
+
# 男(女は今日も可愛いなぁ)
|
55
|
+
```
|
56
|
+
|
57
|
+
### 地の文
|
58
|
+
|
59
|
+
```
|
60
|
+
そのまま書けばそれが地の文になる
|
61
|
+
```
|
62
|
+
|
63
|
+
### コメント
|
64
|
+
|
65
|
+
```
|
66
|
+
# をつけるとその行はコメント扱いされる
|
67
|
+
# 本文には反映されない
|
68
|
+
```
|
data/bin/sssy
ADDED
data/example/example.rb
ADDED
data/example/example.ss
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'slop'
|
2
|
+
require 'ss_syntax/parse'
|
3
|
+
|
4
|
+
module SsSyntax
|
5
|
+
class CommandBuilder
|
6
|
+
def initialize(arguments = ARGV)
|
7
|
+
@arguments = arguments
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse
|
12
|
+
file_path = ARGV[0]
|
13
|
+
return puts 'Please set ss file.' if file_path == nil
|
14
|
+
|
15
|
+
file = File.open(file_path, 'r')
|
16
|
+
text = file.read
|
17
|
+
|
18
|
+
if @options[:html]
|
19
|
+
puts Parse.new(text).to_h
|
20
|
+
else
|
21
|
+
puts Parse.new(text).to_s
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def options
|
28
|
+
Slop.parse!(@arguments, help: true) do
|
29
|
+
on("t", "text", "Generate format to text.")
|
30
|
+
on("html", "Generate format to html.")
|
31
|
+
end.to_hash
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'ss_syntax/parses/character'
|
2
|
+
require 'ss_syntax/parses/comment'
|
3
|
+
require 'ss_syntax/parses/heart_voice'
|
4
|
+
require 'ss_syntax/parses/remark'
|
5
|
+
require 'ss_syntax/parses/none'
|
6
|
+
require 'ss_syntax/parses/type'
|
7
|
+
|
8
|
+
module SsSyntax
|
9
|
+
class Parse
|
10
|
+
attr_reader :text, :characters
|
11
|
+
|
12
|
+
def initialize(text)
|
13
|
+
@text = text
|
14
|
+
@charactes = {}
|
15
|
+
@parse_text = parse_text
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
@parse_text
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_h
|
23
|
+
html_text = ''
|
24
|
+
@parse_text.each_line do |line|
|
25
|
+
line.chomp!
|
26
|
+
html_text += "<span>#{line}</span><br />"
|
27
|
+
end
|
28
|
+
|
29
|
+
html_text
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def parse_text
|
35
|
+
parse_text = ''
|
36
|
+
@text.each_line do |line|
|
37
|
+
line.chomp!
|
38
|
+
case check_type(line)
|
39
|
+
when Parses::Type::Character
|
40
|
+
key, name = Parses::Character.get(line)
|
41
|
+
if key != nil && name != nil
|
42
|
+
@charactes[key] = name
|
43
|
+
end
|
44
|
+
when Parses::Type::Comment
|
45
|
+
when Parses::Type::HeartVoice
|
46
|
+
parse_text += Parses::HeartVoice.get(line, @charactes) + "\n"
|
47
|
+
when Parses::Type::Remark
|
48
|
+
parse_text += Parses::Remark.get(line, @charactes) + "\n"
|
49
|
+
when Parses::Type::None
|
50
|
+
parse_text += Parses::None.get(line) + "\n" if line != ''
|
51
|
+
else
|
52
|
+
raise 'not support type'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
return parse_text
|
57
|
+
end
|
58
|
+
|
59
|
+
def check_type(line)
|
60
|
+
if Parses::Character.check(line)
|
61
|
+
return Parses::Type::Character
|
62
|
+
elsif Parses::Comment.check(line)
|
63
|
+
return Parses::Type::Comment
|
64
|
+
elsif Parses::HeartVoice.check(line)
|
65
|
+
return Parses::Type::HeartVoice
|
66
|
+
elsif Parses::Remark.check(line)
|
67
|
+
return Parses::Type::Remark
|
68
|
+
elsif Parses::None.check(line)
|
69
|
+
return Parses::Type::None
|
70
|
+
end
|
71
|
+
|
72
|
+
nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SsSyntax
|
2
|
+
module Parses
|
3
|
+
class Character
|
4
|
+
def self.check(text)
|
5
|
+
if text.match(/^\*/) || text.match(/^-/)
|
6
|
+
return true
|
7
|
+
end
|
8
|
+
|
9
|
+
return false
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get(text)
|
13
|
+
match = text.match(/^\* (.+) (.+)/) || text.match(/^- (.+) (.+)/)
|
14
|
+
return nil, nil if match == nil
|
15
|
+
return match[1], match[2]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SsSyntax
|
2
|
+
module Parses
|
3
|
+
class HeartVoice
|
4
|
+
def self.check(text)
|
5
|
+
if text.match(/.+_/)
|
6
|
+
return true
|
7
|
+
end
|
8
|
+
|
9
|
+
return false
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get(text, characters)
|
13
|
+
match = text.match(/(.+)_ (.+)/)
|
14
|
+
key, body = match[1], match[2]
|
15
|
+
|
16
|
+
return "#{characters[key]}(#{body})" if characters[key] != nil
|
17
|
+
return "#{key}(#{body})"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SsSyntax
|
2
|
+
module Parses
|
3
|
+
class Remark
|
4
|
+
def self.check(text)
|
5
|
+
if text.match(/.+:/)
|
6
|
+
return true
|
7
|
+
end
|
8
|
+
|
9
|
+
return false
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get(text, characters)
|
13
|
+
match = text.match(/(.+): (.+)/)
|
14
|
+
key, body = match[1], match[2]
|
15
|
+
|
16
|
+
return "#{characters[key]}「#{body}」" if characters[key] != nil
|
17
|
+
return "#{key}「#{body}」"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/ss_syntax.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'ss_syntax/parse'
|
2
|
+
|
3
|
+
module SsSyntax
|
4
|
+
class SsSyntax
|
5
|
+
attr_reader :text, :type
|
6
|
+
|
7
|
+
def initialize(text, type = :text)
|
8
|
+
@text = text
|
9
|
+
@type = type
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse()
|
13
|
+
parse = Parse.new(@text)
|
14
|
+
case @type
|
15
|
+
when :text
|
16
|
+
return parse.to_s
|
17
|
+
when :html
|
18
|
+
return parse.to_h
|
19
|
+
else
|
20
|
+
return parse.to_s
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/ss_syntax.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'ss_syntax/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'ss_syntax'
|
7
|
+
s.version = SsSyntax::VERSION
|
8
|
+
s.summary = "Short Story Syntax"
|
9
|
+
s.authors = ["henteko"]
|
10
|
+
s.email = 'henteko07@gmail.com'
|
11
|
+
s.homepage = 'http://rubygems.org/gems/ss_syntax'
|
12
|
+
s.license = 'MIT'
|
13
|
+
|
14
|
+
s.files = `git ls-files -z`.split("\x0")
|
15
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.add_dependency "slop"
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ss_syntax
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- henteko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: slop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email: henteko07@gmail.com
|
29
|
+
executables:
|
30
|
+
- sssy
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
37
|
+
- README.md
|
38
|
+
- bin/sssy
|
39
|
+
- example/example.rb
|
40
|
+
- example/example.ss
|
41
|
+
- lib/ss_syntax.rb
|
42
|
+
- lib/ss_syntax/command_builder.rb
|
43
|
+
- lib/ss_syntax/parse.rb
|
44
|
+
- lib/ss_syntax/parses/character.rb
|
45
|
+
- lib/ss_syntax/parses/comment.rb
|
46
|
+
- lib/ss_syntax/parses/heart_voice.rb
|
47
|
+
- lib/ss_syntax/parses/none.rb
|
48
|
+
- lib/ss_syntax/parses/remark.rb
|
49
|
+
- lib/ss_syntax/parses/type.rb
|
50
|
+
- lib/ss_syntax/version.rb
|
51
|
+
- ss_syntax.gemspec
|
52
|
+
homepage: http://rubygems.org/gems/ss_syntax
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 2.2.2
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Short Story Syntax
|
76
|
+
test_files: []
|