-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Analysis of common vim syntax group mappings. Shows several areas whe…
…re a better hierarchy will be invaluable. Of course, I don't know how to apply it to existing syntaxes without having a syntax file about 10,000 lines long...
- Loading branch information
1 parent
4a504d5
commit 3144c88
Showing
2 changed files
with
1,954 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/usr/bin/env ruby | ||
|
||
def up(c,last) | ||
return nil if (c.nil? || c.length == 0) | ||
return last if c.upcase == c.downcase | ||
return c.upcase == c | ||
end | ||
|
||
FULLWORDS = ['preproc', 'nontext', 'specialkey', 'errormsg', 'moremsg', | ||
'warningmsg', 'modemsg', 'matchparen','spellbad', 'spellrare', 'spellcap', | ||
'spelllocal', 'specialchar', 'precondit', 'specialcomment', 'storageclass', | ||
'typedef', 'colorcolumn'].join('|') | ||
|
||
def wordparts(word) | ||
word = word.strip.gsub(/#{FULLWORDS}/ium){|m| m.capitalize} | ||
res = []; acc = []; upc = nil | ||
word = word.split //um | ||
begin | ||
letter = word.shift | ||
cupc = up(letter, upc) | ||
if cupc != upc | ||
if cupc # lowercase to uppercase | ||
res << acc.join('').downcase unless acc.size == 0 | ||
acc = [letter] | ||
else # uppercase to lowercase | ||
mine = acc.pop | ||
res << acc.join('').downcase unless acc.size == 0 | ||
acc = [mine, letter] | ||
end | ||
else acc << letter end | ||
upc = cupc | ||
end while word.size > 0 | ||
res << acc.join('').downcase unless acc.size == 0 | ||
res = res.join('_') | ||
return res.split(/_+/).reject{|s|(s.nil? || s.length==0)}.compact | ||
end | ||
|
||
mappings = {} | ||
IO.readlines('./statements.list').each do |stmt| | ||
orig = stmt | ||
next unless stmt.start_with? 'map' | ||
stmt = stmt.split(' ') | ||
next unless stmt.size == 3 | ||
_, from, to = stmt | ||
from = wordparts(from) | ||
to = wordparts(to) | ||
from[0] = '(lang)' if from.size > 1 | ||
|
||
fr = [] | ||
begin | ||
fr << from.pop | ||
fr << from.pop if from.last == '(lang)' | ||
source = fr.reverse.join('/') | ||
dest = to.join('/') | ||
source = "#{from.size}/#{source}" if from.size > 0 | ||
mappings[dest] ||= {} | ||
mappings[dest][source] ||= 0 | ||
mappings[dest][source] += 1 | ||
end while from.size > 0 | ||
end | ||
|
||
mappings = mappings.map do |dest, sources| | ||
sources = sources.to_a.reject{|src,num| num < 3 } | ||
sources = sources.to_a | ||
mag = sources.inject(0){|a,sn| a + sn[1]} | ||
[dest, mag, sources.sort_by{|s,n| - n}] | ||
end | ||
require 'pp' | ||
pp mappings.sort_by{|d,mag,srs| - mag }.reject{|d,mag,srs| (mag < 2 || srs.size == 0)} |
Oops, something went wrong.