0

I am working on a DSL for text processing. The core is searching for regular expressions with some operators around them. These searches are embedded into a more procedural program, which allows for selective execution and setting of metadata. Hopefully, a little snippet gives you an idea how it could look like:

xml_module = import('xml') // various extensions are available to deal with different data formats

// matches when ghi is found at most 5 words away from a match of either abc or def (simplified)
r1 = add_rule('my_rule', [
    distance([
        or([regex('abc'), regex('def')]),
        regex('ghi')
    ]
)

if r1.matched()
    xml.add_tag('root/tag', 'my_value')
endif

The syntax of the DSL is a bit inspired by python. It features statements and expressions and a few select builtin data types. Functions and methods can not be defined by the user.

I am unsure however about the way I should write rules. A rule takes a name and an array of subrules as parameters. Those subrules could be stored in variables to reuse them. It's a tradeoff between loosing readability because all subrule levels are stored in variables, or losing readability because they are all written in place.

Maybe you have some feedback?

3
  • 1
    Are you familiar with awk and sed? You may not like them, but there's a lot to learn there. Particularly awk has something to say about rules and sub-rules and how to do (or how not to do) control flow. If not already familiar, take a look. It's worth seeing what other people did. Commented Jun 4, 2020 at 16:19
  • It sounds like you want to write a tool like Perl. Why not just use Perl? Commented Jun 4, 2020 at 18:59
  • @JamesMcLeod The DSL I am working on will be used by non-programmers. It's severely limited in its expressivness, which is actually a good thing. The features are clearly laid out, however, I'm not entirely happy with the syntax I came up with, especially the construction of rules objects from multiple nested arrays of subrules. Commented Jun 4, 2020 at 19:16

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.