4 # Commont parsing classes for symbols/inet
5 # The parsing is simplified, based on regex - it is NOT a real parser for very
17 @includedSyms = Array.new
20 # Write-only property, parent list of symbols definitions
21 def symbols_list=(symbolsList)
22 @symbolsList = symbolsList
25 # Whether this set of symbols is hidden or not
35 # Add "dependency" - the symbols referenced using the "include" statement.
37 def add_included(other)
38 @includedSyms.push(other)
42 alias keys_original keys
45 # Get the symbol, trying first own definitions, then walking through all
49 own = self.get_original(symName)
51 @includedSyms.find_all do | symsName |
52 syms = @symbolsList[symsName]
64 # All keys - including the ones specified in the included sections
67 @includedSyms.inject(keys_original) do | rv, symsName |
68 syms = @symbolsList[symsName]
79 # Size - takes into account overlapping key definitions
86 # Create a hash including all elements of this hash which are not in the
87 # other hash, use symbols + and * for marking the elements which existed in
88 # the original hash (+ if not existed)
92 self.find_all do | key, value |
95 diff[key] = [ value, existing.nil? ? '+' : '' ]
104 # First output included syms
105 @includedSyms.find_all do | symsName |
106 s += " include \"inet(#{symsName})\"\n"
108 # Then - own definitions
109 self.find_all do | key, value |
110 s += " key #{key} { [ #{value} ] };\n"
117 class SymbolsList < Hash
120 # Add new xkb_symbols
122 def add_symbols (symbolsName, hidden)
123 newSyms = Symbols.new
124 newSyms.symbols_list = self
125 newSyms.hidden = hidden
126 self[symbolsName] = newSyms
130 s = "// Autogenerated\n\n"
131 self.find_all do | symbols, mapping |
132 s += "partial alphanumeric_keys\nxkb_symbols \"#{symbols}\" #{mapping};\n\n"
137 def match_symbols(new_symbols,limit)
139 find_all do | symbols, mapping |
140 diff = new_symbols - mapping
141 if diff.size <= limit
142 matching[symbols] = diff
149 everything = NonuniqueCountingHash.new
150 find_all do | symsName, syms |
151 syms.find_all do | symName, keycode |
152 everything[symName] = keycode
163 allSyms = SymbolsList.new;
166 File.open(fileName) do | file |
167 file.each_line do | line |
168 line.scan(/xkb_symbols\s+"(\w+)"/) do | symsName |
169 currentSyms = allSyms.add_symbols(symsName[0], hidden)
171 line.scan(/^\s*key\s*<(\w+)>\s*\{\s*\[\s*(\w+)/) do | keycode, keysym |
172 currentSyms[keycode] = keysym
174 line.scan(/^partial\s+(hidden\s+)?alphanumeric_keys/) do | h |
177 line.scan(/^\s*include\s+"inet\((\w+)\)"/) do | otherPart |
178 currentSyms.add_included(otherPart[0])