Created
January 6, 2020 01:53
-
-
Save allison-casey/0cc29d9da8d8c47b680125848bf3f99d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import [pyparsing :as pp]) | |
(with [f (open "config.cpp")] | |
(setv config (.readlines f))) | |
(setv colon ":" | |
open-curly "{" | |
klass (pp.CaselessKeyword "class") | |
klass-name ((pp.Word (+ pp.alphanums "_")) "class_name") | |
base-klass ((pp.Word (+ pp.alphanums "_")) "base_class") | |
klass-parser (| (+ klass klass-name open-curly) | |
(+ klass klass-name colon base-klass open-curly))) | |
(defn parse-line | |
[line] | |
(try | |
(setv parsed-line (.parseString klass-parser line)) | |
{:class-name (get parsed-line "class_name") | |
:base-class-name (when (in "base_class" parsed-line) | |
(get parsed-line "base_class"))} | |
(except [pp.ParseException] | |
{:class-name None | |
:base-class-name None}))) | |
(get (.parseString klass-parser (get config 1)) "base_class") | |
(when False) | |
(get config 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment