4 # Commont parsing classes for symbols/inet
5 # The parsing is simplified, based on regex - it is NOT a real parser for very
15 @includedSyms = Array.new
18 # Write-only property, parent list of symbols definitions
19 def symbols_list=(symbolsList)
20 @symbolsList = symbolsList
23 # Whether this set of symbols is hidden or not
33 # Add "dependency" - the symbols referenced using the "include" statement.
35 def add_included(other)
36 @includedSyms.push(other)
42 # Get the symbol, trying first own definitions, then walking through all
46 own = self.get_original(symName)
48 @includedSyms.find_all do | symsName |
49 syms = @symbolsList[symsName]
61 # Create a hash including all elements of this hash which are not in the
62 # other hash, use symbols + and * for marking the elements which existed in
63 # the original hash (+ if not existed)
67 self.find_all do | key, value |
70 diff[key] = [ value, existing.nil? ? '+' : '' ]
79 # First output included syms
80 @includedSyms.find_all do | symsName |
81 s += " include \"inet(#{symsName})\"\n"
83 # Then - own definitions
84 self.find_all do | key, value |
85 s += " key #{key} { [ #{value} ] };\n"
92 class SymbolsList < Hash
97 def add_symbols (symbolsName, hidden)
99 newSyms.symbols_list = self
100 newSyms.hidden = hidden
101 self[symbolsName] = newSyms
105 s = "// Autogenerated\n\n"
106 self.find_all do | symbols, mapping |
107 s += "partial alphanumeric_keys\nxkb_symbols \"#{symbols}\" #{mapping};\n\n"
112 def match_symbols(new_symbols,limit)
114 find_all do | symbols, mapping |
115 diff = new_symbols - mapping
116 if diff.size <= limit
117 matching[symbols] = diff
128 allSyms = SymbolsList.new;
131 File.open(fileName) do | file |
132 file.each_line do | line |
133 line.scan(/xkb_symbols\s+"(\w+)"/) do | symsName |
134 currentSyms = allSyms.add_symbols(symsName[0], hidden)
136 line.scan(/^\s*key\s*<(\w+)>\s*\{\s*\[\s*(\w+)/) do | keycode, keysym |
137 currentSyms[keycode] = keysym
139 line.scan(/^partial\s+(hidden\s+)?alphanumeric_keys/) do | h |
142 line.scan(/^\s*include\s+"inet\((\w+)\)"/) do | otherPart |
143 currentSyms.add_included(otherPart[0])