at_coder_friends-generator-python_ref 0.1.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +32 -0
- data/.rubocop.yml +3 -2
- data/CHANGELOG.md +35 -1
- data/Gemfile.lock +59 -42
- data/README.md +18 -11
- data/at_coder_friends-generator-python_ref.gemspec +14 -12
- data/lib/at_coder_friends/generator/python_ref/version.rb +2 -2
- data/lib/at_coder_friends/generator/python_ref.rb +100 -54
- data/templates/python_ref.py.erb +15 -0
- metadata +28 -15
- data/templates/python_ref_default.py +0 -7
- data/templates/python_ref_interactive.py +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 45f6fd099c746e4e5e4912c4cac72e839cd49985aff42f560d833f13aa8daf96
|
4
|
+
data.tar.gz: 5b3fb579bfc0ac86800cc20b99b75e2505015ce4d98cc0c8908ff6fe2dbcd1f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f142ec1d52f7ceacf31096cd4535f85b1b780f9ef4d4752f742e907344743219277e1f8082488f9a806ab731f34a82d7c2e2c8655a9c1df5fb40b1dd7ddbc82
|
7
|
+
data.tar.gz: d38828116e05577842dffbd5e28648106f1af62649b91e447d977966fda2ea09db6bb5db3114fb7383b7a3374a3629e1409e9fe13be72ba059a58b9ec6674a5e
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.5', '2.7']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
uses: ruby/setup-ruby@v1
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby-version }}
|
30
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
31
|
+
- name: Run tests
|
32
|
+
run: bundle exec rspec
|
data/.rubocop.yml
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
inherit_from: .rubocop_todo.yml
|
2
2
|
|
3
3
|
AllCops:
|
4
|
-
TargetRubyVersion: 2.
|
4
|
+
TargetRubyVersion: 2.5
|
5
|
+
NewCops: enable
|
5
6
|
|
6
7
|
Metrics/BlockLength:
|
7
8
|
Exclude:
|
8
9
|
- 'spec/**/*.rb'
|
9
10
|
- '**/*.gemspec'
|
10
11
|
|
11
|
-
Naming/
|
12
|
+
Naming/MethodParameterName:
|
12
13
|
MinNameLength: 1
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,40 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
-
## master(unreleased)
|
3
|
+
## master (unreleased)
|
4
|
+
|
5
|
+
## 0.3.2 (2021/12/25)
|
6
|
+
### Deleted
|
7
|
+
- drop Ruby2.4 from target version.
|
8
|
+
|
9
|
+
## 0.3.1 (2020/12/20)
|
10
|
+
### Added
|
11
|
+
- python 3.8.2 support - use underscore separator in number literal
|
12
|
+
|
13
|
+
### Deleted
|
14
|
+
- drop Ruby2.3 from target version.
|
15
|
+
|
16
|
+
## 0.3.0 (2020-05-29)
|
17
|
+
### Changed
|
18
|
+
- use -%> in ERB. (available in next release of AtCoderFriends.)
|
19
|
+
|
20
|
+
## 0.2.0 (2020-01-05)
|
21
|
+
### Added
|
22
|
+
- at_coder_friends 0.6.3 support
|
23
|
+
- 'vertical array + matrix' input format support.
|
24
|
+
- 'matrix + vertical array' input format support.
|
25
|
+
- 'vertically expanded matrices' input format support.
|
26
|
+
- 'horizontally expanded matrices' input format support.
|
27
|
+
- decimal type support.
|
28
|
+
- input data with delimiter(- : /) support.
|
29
|
+
|
30
|
+
### Changed
|
31
|
+
- Change template file format to ERB.
|
32
|
+
- Template file integration
|
33
|
+
|
34
|
+
### Deleted
|
35
|
+
- Template file for interactive problems.
|
36
|
+
- '### OUTPUT ###' embedding pattern.
|
37
|
+
- '### URL ###' embedding pattern.
|
4
38
|
|
5
39
|
## 0.1.0 (2019-10-31)
|
6
40
|
- Initial implementation
|
data/Gemfile.lock
CHANGED
@@ -1,74 +1,91 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
at_coder_friends-generator-python_ref (0.
|
4
|
+
at_coder_friends-generator-python_ref (0.3.2)
|
5
|
+
at_coder_friends (~> 0.6.8)
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
8
9
|
specs:
|
9
|
-
addressable (2.
|
10
|
+
addressable (2.8.0)
|
10
11
|
public_suffix (>= 2.0.2, < 5.0)
|
11
|
-
at_coder_friends (0.6.
|
12
|
+
at_coder_friends (0.6.8)
|
12
13
|
colorize (~> 0.8.1)
|
13
|
-
launchy (
|
14
|
+
launchy (>= 2.4.3)
|
14
15
|
mechanize (~> 2.0)
|
15
16
|
colorize (0.8.1)
|
16
|
-
connection_pool (2.2.
|
17
|
-
diff-lcs (1.
|
17
|
+
connection_pool (2.2.5)
|
18
|
+
diff-lcs (1.5.0)
|
19
|
+
docile (1.4.0)
|
18
20
|
domain_name (0.5.20190701)
|
19
21
|
unf (>= 0.0.5, < 1.0.0)
|
20
|
-
http-cookie (1.0.
|
22
|
+
http-cookie (1.0.4)
|
21
23
|
domain_name (~> 0.5)
|
22
|
-
launchy (2.
|
23
|
-
addressable (~> 2.
|
24
|
-
mechanize (2.
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
net-http-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
24
|
+
launchy (2.5.0)
|
25
|
+
addressable (~> 2.7)
|
26
|
+
mechanize (2.8.3)
|
27
|
+
addressable (~> 2.8)
|
28
|
+
domain_name (~> 0.5, >= 0.5.20190701)
|
29
|
+
http-cookie (~> 1.0, >= 1.0.3)
|
30
|
+
mime-types (~> 3.0)
|
31
|
+
net-http-digest_auth (~> 1.4, >= 1.4.1)
|
32
|
+
net-http-persistent (>= 2.5.2, < 5.0.dev)
|
33
|
+
nokogiri (~> 1.11, >= 1.11.2)
|
34
|
+
rubyntlm (~> 0.6, >= 0.6.3)
|
35
|
+
webrick (~> 1.7)
|
36
|
+
webrobots (~> 0.1.2)
|
37
|
+
mime-types (3.4.1)
|
34
38
|
mime-types-data (~> 3.2015)
|
35
|
-
mime-types-data (3.
|
36
|
-
mini_portile2 (2.
|
39
|
+
mime-types-data (3.2021.1115)
|
40
|
+
mini_portile2 (2.6.1)
|
37
41
|
net-http-digest_auth (1.4.1)
|
38
|
-
net-http-persistent (
|
42
|
+
net-http-persistent (4.0.1)
|
39
43
|
connection_pool (~> 2.2)
|
40
|
-
nokogiri (1.
|
41
|
-
mini_portile2 (~> 2.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
rspec-
|
51
|
-
|
44
|
+
nokogiri (1.12.5)
|
45
|
+
mini_portile2 (~> 2.6.1)
|
46
|
+
racc (~> 1.4)
|
47
|
+
nokogiri (1.12.5-x64-mingw32)
|
48
|
+
racc (~> 1.4)
|
49
|
+
public_suffix (4.0.6)
|
50
|
+
racc (1.6.0)
|
51
|
+
rake (13.0.6)
|
52
|
+
rspec (3.10.0)
|
53
|
+
rspec-core (~> 3.10.0)
|
54
|
+
rspec-expectations (~> 3.10.0)
|
55
|
+
rspec-mocks (~> 3.10.0)
|
56
|
+
rspec-core (3.10.1)
|
57
|
+
rspec-support (~> 3.10.0)
|
58
|
+
rspec-expectations (3.10.1)
|
52
59
|
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
-
rspec-support (~> 3.
|
54
|
-
rspec-mocks (3.
|
60
|
+
rspec-support (~> 3.10.0)
|
61
|
+
rspec-mocks (3.10.2)
|
55
62
|
diff-lcs (>= 1.2.0, < 2.0)
|
56
|
-
rspec-support (~> 3.
|
57
|
-
rspec-support (3.
|
63
|
+
rspec-support (~> 3.10.0)
|
64
|
+
rspec-support (3.10.3)
|
65
|
+
rubyntlm (0.6.3)
|
66
|
+
simplecov (0.21.2)
|
67
|
+
docile (~> 1.1)
|
68
|
+
simplecov-html (~> 0.11)
|
69
|
+
simplecov_json_formatter (~> 0.1)
|
70
|
+
simplecov-html (0.12.3)
|
71
|
+
simplecov_json_formatter (0.1.3)
|
58
72
|
unf (0.1.4)
|
59
73
|
unf_ext
|
60
|
-
unf_ext (0.0.
|
74
|
+
unf_ext (0.0.8)
|
75
|
+
unf_ext (0.0.8-x64-mingw32)
|
76
|
+
webrick (1.7.0)
|
61
77
|
webrobots (0.1.2)
|
62
78
|
|
63
79
|
PLATFORMS
|
64
80
|
ruby
|
81
|
+
x64-mingw32
|
65
82
|
|
66
83
|
DEPENDENCIES
|
67
|
-
at_coder_friends (~> 0.6)
|
68
84
|
at_coder_friends-generator-python_ref!
|
69
85
|
bundler (~> 2.0)
|
70
|
-
rake (~>
|
86
|
+
rake (~> 13.0)
|
71
87
|
rspec (~> 3.0)
|
88
|
+
simplecov (~> 0.10)
|
72
89
|
|
73
90
|
BUNDLED WITH
|
74
|
-
2.
|
91
|
+
2.1.4
|
data/README.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/at_coder_friends-generator-python_ref.svg)](https://badge.fury.io/rb/at_coder_friends-generator-python_ref)
|
2
|
+
![Gem](https://img.shields.io/gem/dt/at_coder_friends-generator-python_ref)
|
3
|
+
[![Ruby](https://github.com/nejiko96/at_coder_friends-generator-python_ref/actions/workflows/ruby.yml/badge.svg)](https://github.com/nejiko96/at_coder_friends-generator-python_ref/actions/workflows/ruby.yml)
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/0775ef9da0798b73beb4/maintainability)](https://codeclimate.com/github/nejiko96/at_coder_friends-generator-python_ref/maintainability)
|
5
|
+
![GitHub](https://img.shields.io/github/license/nejiko96/at_coder_friends-generator-python_ref)
|
6
|
+
|
1
7
|
# AtCoderFriends::Generator::PythonRef
|
2
8
|
|
3
9
|
Python source generator for [AtCoderFriends](https://github.com/nejiko96/at_coder_friends).
|
@@ -21,27 +27,28 @@ Or install it yourself as:
|
|
21
27
|
|
22
28
|
## Configuration
|
23
29
|
|
24
|
-
Add ```PythonRef``` to ```generators``` setting in ```.at_coder_friends.yml
|
25
|
-
```YAML
|
26
|
-
generators:
|
27
|
-
- PythonRef
|
28
|
-
```
|
30
|
+
Add ```PythonRef``` to ```generators``` setting in ```.at_coder_friends.yml```
|
29
31
|
|
30
32
|
## Generator Options
|
31
33
|
|
32
|
-
|
33
|
-
in ```.at_coder_friends.yml```:
|
34
|
+
Following options are available
|
35
|
+
in ```generator_settings/PythonRef``` section of ```.at_coder_friends.yml```:
|
34
36
|
|
35
|
-
|
|
37
|
+
| Option | Description | Default |
|
36
38
|
|---------|-------------|---------|
|
37
|
-
|default_template|Source template file path|[/templates/
|
38
|
-
|interactive_template|Source template file path for interactive problems|[/templates/python_ref_interactive.py](/templates/python_ref_interactive.py)|
|
39
|
+
|default_template|Source template file path|[/templates/python_ref.py.erb](/templates/python_ref.py.erb)|
|
39
40
|
|
40
|
-
|
41
|
+
## ```.at_coder_friends.yml``` example for Python
|
41
42
|
```YAML
|
43
|
+
generators:
|
44
|
+
- PythonRef
|
42
45
|
generator_settings:
|
43
46
|
PythonRef:
|
44
47
|
default_template: /path/to/template
|
48
|
+
ext_settings:
|
49
|
+
'py':
|
50
|
+
test_cmd:
|
51
|
+
default: 'python "{dir}/{base}.py"'
|
45
52
|
```
|
46
53
|
|
47
54
|
## Development
|
@@ -1,19 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require 'at_coder_friends/generator/python_ref/version'
|
3
|
+
require_relative 'lib/at_coder_friends/generator/python_ref/version'
|
6
4
|
|
7
5
|
Gem::Specification.new do |spec|
|
8
6
|
spec.name = 'at_coder_friends-generator-python_ref'
|
9
|
-
spec.version = AtCoderFriends::Generator::
|
7
|
+
spec.version = AtCoderFriends::Generator::PythonRefConstants::VERSION
|
10
8
|
spec.authors = ['nejiko96']
|
11
9
|
spec.email = ['nejiko2006@gmail.com']
|
12
10
|
|
13
11
|
spec.summary = 'Python generator for AtCoderFriends'
|
14
12
|
spec.description = <<-DESCRIPTION
|
15
|
-
|
16
|
-
which Generates Python source from problem description
|
13
|
+
Python source generator plugin for AtCoderFriends
|
17
14
|
(reference implementation)
|
18
15
|
DESCRIPTION
|
19
16
|
spec.homepage = 'https://github.com/nejiko96/at_coder_friends-generator-python_ref'
|
@@ -31,14 +28,19 @@ Gem::Specification.new do |spec|
|
|
31
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
29
|
spec.require_paths = ['lib']
|
33
30
|
|
34
|
-
spec.required_ruby_version = '>= 2.
|
31
|
+
spec.required_ruby_version = '>= 2.5.0'
|
35
32
|
|
36
|
-
spec.metadata
|
37
|
-
|
38
|
-
|
33
|
+
spec.metadata = {
|
34
|
+
'homepage_uri' => spec.homepage,
|
35
|
+
'source_code_uri' => spec.homepage,
|
36
|
+
'changelog_uri' => "#{spec.homepage}/blob/master/CHANGELOG.md",
|
37
|
+
'rubygems_mfa_required' => 'true'
|
38
|
+
}
|
39
|
+
|
40
|
+
spec.add_dependency 'at_coder_friends', '~> 0.6.8'
|
39
41
|
|
40
|
-
spec.add_development_dependency 'at_coder_friends', '~> 0.6'
|
41
42
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
42
|
-
spec.add_development_dependency 'rake', '~>
|
43
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
43
44
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
45
|
+
spec.add_development_dependency 'simplecov', '~> 0.10'
|
44
46
|
end
|
@@ -1,47 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'at_coder_friends'
|
3
4
|
require 'at_coder_friends/generator/python_ref/version'
|
4
5
|
|
5
6
|
module AtCoderFriends
|
6
7
|
module Generator
|
7
8
|
# generates Python source from problem description
|
8
|
-
class PythonRef
|
9
|
+
class PythonRef < Base
|
10
|
+
include PythonRefConstants
|
11
|
+
|
9
12
|
ACF_HOME = File.realpath(File.join(__dir__, '..', '..', '..'))
|
10
13
|
TMPL_DIR = File.join(ACF_HOME, 'templates')
|
11
|
-
DEFAULT_TMPL = File.join(TMPL_DIR, '
|
12
|
-
|
13
|
-
|
14
|
-
attr_reader :cfg, :pbm
|
15
|
-
|
16
|
-
def initialize(cfg = nil)
|
17
|
-
@cfg = cfg || {}
|
18
|
-
end
|
19
|
-
|
20
|
-
def process(pbm)
|
21
|
-
src = generate(pbm)
|
22
|
-
pbm.add_src(:py, src)
|
23
|
-
end
|
24
|
-
|
25
|
-
def generate(pbm)
|
26
|
-
@pbm = pbm
|
27
|
-
File
|
28
|
-
.read(select_template)
|
29
|
-
.gsub('### URL ###', pbm.url)
|
30
|
-
.gsub('### CONSTS ###', gen_consts.join("\n"))
|
31
|
-
.gsub('### DCLS ###', gen_decls.join("\n"))
|
32
|
-
.gsub('### OUTPUT ###', gen_output)
|
33
|
-
end
|
34
|
-
|
35
|
-
def select_template(interactive = pbm.options.interactive)
|
36
|
-
interactive ? interactive_template : default_template
|
37
|
-
end
|
14
|
+
DEFAULT_TMPL = File.join(TMPL_DIR, 'python_ref.py.erb')
|
15
|
+
ATTRS = Attributes.new(:py, DEFAULT_TMPL)
|
38
16
|
|
39
|
-
def
|
40
|
-
|
17
|
+
def attrs
|
18
|
+
ATTRS
|
41
19
|
end
|
42
20
|
|
43
|
-
def
|
44
|
-
|
21
|
+
def render(src)
|
22
|
+
src = embed_lines(src, '### CONSTS ###', gen_consts)
|
23
|
+
embed_lines(src, '### DCLS ###', gen_decls)
|
45
24
|
end
|
46
25
|
|
47
26
|
def gen_consts(constants = pbm.constants)
|
@@ -51,8 +30,7 @@ module AtCoderFriends
|
|
51
30
|
end
|
52
31
|
|
53
32
|
def gen_mod(c)
|
54
|
-
|
55
|
-
v = c.value.gsub('^', '**').gsub(',', '')
|
33
|
+
v = c.value.gsub('^', '**').gsub(',', '_')
|
56
34
|
"MOD = #{v}"
|
57
35
|
end
|
58
36
|
|
@@ -67,35 +45,45 @@ module AtCoderFriends
|
|
67
45
|
when :harray
|
68
46
|
gen_harray_decl(inpdef)
|
69
47
|
when :varray
|
70
|
-
|
71
|
-
gen_varray_1_decl(inpdef)
|
72
|
-
else
|
73
|
-
gen_varray_n_decl(inpdef)
|
74
|
-
end
|
48
|
+
gen_varray_decl(inpdef)
|
75
49
|
when :matrix
|
76
50
|
gen_matrix_decl(inpdef)
|
51
|
+
when :varray_matrix, :matrix_varray
|
52
|
+
gen_cmb_decl(inpdef)
|
53
|
+
when :vmatrix
|
54
|
+
gen_vmatrix_decl(inpdef)
|
55
|
+
when :hmatrix
|
56
|
+
gen_hmatrix_decl(inpdef)
|
77
57
|
end
|
78
58
|
end
|
79
59
|
|
80
60
|
def gen_single_decl(inpdef)
|
81
61
|
names = inpdef.names
|
82
62
|
dcl = names.join(', ')
|
83
|
-
expr = gen_expr(inpdef
|
63
|
+
expr = gen_expr(inpdef, names.size > 1)
|
84
64
|
"#{dcl} = #{expr}"
|
85
65
|
end
|
86
66
|
|
87
67
|
def gen_harray_decl(inpdef)
|
88
68
|
v = inpdef.names[0]
|
89
69
|
dcl = "#{v}s"
|
90
|
-
expr = gen_expr(inpdef
|
70
|
+
expr = gen_expr(inpdef, true)
|
91
71
|
"#{dcl} = #{expr}"
|
92
72
|
end
|
93
73
|
|
74
|
+
def gen_varray_decl(inpdef)
|
75
|
+
if inpdef.names.size == 1
|
76
|
+
gen_varray_1_decl(inpdef)
|
77
|
+
else
|
78
|
+
gen_varray_n_decl(inpdef)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
94
82
|
def gen_varray_1_decl(inpdef)
|
95
83
|
v = inpdef.names[0]
|
96
84
|
sz = inpdef.size[0]
|
97
85
|
dcl = "#{v}s"
|
98
|
-
expr = gen_expr(inpdef
|
86
|
+
expr = gen_expr(inpdef, false)
|
99
87
|
"#{dcl} = [#{expr} for _ in range(#{sz})]"
|
100
88
|
end
|
101
89
|
|
@@ -103,7 +91,7 @@ module AtCoderFriends
|
|
103
91
|
names = inpdef.names
|
104
92
|
sz = inpdef.size[0]
|
105
93
|
dcl = names.map { |v| "#{v}s[i]" }.join(', ')
|
106
|
-
expr = gen_expr(inpdef
|
94
|
+
expr = gen_expr(inpdef, true)
|
107
95
|
ret = []
|
108
96
|
ret += names.map { |v| "#{v}s = [None for _ in range(#{sz})]" }
|
109
97
|
ret << "for i in range(#{sz}):"
|
@@ -115,28 +103,86 @@ module AtCoderFriends
|
|
115
103
|
v = inpdef.names[0]
|
116
104
|
sz = inpdef.size[0]
|
117
105
|
decl = "#{v}ss"
|
118
|
-
expr = gen_expr(inpdef
|
106
|
+
expr = gen_expr(inpdef, true)
|
119
107
|
"#{decl} = [#{expr} for _ in range(#{sz})]"
|
120
108
|
end
|
121
109
|
|
122
|
-
def
|
123
|
-
|
110
|
+
def gen_cmb_decl(inpdef)
|
111
|
+
mx = inpdef.container == :varray_matrix ? -1 : 0
|
112
|
+
vs = inpdef.names.map { |v| "#{v}s" }
|
113
|
+
vs[mx] += 's'
|
114
|
+
sz = inpdef.size[0]
|
115
|
+
dcls = vs.map { |v| "#{v}[i]" }
|
116
|
+
dcls[mx] = "*#{dcls[mx]}" unless inpdef.item == :char
|
117
|
+
dcl = dcls.join(', ')
|
118
|
+
expr = gen_cmb_expr(inpdef)
|
119
|
+
ret = []
|
120
|
+
ret += vs.map { |v| "#{v} = [None for _ in range(#{sz})]" }
|
121
|
+
ret << "for i in range(#{sz}):"
|
122
|
+
ret << " #{dcl} = #{expr}"
|
123
|
+
ret
|
124
|
+
end
|
125
|
+
|
126
|
+
def gen_vmatrix_decl(inpdef)
|
127
|
+
names = inpdef.names
|
128
|
+
sz1, sz2 = inpdef.size
|
129
|
+
dcl = names.map { |v| "#{v}ss[i][j]" }.join(', ')
|
130
|
+
expr = gen_expr(inpdef, true)
|
131
|
+
ret = []
|
132
|
+
ret += names.map do |v|
|
133
|
+
"#{v}ss = [[None for _ in range(#{sz2})] for _ in range(#{sz1})]"
|
134
|
+
end
|
135
|
+
ret << "for i in range(#{sz1}):"
|
136
|
+
ret << " for j in range(#{sz2}):"
|
137
|
+
ret << " #{dcl} = #{expr}"
|
138
|
+
ret
|
139
|
+
end
|
140
|
+
|
141
|
+
def gen_hmatrix_decl(inpdef)
|
142
|
+
names = inpdef.names
|
143
|
+
sz = inpdef.size[0]
|
144
|
+
dcls = names.map { |v| "#{v}ss[i]" }
|
145
|
+
expr = gen_expr(inpdef, true)
|
146
|
+
ret = []
|
147
|
+
ret += names.map { |v| "#{v}ss = [None for _ in range(#{sz})]" }
|
148
|
+
ret << "for i in range(#{sz}):"
|
149
|
+
ret << " line = #{expr}"
|
150
|
+
ret += dcls.map.with_index do |dcl, i|
|
151
|
+
" #{dcl} = line[#{i}::#{dcls.size}]"
|
152
|
+
end
|
153
|
+
ret
|
154
|
+
end
|
155
|
+
|
156
|
+
def gen_expr(inpdef, split)
|
157
|
+
read = gen_read(inpdef.delim)
|
158
|
+
case inpdef.item
|
124
159
|
when :number
|
125
|
-
split ?
|
160
|
+
split ? "list(map(int, #{read}.split()))" : "int(#{read})"
|
161
|
+
when :decimal
|
162
|
+
split ? "list(map(float, #{read}.split()))" : "float(#{read})"
|
126
163
|
when :string
|
127
|
-
split ?
|
164
|
+
split ? "#{read}.split()" : read
|
128
165
|
when :char
|
129
|
-
|
166
|
+
read
|
130
167
|
end
|
131
168
|
end
|
132
169
|
|
133
|
-
def
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
170
|
+
def gen_cmb_expr(inpdef)
|
171
|
+
read = gen_read(inpdef.delim)
|
172
|
+
case inpdef.item
|
173
|
+
when :number
|
174
|
+
"list(map(int, #{read}.split()))"
|
175
|
+
when :decimal
|
176
|
+
"list(map(float, #{read}.split()))"
|
177
|
+
when :string, :char
|
178
|
+
"#{read}.split()"
|
138
179
|
end
|
139
180
|
end
|
181
|
+
|
182
|
+
def gen_read(delim)
|
183
|
+
sub = delim.chars.map { |d| ".replace('#{d}', ' ')" }.join
|
184
|
+
"input()#{sub}"
|
185
|
+
end
|
140
186
|
end
|
141
187
|
end
|
142
188
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# <%= pbm.url %>
|
2
|
+
|
3
|
+
<% gen_consts.each do |line| -%>
|
4
|
+
<%= line %>
|
5
|
+
<% end -%>
|
6
|
+
|
7
|
+
<% gen_decls.each do |line| -%>
|
8
|
+
<%= line %>
|
9
|
+
<% end -%>
|
10
|
+
|
11
|
+
<% if (vs = pbm.options.binary_values) -%>
|
12
|
+
print('<%= vs[0] %>' if cond else '<%= vs[1] %>')
|
13
|
+
<% else -%>
|
14
|
+
print(ans)
|
15
|
+
<% end -%>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: at_coder_friends-generator-python_ref
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nejiko96
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: at_coder_friends
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
type: :
|
19
|
+
version: 0.6.8
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.6.8
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,9 +66,22 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
69
83
|
description: |2
|
70
|
-
|
71
|
-
which Generates Python source from problem description
|
84
|
+
Python source generator plugin for AtCoderFriends
|
72
85
|
(reference implementation)
|
73
86
|
email:
|
74
87
|
- nejiko2006@gmail.com
|
@@ -76,6 +89,7 @@ executables: []
|
|
76
89
|
extensions: []
|
77
90
|
extra_rdoc_files: []
|
78
91
|
files:
|
92
|
+
- ".github/workflows/ruby.yml"
|
79
93
|
- ".gitignore"
|
80
94
|
- ".rspec"
|
81
95
|
- ".rubocop.yml"
|
@@ -93,15 +107,15 @@ files:
|
|
93
107
|
- bin/setup
|
94
108
|
- lib/at_coder_friends/generator/python_ref.rb
|
95
109
|
- lib/at_coder_friends/generator/python_ref/version.rb
|
96
|
-
- templates/
|
97
|
-
- templates/python_ref_interactive.py
|
110
|
+
- templates/python_ref.py.erb
|
98
111
|
homepage: https://github.com/nejiko96/at_coder_friends-generator-python_ref
|
99
112
|
licenses:
|
100
113
|
- MIT
|
101
114
|
metadata:
|
102
115
|
homepage_uri: https://github.com/nejiko96/at_coder_friends-generator-python_ref
|
103
116
|
source_code_uri: https://github.com/nejiko96/at_coder_friends-generator-python_ref
|
104
|
-
changelog_uri: https://github.com/nejiko96/at_coder_friends-generator-python_ref/CHANGELOG.md
|
117
|
+
changelog_uri: https://github.com/nejiko96/at_coder_friends-generator-python_ref/blob/master/CHANGELOG.md
|
118
|
+
rubygems_mfa_required: 'true'
|
105
119
|
post_install_message:
|
106
120
|
rdoc_options: []
|
107
121
|
require_paths:
|
@@ -110,15 +124,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
124
|
requirements:
|
111
125
|
- - ">="
|
112
126
|
- !ruby/object:Gem::Version
|
113
|
-
version: 2.
|
127
|
+
version: 2.5.0
|
114
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
129
|
requirements:
|
116
130
|
- - ">="
|
117
131
|
- !ruby/object:Gem::Version
|
118
132
|
version: '0'
|
119
133
|
requirements: []
|
120
|
-
|
121
|
-
rubygems_version: 2.5.2.3
|
134
|
+
rubygems_version: 3.1.6
|
122
135
|
signing_key:
|
123
136
|
specification_version: 4
|
124
137
|
summary: Python generator for AtCoderFriends
|