at_coder_friends 0.6.9 → 0.7.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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +1 -1
  3. data/.github/workflows/ruby.yml +7 -1
  4. data/.gitignore +3 -0
  5. data/.rubocop.yml +1 -1
  6. data/CHANGELOG.md +17 -4
  7. data/Gemfile.lock +37 -40
  8. data/README.md +10 -91
  9. data/at_coder_friends.gemspec +2 -2
  10. data/lib/at_coder_friends/cli.rb +13 -28
  11. data/lib/at_coder_friends/config_loader.rb +1 -2
  12. data/lib/at_coder_friends/generator/any_builtin.rb +22 -0
  13. data/lib/at_coder_friends/generator/base.rb +55 -6
  14. data/lib/at_coder_friends/generator/c_builtin.rb +22 -0
  15. data/lib/at_coder_friends/generator/cxx_builtin.rb +8 -239
  16. data/lib/at_coder_friends/generator/fragment.rb +106 -0
  17. data/lib/at_coder_friends/generator/main.rb +14 -6
  18. data/lib/at_coder_friends/generator/ruby_builtin.rb +13 -165
  19. data/lib/at_coder_friends/parser/binary.rb +9 -3
  20. data/lib/at_coder_friends/parser/constraints.rb +8 -8
  21. data/lib/at_coder_friends/parser/input_format.rb +5 -5
  22. data/lib/at_coder_friends/path_util.rb +1 -1
  23. data/lib/at_coder_friends/problem.rb +4 -4
  24. data/lib/at_coder_friends/scraping/session.rb +1 -1
  25. data/lib/at_coder_friends/scraping/tasks.rb +1 -1
  26. data/lib/at_coder_friends/version.rb +1 -1
  27. data/lib/at_coder_friends.rb +3 -0
  28. data/templates/any_builtin.md.erb +30 -0
  29. data/templates/any_builtin_fragments.yml +5 -0
  30. data/templates/c_builtin.c.erb +36 -0
  31. data/templates/c_builtin_fragments.yml +127 -0
  32. data/templates/csharp_sample.cs.erb +29 -0
  33. data/templates/csharp_sample_fragments.yml +159 -0
  34. data/templates/java_sample.java.erb +25 -0
  35. data/templates/java_sample_fragments.yml +98 -0
  36. data/templates/ruby_builtin_fragments.yml +93 -0
  37. metadata +22 -6
  38. data/.travis.yml +0 -16
  39. data/docs/CONFIGURATION.md +0 -421
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc8c9e5d2e8f2f243d7e520c88186cc62b46296a3e1b5d7a60673d8a208dd7ec
4
- data.tar.gz: 732ab4cbadae2e8e8a1a51e3928fc0bb7f58da4738c770c93d82f5b6262f76b4
3
+ metadata.gz: bada11ce4daaea235dde05940e0e6d75dc07c64d964b0192e3f9d789346bdc01
4
+ data.tar.gz: 4324be344fdd848ea9397fc9b21bfa542567f5d9ced110fefc188c7f787c656e
5
5
  SHA512:
6
- metadata.gz: df86a0c84321098080ba9ad9ef32b6b8f413621ecd90c297fc27d65f36d8d159e7cbfe03c54cce0aa9560ce2b33841c9afa46eb5fbff33bb977d3c0dcfb186bb
7
- data.tar.gz: fbc249260ea37187c833ff102002feee9781dc6eecdfd175d4fd06ccf3f33d7a706431353c39a4126d9761825f50b3050b695b02353558594ef93ab07a4dede0
6
+ metadata.gz: 2612df7b0bbdf727dc76aca694a9d02f8278eebfd2683b4e13c06cfa18a18abb4844d474df393651e04a56a07328fc5274ac79a160c7475f4ec01e97474cc305
7
+ data.tar.gz: 765962cc818da264ff9655eef7cd73e13c4579e03d1ff2c253b4934b1f84bf581484b46d925d7754a087ea916d51b89b8785fec68f4b8ec2362f85f048ec8c00
data/.gitattributes CHANGED
@@ -1 +1 @@
1
- spec/mocks/* linguist-vendored
1
+ spec/mocks/** linguist-vendored
@@ -19,7 +19,7 @@ jobs:
19
19
  runs-on: ubuntu-latest
20
20
  strategy:
21
21
  matrix:
22
- ruby-version: ['2.5', '2.7']
22
+ ruby-version: ['2.7', '3.0', '3.2']
23
23
 
24
24
  steps:
25
25
  - uses: actions/checkout@v2
@@ -30,3 +30,9 @@ jobs:
30
30
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
31
31
  - name: Run tests
32
32
  run: script -e -c "bundle exec rspec"
33
+ env:
34
+ COVERAGE: true
35
+ - name: publish code coverage
36
+ uses: paambaati/codeclimate-action@v3.0.0
37
+ env:
38
+ CC_TEST_REPORTER_ID: cb942bcc168feb78c43c506364d5344c5ec9a46a0b68dc66acb581e77c981ff1
data/.gitignore CHANGED
@@ -19,3 +19,6 @@
19
19
 
20
20
  # regression environment
21
21
  /regression
22
+
23
+ # Visual Studio Code local settings
24
+ .vscode/
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
3
  AllCops:
4
- TargetRubyVersion: 2.5
4
+ TargetRubyVersion: 2.7
5
5
  Exclude:
6
6
  - 'templates/**/*'
7
7
  - 'spec/fixtures/**/*'
data/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.7.0 (2023-05-12)
6
+ ### Added
7
+ - add AnyBuiltin Generator
8
+ - add file extension to generator settings
9
+ - enable multiple configuration for one generator
10
+ - add CBuiltin Generator
11
+ - add Ruby3.2 to target version.
12
+ - add C# and Java templates for AnyBuiltin Generator
13
+ ### Deleted
14
+ - drop Ruby2.6 from target version.
15
+ ### Changed
16
+ - generators : externalize code fragments to YAML
17
+
5
18
  ## 0.6.9 (2021-12-25)
6
19
  ### Added
7
20
  - input_format.rb : \hspace{...}, \text{...} support
@@ -67,7 +80,7 @@
67
80
 
68
81
  ## 0.6.2 (2019-11-18)
69
82
  ### Added
70
- - add ```check-and-go``` command.
83
+ - add `check-and-go` command.
71
84
 
72
85
  ### Changed
73
86
  - Enhancement in input format parser.
@@ -87,7 +100,7 @@
87
100
  - Add settings about source generation.
88
101
 
89
102
  ### Changed
90
- - Treat all ```A_*.in``` format files as sample input data
103
+ - Treat all `A_*.in` format files as sample input data
91
104
 
92
105
  ## 0.5.2 (2019-10-14)
93
106
  ### Fixed
@@ -103,7 +116,7 @@
103
116
 
104
117
  ## 0.5.0 (2019-10-04)
105
118
  ### Added
106
- - User/password setting in ```.at_coder_friends.yml``` is no longer required.
119
+ - User/password setting in `.at_coder_friends.yml` is no longer required.
107
120
  - Saving and restoring session feature.
108
121
 
109
122
  ## 0.4.0 (2019-09-16)
@@ -112,4 +125,4 @@
112
125
 
113
126
  ## 0.3.3 (2019-09-01)
114
127
  ### Added
115
- - Add ```open-contest-page``` command.
128
+ - Add `open-contest-page` command.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- at_coder_friends (0.6.9)
4
+ at_coder_friends (0.7.0)
5
5
  colorize (~> 0.8.1)
6
6
  launchy (>= 2.4.3)
7
7
  mechanize (~> 2.0)
@@ -9,10 +9,10 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- addressable (2.8.0)
13
- public_suffix (>= 2.0.2, < 5.0)
12
+ addressable (2.8.4)
13
+ public_suffix (>= 2.0.2, < 6.0)
14
14
  colorize (0.8.1)
15
- connection_pool (2.2.5)
15
+ connection_pool (2.4.0)
16
16
  crack (0.4.5)
17
17
  rexml
18
18
  diff-lcs (1.5.0)
@@ -20,11 +20,12 @@ GEM
20
20
  domain_name (0.5.20190701)
21
21
  unf (>= 0.0.5, < 1.0.0)
22
22
  hashdiff (1.0.1)
23
- http-cookie (1.0.4)
23
+ http-cookie (1.0.5)
24
24
  domain_name (~> 0.5)
25
- launchy (2.5.0)
26
- addressable (~> 2.7)
27
- mechanize (2.8.3)
25
+ json (2.6.3)
26
+ launchy (2.5.2)
27
+ addressable (~> 2.8)
28
+ mechanize (2.9.1)
28
29
  addressable (~> 2.8)
29
30
  domain_name (~> 0.5, >= 0.5.20190701)
