Skip to content

Commit

Permalink
Accept any valid identifier as shogun identifier
Browse files Browse the repository at this point in the history
- This is a (temporary) solution to not use typelist.sh which is not
  portable
  • Loading branch information
lisitsyn authored and vigsterkr committed Mar 10, 2016
1 parent 9698a78 commit f58bcf8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 4 additions & 2 deletions examples/examples_v2/CMakeLists.txt
Expand Up @@ -3,15 +3,17 @@
# Check which interfaces are turned on
# Add CMakeLists file for each turned on interface

# Generate type list
#execute_process(COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/generator/types/get_type_list.sh > ${CMAKE_CURRENT_SOURCE_DIR}/generator/types/typelist)

# Check if PLY is installed
find_package(PLY)
IF(NOT PLY_FOUND)
message(WARNING "Python module PLY was not found. This may cause example generation to be very slow.")
ENDIF()

# Disabled (temporary) as non-portable solution. This is replaced by allowing any [a-zA-Z_][a-zA-Z0-9_]* as shogun keyword
# Generate type list
# execute_process(COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/generator/types/get_type_list.sh > ${CMAKE_CURRENT_SOURCE_DIR}/generator/types/typelist)

# Run example generation script
add_custom_target(shogun_meta_examples
COMMAND ${PYTHON_EXECUTABLE}
Expand Down
15 changes: 9 additions & 6 deletions examples/examples_v2/generator/parse.py
Expand Up @@ -26,12 +26,15 @@ def parse(self, programString, filePath="Unknown"):
def shogunType(self):
basepath = os.path.dirname(__file__)
type = self.pp.Forward()
with open(os.path.join(basepath,"types/typelist"), "r") as typelist:
for line in typelist:
# Make sure the line is not an empty string
if line.replace('\n', '') != '':
type = type ^ self.pp.Literal(line.replace('\n', ''))

# This is probably a temporary solution, we treat any [a-zA-Z_][a-zA-Z0-9_]* as valid shogun keyword
type = type ^ self.pp.Word(self.pp.srange("[a-zA-Z_]"), self.pp.srange("[a-zA-Z0-9_]"))

# with open(os.path.join(basepath,"types/typelist"), "r") as typelist:
# for line in typelist:
# # Make sure the line is not an empty string
# if line.replace('\n', '') != '':
# type = type ^ self.pp.Literal(line.replace('\n', ''))
return type

def grammar(self):
Expand Down Expand Up @@ -426,4 +429,4 @@ def parse(programString, filePath):
# Parse input and print json output
program = parse(programString, filePath)

print json.dumps(program, indent=indentWidth)
print json.dumps(program, indent=indentWidth)

0 comments on commit f58bcf8

Please sign in to comment.