File: compile.rake

package info (click to toggle)
ruby-rubocop-ast 1.24.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,256 kB
  • sloc: ruby: 15,071; yacc: 90; makefile: 9
file content (39 lines) | stat: -rw-r--r-- 1,015 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

require 'oedipus_lex'
Rake.application.rake_require 'oedipus_lex'

def update_file(path)
  content = File.read(path)
  File.write(path, yield(content))
end

ENCODING_COMMENT = '# frozen_string_literal: true'
GENERATED_FILES = %w[
  lib/rubocop/ast/node_pattern/parser.racc.rb
  lib/rubocop/ast/node_pattern/lexer.rex.rb
].freeze
desc 'Generate the lexer and parser files.'
task generate: %w[generate:lexer generate:parser]

files = {
  lexer: 'lib/rubocop/ast/node_pattern/lexer.rex.rb',
  parser: 'lib/rubocop/ast/node_pattern/parser.racc.rb'
}

namespace :generate do
  files.each do |kind, filename|
    desc "Generate just the #{kind}"
    task kind => filename do
      update_file(filename) do |content|
        content.prepend ENCODING_COMMENT, "\n" unless content.start_with?(ENCODING_COMMENT)
        content.gsub 'module NodePattern', 'class NodePattern'
      end
    end
  end
end

rule '.racc.rb' => '.y' do |t|
  cmd = "racc -l -v -o #{t.name} #{t.source}"
  sh cmd
end