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 637867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:40:14+00:00 2026-05-13T20:40:14+00:00

I’m looking to speed along my discovery process here quite a bit, as this

  • 0

I’m looking to speed along my discovery process here quite a bit, as this is my first venture into the world of lexical analysis. Maybe this is even the wrong path. First, I’ll describe my problem:

I’ve got very large properties files (in the order of 1,000 properties), which when distilled, are really just about 15 important properties and the rest can be generated or rarely ever change.

So, for example:

general {
  name = myname
  ip = 127.0.0.1
}

component1 {
   key = value
   foo = bar
}

This is the type of format I want to create to tokenize something like:

property.${general.name}blah.home.directory = /blah
property.${general.name}.ip = ${general.ip}
property.${component1}.ip = ${general.ip}
property.${component1}.foo = ${component1.foo}

into

property.mynameblah.home.directory = /blah
property.myname.ip = 127.0.0.1
property.component1.ip = 127.0.0.1
property.component1.foo = bar

Lexical analysis and tokenization sounds like my best route, but this is a very simple form of it. It’s a simple grammar, a simple substitution and I’d like to make sure that I’m not bringing a sledgehammer to knock in a nail.

I could create my own lexer and tokenizer, or ANTlr is a possibility, but I don’t like re-inventing the wheel and ANTlr sounds like overkill.

I’m not familiar with compiler techniques, so pointers in the right direction & code would be most appreciated.

Note: I can change the input format.

  • 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-05-13T20:40:15+00:00Added an answer on May 13, 2026 at 8:40 pm

    There’s an excellent article on Using Regular Expressions for Lexical Analysis at effbot.org.

    Adapting the tokenizer to your problem:

    import re
    
    token_pattern = r"""
    (?P<identifier>[a-zA-Z_][a-zA-Z0-9_]*)
    |(?P<integer>[0-9]+)
    |(?P<dot>\.)
    |(?P<open_variable>[$][{])
    |(?P<open_curly>[{])
    |(?P<close_curly>[}])
    |(?P<newline>\n)
    |(?P<whitespace>\s+)
    |(?P<equals>[=])
    |(?P<slash>[/])
    """
    
    token_re = re.compile(token_pattern, re.VERBOSE)
    
    class TokenizerException(Exception): pass
    
    def tokenize(text):
        pos = 0
        while True:
            m = token_re.match(text, pos)
            if not m: break
            pos = m.end()
            tokname = m.lastgroup
            tokvalue = m.group(tokname)
            yield tokname, tokvalue
        if pos != len(text):
            raise TokenizerException('tokenizer stopped at pos %r of %r' % (
                pos, len(text)))
    

    To test it, we do:

    stuff = r'property.${general.name}.ip = ${general.ip}'
    stuff2 = r'''
    general {
      name = myname
      ip = 127.0.0.1
    }
    '''
    
    print ' stuff '.center(60, '=')
    for tok in tokenize(stuff):
        print tok
    
    print ' stuff2 '.center(60, '=')
    for tok in tokenize(stuff2):
        print tok
    

    for:

    ========================== stuff ===========================
    ('identifier', 'property')
    ('dot', '.')
    ('open_variable', '${')
    ('identifier', 'general')
    ('dot', '.')
    ('identifier', 'name')
    ('close_curly', '}')
    ('dot', '.')
    ('identifier', 'ip')
    ('whitespace', ' ')
    ('equals', '=')
    ('whitespace', ' ')
    ('open_variable', '${')
    ('identifier', 'general')
    ('dot', '.')
    ('identifier', 'ip')
    ('close_curly', '}')
    ========================== stuff2 ==========================
    ('newline', '\n')
    ('identifier', 'general')
    ('whitespace', ' ')
    ('open_curly', '{')
    ('newline', '\n')
    ('whitespace', '  ')
    ('identifier', 'name')
    ('whitespace', ' ')
    ('equals', '=')
    ('whitespace', ' ')
    ('identifier', 'myname')
    ('newline', '\n')
    ('whitespace', '  ')
    ('identifier', 'ip')
    ('whitespace', ' ')
    ('equals', '=')
    ('whitespace', ' ')
    ('integer', '127')
    ('dot', '.')
    ('integer', '0')
    ('dot', '.')
    ('integer', '0')
    ('dot', '.')
    ('integer', '1')
    ('newline', '\n')
    ('close_curly', '}')
    ('newline', '\n')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
We're building an app, our first using Rails 3, and we're having to build

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.