Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8251861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:22:31+00:00 2026-06-08T00:22:31+00:00

I have config files structured like simplified C syntax, eg: Main { /* some

  • 0

I have config files structured like simplified C syntax, eg:

Main { /* some comments */
    VariableName1 = VariableValue1;
    VariableName2 = VariableValue2;

    SubSection {
        VariableName1 = VariableValue1; // inline comment
        VariableName2 = VariableValue2;
    }

    VariableName3 = "StriingValue4";
}

Sections may be recursivesly nested.

How can I parse that file into dict in a clean and “pythonish” way?

[EDIT]

OK, I’ve found pyparsing module 🙂 but maybe someone can tell how to do this without it.

[EDIT2]

Because of curiosity, I want to know for future how to write that I think simple task by hand.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:22:33+00:00Added an answer on June 8, 2026 at 12:22 am

    Use a parser like SimpleParse, just feed it the EBNF definition.

    Do you have the format documented in some sort of BNF, don’t you? If not, you can tell the next genius inventing another config format instead of using json, xml, yaml or xml that he is not authorized to reinvent the wheel unless he can specify the syntax using EBNF.

    It may take some time to write a grammar if you are not familiarized with EBNF, but it pays. It will make your code well documented, rock solid and easier to maintain.

    See the python wiki about Language Parsing for another options.

    If you try to pull some stunt using str.split or regular expressions, every other developer to do maintenance of this piece of code will curse you.

    UPDATE:

    It just occurred to me that if you replace the SectionName with SectionName :, ; with , and enclose the main section with a pair of curly braces, this format will likely to be valid json.

    "Name"     = JSON Grammar
    "Author"   = Arsène von Wyss
    "Version"  = 1.0
    "About"    = 'Grammar for JSON data, following http://www.json.org/'
    ! and compliant with http://www.ietf.org/rfc/rfc4627
    
    "Start Symbol" = <Json>
    "Case Sensitive" = True
    "Character Mapping" = 'Unicode'
    
    ! ------------------------------------------------- Sets
    
    {Unescaped} = {All Valid} - {&1 .. &19} - ["\]
    {Hex} = {Digit} + [ABCDEFabcdef]
    {Digit9} = {Digit} - [0]
    
    ! ------------------------------------------------- Terminals
    
    Number = '-'?('0'|{Digit9}{Digit}*)('.'{Digit}+)?([Ee][+-]?{Digit}+)?
    String = '"'({Unescaped}|'\'(["\/bfnrt]|'u'{Hex}{Hex}{Hex}{Hex}))*'"'
    
    ! ------------------------------------------------- Rules
    
    <Json> ::= <Object>
             | <Array>
    
    <Object> ::= '{' '}'
               | '{' <Members> '}'
    
    <Members> ::= <Pair>
                | <Pair> ',' <Members>
    
    <Pair> ::= String ':' <Value>
    
    <Array> ::= '[' ']'
              | '[' <Elements> ']'
    
    <Elements> ::= <Value>
                 | <Value> ',' <Elements>
    
    <Value> ::= String
              | Number
              | <Object>
              | <Array>
              | true
              | false
              | null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web directory where I store some config files. I'd like to
I have seen config files(yes, text files) for various console applications that look like
following is my files directory structure... Config config.php (is calling some files too like
In a complex project, I have many XML files like data files, config files
I have a file system structure with symlinks, something like this: folder123 index.php config.php
We have multiple config files (app.DEV.config, app.TEST.config, etc) and a pre-build event that copies
In my home folder in Linux I have several config files that have rc
Is it possible to have two app.config files where one app.config serves as a
In the Setup Project I have 2 web.config files: web.config - used during the
I have a windows service where the app.config file and the log4net.config files are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.