Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 11 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,25 @@ multitask(:syntax_tree) do
inplace = /darwin|bsd/ =~ RUBY_PLATFORM ? %w[-i''] : %w[-i]
uuid = SecureRandom.uuid

# `syntax_tree` has trouble with `rbs`'s class aliases
# `syntax_tree` has trouble with `rbs`'s class & module aliases

sed = xargs + %w[sed -E] + inplace + %w[-e]
# annotate class aliases with a unique comment
pre = sed + ["s/class ([^ ]+) = (.+$)/# #{uuid}\\n\\1: \\2/", "--"]
# annotate unprocessable aliases with a unique comment
pre = sed + ["s/(class|module) ([^ ]+) = (.+$)/# \\1 #{uuid}\\n\\2: \\3/", "--"]
fmt = xargs + %w[stree write --plugin=rbs --]
# remove the unique comment and transform class aliases to type aliases
# remove the unique comment and unprocessable aliases to type aliases
subst = <<~SED
s/# #{uuid}//
s/# (class|module) #{uuid}/\\1/
t l1
b

: l1
n
s/([^ :]+): (.+$)/class \\1 = \\2/
N
s/\\n *([^:]+): (.+)$/ \\1 = \\2/
SED
# 1. delete the unique comment
# 2. if deletion happened, branch to label `l1`, else continue
# 3. transform the class alias to a type alias at label `l1`
# for each line:
# 1. try transform the unique comment into `class | module`, if successful, branch to label `l1`.
# 2. at label `l1`, join previously annotated line with `class | module` information.
pst = sed + [subst, "--"]

# transform class aliases to type aliases, which syntax tree has no trouble with
Expand Down
Loading