Skip to content

Commit

Permalink
Fix autogeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo98 committed Jan 27, 2024
1 parent 712a923 commit b8f54cb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
20 changes: 6 additions & 14 deletions .caskignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
./**/font-lisutzimu.rb
./**/font-aileron.rb
./**/font-xits.rb
./**/font-sf-mono.rb
./**/font-sf-compact.rb
./**/font-sf-pro.rb
./**/font-kanjistrokeorders.rb
./**/font-new-york.rb
./**/font-d2coding.rb
./**/font-liberation.rb
./**/font-3270.rb
./**/font-gilbert.rb
./**/font-brill.rb
./**/font-sf-arabic.rb
./**/font-fira-code.rb
./**/font-anonymous-pro.rb
./**/font-sf-armenian.rb
./**/font-sf-compact.rb
./**/font-sf-georgian.rb
./**/font-sf-hebrew.rb
./**/font-sf-mono.rb
./**/font-sf-pro.rb
30 changes: 20 additions & 10 deletions cask2formula
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end

class CaskParser < Parslet::Parser
rule(:space) {
match("[ \t\n\r]").repeat
match("[ \t\n\r]").repeat(1)
}
rule(:string) {
((str('"') >>
Expand All @@ -41,24 +41,26 @@ class CaskParser < Parslet::Parser
(word >> str(":")).as(:left) >> space >> (string | keyword | word).as(:right)
}
rule(:doblock) {
(str("do") >> (str("end").absent? >> any).repeat >> str("end")).as(:doblock)
(str("do") >> space >>
((space >> doblock) | (match("[ \t\n\r]+end").absent? >> any)).repeat >>
space >> str("end"))
}
rule(:heredoc) {
(str("<<~EOS") >> (str("EOS").absent? >> any).repeat >> str("EOS")).as(:heredoc)
}
rule(:value) {
(string | keyword | pair | heredoc | doblock)
(string | keyword | pair | heredoc | doblock.as(:doblock))
}
rule(:font) {
str("font") >> space >> string.as(:font)
}
rule(:command) {
(str("font").absent? >> word).as(:command) >> space >>
(str("font").absent? >> word >> str("!").maybe).as(:command) >> space >>
value.as(:first_argument) >>
(space >> str(",") >> space >> value).repeat.as(:rest_arguments)
(str(",") >> space >> value).repeat.as(:rest_arguments)
}
rule(:comment) {
(str("#") >> (str("\n").absent? >> any).repeat >> str("\n")).as(:comment)
(str("#") >> (str("\n").absent? >> any).repeat).as(:comment)
}
rule(:cask) {
str("cask") >> space >> string.as(:name) >> space >> str("do") >> space >>
Expand Down Expand Up @@ -90,7 +92,7 @@ class CaskTransform < Parslet::Transform
left + " " + right
}
rule(:comment => simple(:comment)) {
comment.to_s
comment.to_s + "\n"
}
rule(:font => simple(:font)) {
afont = font.to_s
Expand Down Expand Up @@ -154,6 +156,8 @@ class CaskTransform < Parslet::Transform
"head #{arguments.join(", ")}"
elsif command == "livecheck" then
""
elsif command == "deprecate!" || command == "disable!" then
command + " " + arguments.join(", ").gsub(":discontinued", ":unsupported")
else
command + " " + replace_cask_version_properties(arguments.join(", ").to_s)
end
Expand All @@ -162,20 +166,25 @@ end

class CaskConverter
def convert
transform = CaskTransform.new
transform = CaskTransform.new(true)
parser = CaskParser.new
ignores = IO.readlines('.caskignore', chomp: true)
Dir.glob('./homebrew-cask-fonts/Casks/*.rb').select{|file|
ignores.all? { |ignore| !File.fnmatch(ignore, file) }
}.each{|cask|
}.each do |cask|
p "< #{cask}"
recipe = File.read(cask)
recipe = parser.parse(recipe)
recipe = transform.apply(recipe)
formula = cask.sub(%r{homebrew-cask-fonts/Casks}, 'Formula')
File.write(formula, recipe)
p "> #{formula}"
}
rescue Parslet::ParseFailed => failure
$stderr.puts failure.parse_failure_cause.ascii_tree
exit 1
end

(Dir.children("Formula") - Dir.children("homebrew-cask-fonts/Casks")).each { |file| File.delete("Formula/#{file}") }
end

def commit
Expand All @@ -192,6 +201,7 @@ class CaskConverter
end
end

Dir.chdir(__dir__)
converter = CaskConverter.new
case ARGV[0]
when "convert" then converter.convert
Expand Down

0 comments on commit b8f54cb

Please sign in to comment.