30
31
  http-cookie (~> 1.0, >= 1.0.3)
@@ -37,62 +38,58 @@ GEM
37
38
  webrobots (~> 0.1.2)
38
39
  mime-types (3.4.1)
39
40
  mime-types-data (~> 3.2015)
40
- mime-types-data (3.2021.1115)
41
- mini_portile2 (2.6.1)
41
+ mime-types-data (3.2023.0218.1)
42
42
  net-http-digest_auth (1.4.1)
43
- net-http-persistent (4.0.1)
43
+ net-http-persistent (4.0.2)
44
44
  connection_pool (~> 2.2)
45
- nokogiri (1.12.5)
46
- mini_portile2 (~> 2.6.1)
45
+ nokogiri (1.14.3-arm64-darwin)
47
46
  racc (~> 1.4)
48
- nokogiri (1.12.5-x64-mingw32)
47
+ nokogiri (1.14.3-x86_64-linux)
49
48
  racc (~> 1.4)
50
- public_suffix (4.0.6)
51
- racc (1.6.0)
49
+ public_suffix (5.0.1)
50
+ racc (1.6.2)
52
51
  rake (13.0.6)
53
52
  rexml (3.2.5)
54
- rspec (3.10.0)
55
- rspec-core (~> 3.10.0)
56
- rspec-expectations (~> 3.10.0)
57
- rspec-mocks (~> 3.10.0)
58
- rspec-core (3.10.1)
59
- rspec-support (~> 3.10.0)
60
- rspec-expectations (3.10.1)
53
+ rspec (3.12.0)
54
+ rspec-core (~> 3.12.0)
55
+ rspec-expectations (~> 3.12.0)
56
+ rspec-mocks (~> 3.12.0)
57
+ rspec-core (3.12.2)
58
+ rspec-support (~> 3.12.0)
59
+ rspec-expectations (3.12.3)
61
60
  diff-lcs (>= 1.2.0, < 2.0)
62
- rspec-support (~> 3.10.0)
63
- rspec-mocks (3.10.2)
61
+ rspec-support (~> 3.12.0)
62
+ rspec-mocks (3.12.5)
64
63
  diff-lcs (>= 1.2.0, < 2.0)
65
- rspec-support (~> 3.10.0)
66
- rspec-support (3.10.3)
64
+ rspec-support (~> 3.12.0)
65
+ rspec-support (3.12.0)
67
66
  rubyntlm (0.6.3)
68
- simplecov (0.21.2)
67
+ simplecov (0.17.1)
69
68
  docile (~> 1.1)
70
- simplecov-html (~> 0.11)
71
- simplecov_json_formatter (~> 0.1)
72
- simplecov-html (0.12.3)
73
- simplecov_json_formatter (0.1.3)
69
+ json (>= 1.8, < 3)
70
+ simplecov-html (~> 0.10.0)
71
+ simplecov-html (0.10.2)
74
72
  unf (0.1.4)
75
73
  unf_ext
76
- unf_ext (0.0.8)
77
- unf_ext (0.0.8-x64-mingw32)
78
- webmock (3.14.0)
74
+ unf_ext (0.0.8.2)
75
+ webmock (3.18.1)
79
76
  addressable (>= 2.8.0)
80
77
  crack (>= 0.3.2)
81
78
  hashdiff (>= 0.4.0, < 2.0.0)
82
- webrick (1.7.0)
79
+ webrick (1.8.1)
83
80
  webrobots (0.1.2)
84
81
 
85
82
  PLATFORMS
86
- ruby
87
- x64-mingw32
83
+ arm64-darwin-20
84
+ x86_64-linux
88
85
 
89
86
  DEPENDENCIES
90
87
  at_coder_friends!
91
88
  bundler (~> 2.0)
92
89
  rake (~> 13.0)
93
90
  rspec (~> 3.0)
94
- simplecov (~> 0.10)
91
+ simplecov (~> 0.10, < 0.18)
95
92
  webmock (~> 3.0)
96
93
 
97
94
  BUNDLED WITH
