elif operator == ":":
macros_map.replaceScanCode( trigger, result )
- print ( triggers )
- print ( results )
-
def eval_usbCode( triggers, operator, results ):
# Convert to lists of lists of lists to tuples of tuples of tuples
# Tuples are non-mutable, and can be used has index items
scanCodes = macros_map.lookupUSBCodes( trigger )
for scanCode in scanCodes:
for result in results:
- # Append Case
- if operator == ":+":
- macros_map.appendScanCode( scanCode, result )
-
- # Remove Case
- elif operator == ":-":
- macros_map.removeScanCode( scanCode, result )
-
- # Replace Case
- elif operator == ":":
- macros_map.replaceScanCode( scanCode, result )
-
- print ( triggers )
- print ( results )
+ # Cache assignment until file finishes processing
+ macros_map.cacheAssignment( operator, scanCode, result )
def eval_variable( name, content ):
# Content might be a concatenation of multiple data types, convert everything into a single string
#| <trigger> : <result>;
operatorTriggerResult = operator(':') | operator(':+') | operator(':-')
-scanCode_expression = triggerCode_outerList + operatorTriggerResult + resultCode_outerList + skip( eol ) >> map_scanCode
-usbCode_expression = triggerUSBCode_outerList + operatorTriggerResult + resultCode_outerList + skip( eol ) #>> map_usbCode
+scanCode_expression = triggerCode_outerList + operatorTriggerResult + resultCode_outerList + skip( eol ) >> map_scanCode
+usbCode_expression = triggerUSBCode_outerList + operatorTriggerResult + resultCode_outerList + skip( eol ) >> map_usbCode
def parse( tokenSequence ):
"""Sequence(Token) -> object"""
+def processKLLFile( filename ):
+ with open( filename ) as file:
+ data = file.read()
+ tokenSequence = tokenize( data )
+ #print ( pformat( tokenSequence ) ) # Display tokenization
+ tree = parse( tokenSequence )
+
+ # Apply assignment cache, see 5.1.2 USB Codes for why this is necessary
+ macros_map.replayCachedAssignments()
+
+
+
### Main Entry Point ###
if __name__ == '__main__':
backend_import = importlib.import_module( "backends.{0}".format( backend_name ) )
backend = backend_import.Backend( template )
- #TODO Move elsewhere
+ # Default combined layer
for filename in defaultFiles:
- with open( filename ) as file:
- data = file.read()
-
- tokenSequence = tokenize( data )
- print ( pformat( tokenSequence ) ) # Display tokenization
- tree = parse( tokenSequence )
- #print ( tree )
- #print ( variable_dict )
- #print ( capabilities_dict )
+ processKLLFile( filename )
+
+ # Iterate through additional layers
+ for partial in partialFileSets:
+ # Increment layer for each -p option
+ macros_map.addLayer()
+
+ # Iterate and process each of the file in the layer
+ for filename in partial:
+ processKLLFile( filename )
# Do macro correlation and transformation
macros_map.generate()