Skip to content

Commit

Permalink
WIP: Lower-case function definitions (TriBITSPub#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlettroscoe committed Jun 16, 2021
1 parent 0ee9dac commit 8e869a2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
50 changes: 50 additions & 0 deletions test/python_utils/lower_case_cmake_UnitTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,56 @@ def test_macro_def_1(self):
cmakeCodeStrOut = LCC.makeCmndsLowerCaseInCMakeStr(cmakeCodeStrIn)
self.assertEqual(cmakeCodeStrOut, cmakeCodeStrOut_expected)

def test_function_def_1(self):
cmakeCodeStrIn = "\n"+\
"# Some function we are defining\n"+\
"#\n"+\
"# Usage::\n"+\
"#\n"+\
"# SOME_FUNCTION(<some_args>)\n"+\
"#\n"+\
"Function(Some_Function1 ARG1 ARG2)\n"+\
" #SOME_CALL()\n"+\
"EndFunction()\n"+\
"\n"+\
"FUNCTION (Some_Function2)\n"+\
"ENDFUNCTION()\n"+\
"\n"+\
"function\n"+\
" (SOME_FUNCTION3)\n"+\
"ENDFUNCTION()\n"+\
"\n"+\
"FUNCTION\n"+\
" (\n"+\
" SOME_FUNCTION4)\n"+\
"ENDFUNCTION()\n"+\
"\n"
cmakeCodeStrOut_expected = "\n"+\
"# Some function we are defining\n"+\
"#\n"+\
"# Usage::\n"+\
"#\n"+\
"# some_function(<some_args>)\n"+\
"#\n"+\
"function(some_function1 ARG1 ARG2)\n"+\
" #some_call()\n"+\
"endfunction()\n"+\
"\n"+\
"function (some_function2)\n"+\
"endfunction()\n"+\
"\n"+\
"function\n"+\
" (some_function3)\n"+\
"endfunction()\n"+\
"\n"+\
"function\n"+\
" (\n"+\
" some_function4)\n"+\
"endfunction()\n"+\
"\n"
cmakeCodeStrOut = LCC.makeCmndsLowerCaseInCMakeStr(cmakeCodeStrIn)
self.assertEqual(cmakeCodeStrOut, cmakeCodeStrOut_expected)


if __name__ == '__main__':
unittest.main()
9 changes: 7 additions & 2 deletions tribits/python_utils/lower_case_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
#
def makeCmndsLowerCaseInCMakeStr(cmakeCodeStrIn):
cmakeCodeStrOut = cmakeCodeStrIn
# Regex for a command name in CMake: [COMMAND_NAME(]
# Lower-case command call in CMake: [COMMAND_NAME(]
cmakeCodeStrOut = makeRegexMatchesLowerCaseInCMakeStr(
cmakeCodeStrOut,
re.compile(r'[a-zA-Z_][a-zA-Z0-9_]*[\s]*\(', re.DOTALL) )
# Regex for a macro defintion: [COMMAND_NAME(]
# Lower-case macro defintion in CMake: [MACRO(COMMAND_NAME]
cmakeCodeStrOut = makeRegexMatchesLowerCaseInCMakeStr(
cmakeCodeStrOut,
re.compile(r'[mM][aA][cC][rR][oO][\s]*\([\s]*[a-zA-Z_][a-zA-Z0-9_]*', re.DOTALL) )
# Lower-case function defintion: [FUNCTION(COMMAND_NAME]
cmakeCodeStrOut = makeRegexMatchesLowerCaseInCMakeStr(
cmakeCodeStrOut,
re.compile(r'[fF][uU][nN][cC][tT][iI][oO][nN][\s]*\([\s]*[a-zA-Z_][a-zA-Z0-9_]*',
re.DOTALL) )
return cmakeCodeStrOut


Expand Down

0 comments on commit 8e869a2

Please sign in to comment.