98
- 2.2.32
95
+ 2.4.12
data/README.md CHANGED
@@ -20,7 +20,7 @@ AtCoderFriends automates tasks about [AtCoder](https://atcoder.jp/) programming
20
20
 
21
21
  ## Dependencies
22
22
 
23
- - Ruby 2.5 or newer
23
+ - Ruby 2.7 or newer
24
24
  - [Mechanize](https://github.com/sparklemotion/mechanize)
25
25
 
26
26
  ## Installation
@@ -84,107 +84,26 @@ at_coder_friends check-and-go /path/to/contest/source_file
84
84
  ### Naming convention
85
85
 
86
86
  - Contest folder name will be used in the contest site URL.
87
- For example, if ```arc001``` folder is specified, AtCoderFriends will use ```https://atcoder.jp/contests/arc001/```.
88
- - Source file should be named ```[problem ID].[language specific extension]```(e.g. ```A.rb```),
87
+ For example, if `arc001` folder is specified, AtCoderFriends will use `https://atcoder.jp/contests/arc001/`.
88
+ - Source file should be named `[problem ID].[language specific extension]`(e.g. `A.rb`),
89
89
  in order to let AtCoderFriends find test cases or fill the submission form.
90
- - Suffixes (start with underscore) may be added to the file name (e.g. ```A_v2.rb```),
90
+ - Suffixes (start with underscore) may be added to the file name (e.g. `A_v2.rb`),
91
91
  so that you can try multiple codes for one problem.
92
92
 
93
93
  ## Notes
94
94
 
95
95
  - Compilation is not supported.
96
- - Source generator supports Ruby and C++ in default, and can be added by plugin.
96
+ - Source generator supports Ruby and C/C++ in default, and can be added by plugin.
97
97
  - Test runner and code submission are supported in 36 languages.
98
98
 
99
99
 
100
100
  ## Configuration
101
101
 
102
- See [CONFIGURATION.md](docs/CONFIGURATION.md) for details.
103
-
104
- ## For Sublime Text user
105
-
106
- It is convenient to use AtCoderFriends from Sublime Text plugin.
107
-
108
- - [sublime_at_coder_friends](https://github.com/nejiko96/sublime_at_coder_friends)
109
-
110
- ## For Visual Studio Code user
111
-
112
- - Run **Configure Tasks** from the global Terminal menu.
113
- - Select the **Create tasks.json file from template** entry.
114
- - Select **Others** from the list.
115
- - Add following settings to ```tasks.json```.
116
-
117
- ```JSON
118
- {
119
- "version": "2.0.0",
120
- "tasks": [
121
- {
122
- "label": "AtCoderFriends:New Contest",
123
- "type": "shell",
124
- "command": "at_coder_friends",
125
- "args": [
126
- "setup",
127
- "${input:contestName}"
128
- ],
129
- "problemMatcher": [],
130
- "group": "none"
131
- },
132
- {
133
- "label": "AtCoderFriends:Test One",
134
- "type": "shell",
135
- "command": "at_coder_friends",
136
- "args": [
137
- "test-one",
138
- "${file}"
139
- ],
140
- "problemMatcher": [],
141
- "group": "none"
142
- },
143
- {
144
- "label": "AtCoderFriends:Test All",
145
- "type": "shell",
146
- "command": "at_coder_friends",
147
- "args": [
148
- "test-all",
149
- "${file}"
150
- ],
151
- "problemMatcher": [],
152
- "group": "none"
153
- },
154
- {
155
- "label": "AtCoderFriends:Submit",
156
- "type": "shell",
157
- "command": "at_coder_friends",
158
- "args": [
159
- "submit",
160
- "${file}"
161
- ],
162
- "problemMatcher": [],
163
- "group": "none",
164
- },
165
- {
166
- "label": "AtCoderFriends:Check & Go",
167
- "type": "shell",
168
- "command": "at_coder_friends",
169
- "args": [
170
- "check-and-go",
171
- "${file}"
172
- ],
173
- "problemMatcher": [],
174
- "group": "none",
175
- },
176
- ...
177
- ],
178
- "inputs": [
179
- {
180
- "id": "contestName",
181
- "type": "promptString",
182
- "default": "",
183
- "description": "Contest Name"
184
- }
185
- ]
186
- }
187
- ```
102
+ See [Wiki](https://github.com/nejiko96/at_coder_friends/wiki/Configuration-details) for details.
103
+
104
+ ## Customizing editor
105
+
106
+ See [Wiki](https://github.com/nejiko96/at_coder_friends/wiki/Customizing-editor) for details.
188
107
 
189
108
  ## Development
190
109
 
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ['lib']
30
30
 
31
- spec.required_ruby_version = '>= 2.5.0'
31
+ spec.required_ruby_version = '>= 2.7.0'
32
32
 
33
33
  spec.metadata = {
34
34
  'homepage_uri' => spec.homepage,
@@ -44,6 +44,6 @@ Gem::Specification.new do |spec|
44
44
  spec.add_development_dependency 'bundler', '~> 2.0'
45
45
  spec.add_development_dependency 'rake', '~> 13.0'
46
46
  spec.add_development_dependency 'rspec', '~> 3.0'
47
- spec.add_development_dependency 'simplecov', '~> 0.10'
47
+ spec.add_development_dependency 'simplecov', '~> 0.10', '< 0.18'
48
48
  spec.add_development_dependency 'webmock', '~> 3.0'
49
49
  end
@@ -67,30 +67,15 @@ module AtCoderFriends
67
67
 
68
68
  def exec_command(command, path, *args)
69
69
  @ctx = Context.new(@options, path)
70
- case command
71
- when 'setup'
72
- setup
73
- when 'test-one'
74
- test_one(*args)
75
- when 'test-all'
76
- test_all
77
- when 'submit'
78
- submit
79
- when 'check-and-go'
80
- check_and_go
81
- when 'judge-one'
82
- judge_one(*args)
83
- when 'judge-all'
84
- judge_all
85
- when 'open-contest'
86
- open_contest
87
- else
88
- raise ParamError, "unknown command: #{command}"
89
- end
70
+
71
+ mtd = "command_#{command.gsub('-', '_')}"
72
+ raise ParamError, "unknown command: #{command}" unless respond_to?(mtd)
73
+
74
+ send(mtd, *args)
90
75
  ctx.post_process
91
76
  end
92
77
 
93
- def setup
78
+ def command_setup
94
79
  path = ctx.path
95
80
  raise AppError, "#{path} is not empty." \
96
81
  if Dir.exist?(path) && !Dir["#{path}/*"].empty?
@@ -102,16 +87,16 @@ module AtCoderFriends
102
87
  end
103
88
  end
104
89
 
105
- def test_one(id = '001')
90
+ def command_test_one(id = '001')
106
91
  ctx.sample_test_runner.test_one(id)
107
92
  end
108
93
 
109
- def test_all
94
+ def command_test_all
110
95
  ctx.sample_test_runner.test_all
111
96
  ctx.verifier.verify
112
97
  end
113
98
 
114
- def submit
99
+ def command_submit
115
100
  vf = ctx.verifier
116
101
  raise AppError, "#{vf.file} has not been tested." unless vf.verified?
117
102
 
@@ -120,7 +105,7 @@ module AtCoderFriends
120
105
  open_submission_list
121
106
  end
122
107
 
123
- def check_and_go
108
+ def command_check_and_go
124
109
  vf = ctx.verifier
125
110
  if ctx.sample_test_runner.test_all
126
111
  # submit automatically
@@ -133,15 +118,15 @@ module AtCoderFriends
133
118
  end
134
119
  end
135
120
 
136
- def judge_one(id = '')
121
+ def command_judge_one(id = '')
137
122
  ctx.judge_test_runner.judge_one(id)
138
123
  end
139
124
 
140
- def judge_all
125
+ def command_judge_all
141
126
  ctx.judge_test_runner.judge_all
142
127
  end
143
128
 
144
- def open_contest
129
+ def command_open_contest
145
130
  Launchy.open(ctx.scraping_agent.contest_url)
146
131
  end
147
132
 
@@ -61,8 +61,7 @@ module AtCoderFriends
61
61
  end
62
62
 
63
63
  def load_yaml(path)
64
- yaml = File.read(path, encoding: Encoding::UTF_8)
65
- YAML.safe_load(yaml, [], [], false, path) || {}
64
+ YAML.load_file(path) || {}
66
65
  rescue Errno::ENOENT
67
66
  raise ConfigNotFoundError,
68
67
  "Configuration file not found: #{path}"
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AtCoderFriends
4
+ module Generator
5
+ # generates source from template
6
+ class AnyBuiltin < Base
7
+ include ConstFragmentMixin
8
+ include DeclFragmentMixin
9
+ include InputFragmentMixin
10
+
11
+ ACF_HOME = File.realpath(File.join(__dir__, '..', '..', '..'))
12
+ TMPL_DIR = File.join(ACF_HOME, 'templates')
13
+ TEMPLATE = File.join(TMPL_DIR, 'any_builtin.md.erb')
14
+ FRAGMENTS = File.join(TMPL_DIR, 'any_builtin_fragments.yml')
15
+ ATTRS = Attributes.new(:md, TEMPLATE, FRAGMENTS)
16
+
17
+ def attrs
18
+ ATTRS
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,13 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'yaml'
3
4
  require 'erb'
4
5
 
5
6
  module AtCoderFriends
6
7
  module Generator
7
- Attributes = Struct.new(:file_ext, :default_template)
8
+ Attributes = Struct.new(:file_ext, :template, :fragments)
8
9
 
9
10
  # common behavior of generators
10
11
  class Base
12
+ ACF_HOME = File.realpath(File.join(__dir__, '..', '..', '..'))
13
+ TMPL_DIR = File.join(ACF_HOME, 'templates')
14
+
11
15
  attr_reader :cfg, :pbm
12
16
 
13
17
  def initialize(cfg = nil)
@@ -15,21 +19,36 @@ module AtCoderFriends
15
19
  end
16
20
 
17
21
  def process(pbm)
18
- pbm.add_src(attrs.file_ext, generate(pbm))
22
+ pbm.add_src(config_file_ext, generate(pbm))
19
23
  end
20
24
 
21
25
  def generate(pbm)
22
26
  @pbm = pbm
23
- src = File.read(select_template)
24
- src = ERB.new(src, safe_level = nil, trim_mode = '-').result(binding)
27
+ template = File.read(config_template)
28
+ src = ERB.new(template, trim_mode: '-').result(binding)
25
29
  src = render(src) if respond_to?(:render)
26
30
  src
27
31
  end
28
32
 
29
- def select_template
30
- cfg['default_template'] || attrs.default_template
33
+ def fragments
34
+ @fragments ||= YAML.load_file(config_fragments)
35
+ end
36
+
37
+ def config_file_ext
38
+ cfg['file_ext']&.to_sym || attrs.file_ext
31
39
  end
32
40
 
41
+ def config_template
42
+ template = cfg['template'] || cfg['default_template'] || attrs.template
43
+ template.sub(/\A@/, TMPL_DIR)
44
+ end
45
+
46
+ def config_fragments
47
+ fragments = cfg['fragments'] || attrs.fragments
48
+ fragments.sub(/\A@/, TMPL_DIR)
49
+ end
50
+
51
+ # deprecated, use ERB syntax
33
52
  def embed_lines(src, pat, lines)
34
53
  re = Regexp.escape(pat)
35
54
  src.gsub(
@@ -38,5 +57,35 @@ module AtCoderFriends
38
57
  )
39
58
  end
40
59
  end
60
+
61
+ module ConstFragmentMixin
62
+ def gen_consts
63
+ pbm.constants.map { |c| gen_const(c) }
64
+ end
65
+
66
+ def gen_const(c)
67
+ ConstFragment.new(c, fragments['constant']).generate
68
+ end
69
+ end
70
+
71
+ module DeclFragmentMixin
72
+ def gen_decls
73
+ pbm.formats.map { |inpdef| gen_decl(inpdef).split("\n") }.flatten
74
+ end
75
+
76
+ def gen_decl(inpdef)
77
+ InputFormatFragment.new(inpdef, fragments['declaration']).generate
78
+ end
79
+ end
80
+
81
+ module InputFragmentMixin
82
+ def gen_inputs
83
+ pbm.formats.map { |inpdef| gen_input(inpdef).split("\n") }.flatten
84
+ end
85
+
86
+ def gen_input(inpdef)
87
+ InputFormatFragment.new(inpdef, fragments['input']).generate
88
+ end
89
+ end
41
90
  end
42
91
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AtCoderFriends
4
+ module Generator
5
+ # generates C source from problem description
6
+ class CBuiltin < Base
7
+ include ConstFragmentMixin
8
+ include DeclFragmentMixin
9
+ include InputFragmentMixin
10
+
11
+ ACF_HOME = File.realpath(File.join(__dir__, '..', '..', '..'))
12
+ TMPL_DIR = File.join(ACF_HOME, 'templates')
13
+ TEMPLATE = File.join(TMPL_DIR, 'c_builtin.c.erb')
14
+ FRAGMENTS = File.join(TMPL_DIR, 'c_builtin_fragments.yml')
15
+ ATTRS = Attributes.new(:c, TEMPLATE, FRAGMENTS)
16
+
17
+ def attrs
18
+ ATTRS
19
+ end
20
+ end
21
+ end
22
+ end