X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=kll.py;h=37cfd5fc285c8d354491726e983c6b96d2f27cac;hb=0cb66411aad82f7bf9fa20e4942be9bacefcfa86;hp=76dc3b50da92e8564a2e9275d4c89bf47a17fe02;hpb=6454917b11f89eb345d57daf9976ecfeab6509dc;p=kiibohd-kll.git diff --git a/kll.py b/kll.py index 76dc3b5..37cfd5f 100755 --- a/kll.py +++ b/kll.py @@ -2,7 +2,7 @@ # KLL Compiler # Keyboard Layout Langauge # -# Copyright (C) 2014 by Jacob Alexander +# Copyright (C) 2014-2015 by Jacob Alexander # # This file is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -387,7 +387,6 @@ def optionExpansion( sequences ): curLeafList[ leaf ] = 0 if leaf + 1 < len( curLeafList ): curLeafList[ leaf + 1 ] += 1 - break return expandedSequences @@ -553,8 +552,37 @@ def processKLLFile( filename ): data = file.read() tokenSequence = tokenize( data ) #print ( pformat( tokenSequence ) ) # Display tokenization - tree = parse( tokenSequence ) + try: + tree = parse( tokenSequence ) + except NoParseError as e: + print("Error parsing %s. %s" % (filename, e.msg), file=sys.stderr) + sys.exit(1) + + +### Misc Utility Functions ### + +def gitRevision( kllPath ): + import subprocess + + # Change the path to where kll.py is + origPath = os.getcwd() + os.chdir( kllPath ) + # Just in case git can't be found + try: + # Get hash of the latest git commit + revision = subprocess.check_output( ['git', 'rev-parse', 'HEAD'] ).decode()[:-1] + + # Get list of files that have changed since the commit + changed = subprocess.check_output( ['git', 'diff-index', '--name-only', 'HEAD', '--'] ).decode().splitlines() + except: + revision = "" + changed = [] + + # Change back to the old working directory + os.chdir( origPath ) + + return revision, changed ### Main Entry Point ### @@ -562,6 +590,9 @@ def processKLLFile( filename ): if __name__ == '__main__': (baseFiles, defaultFiles, partialFileSets, backend_name, template, defines_template, output, defines_output) = processCommandLineArgs() + # Look up git information on the compiler + gitRev, gitChanges = gitRevision( os.path.dirname( os.path.realpath( __file__ ) ) ) + # Load backend module global backend backend_import = importlib.import_module( "backends.{0}".format( backend_name ) ) @@ -601,7 +632,13 @@ if __name__ == '__main__': macros_map.generate() # Process needed templating variables using backend - backend.process( capabilities_dict, macros_map, variables_dict ) + backend.process( + capabilities_dict, + macros_map, + variables_dict, + gitRev, + gitChanges + ) # Generate output file using template and backend backend.generate( output, defines_output )