From e282437a5b7c2075d78b09ae3fcc5c5fc0cfad7e Mon Sep 17 00:00:00 2001
From: Henning Glawe <glaweh@debian.org>
Date: Fri, 28 Oct 2016 11:31:39 +0200
Subject: [PATCH] add literal2python method, converts literal match object to
 appropriate python types/values

---
 parser/parser-fplo/FploInputParser.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/parser/parser-fplo/FploInputParser.py b/parser/parser-fplo/FploInputParser.py
index 14b5cf4..2a1949d 100755
--- a/parser/parser-fplo/FploInputParser.py
+++ b/parser/parser-fplo/FploInputParser.py
@@ -93,12 +93,33 @@ class FploInputParser(object):
             m = cRE_end_newline.match(what)
             self.__annotateFile.write(highlight + m.group(1) + ANSI.RESET + m.group(2))
 
+    def literal2python(self, match):
+        if match.group('str_d') is not None:
+            return match.group('str_d')
+        if match.group('str_s') is not None:
+            return match.group('str_s')
+        if match.group('float') is not None:
+            return float(match.group('float'))
+        if match.group('hex_int') is not None:
+            return int(match.group('hex_int'), base=16)
+        if match.group('octal_int') is not None:
+            return int(match.group('octal_int'), base=8)
+        if match.group('decimal_int') is not None:
+            return int(match.group('decimal_int'))
+        if match.group('logical') is not None:
+            if match.group('logical') == 't':
+                return True
+            else:
+                return False
+        raise RuntimeError('no idea what to do with literal "%s"' % (match.group(0)))
+
     def state_root(self, line, pos_in_line):
         """state: no open section, i.e. at the root of the namelist"""
         # match literals
         m = cRE_literal.match(line, pos_in_line)
         if m is not None:
             self.annotate(m.group(), ANSI.FG_MAGENTA)
+            lit = self.literal2python(m)
             return m.end()
         # match identifier or keyword
         m = cRE_kw_ident.match(line, pos_in_line)
-- 
GitLab