What is the opposite of 'parse'?

Viewed 44267

I have a function, parseQuery, that parses a SQL query into an abstract representation of that query.

I'm about to write a function that takes an abstract representation of a query and returns a SQL query string.

What should I call the second function?

33 Answers

I think the verb you want is 'compose'.

The opposite of parse is serialize

In compiler terminology, the opposite is "unparse". Specifically, parsing turns a stream of tokens into abstract syntax trees, while unparsing turns abstract syntax trees into a stream of tokens.

Compose? When parsing a query you break it into its constituent parts (tokens, etc.), the reverse would be composing the parts into a string query.

To complement your existing naming, composeQuery looks best.

But in the general case, the opposite of parse is ǝsɹɐd

I would use one of these:

  • ToString()
  • ToSQL()
  • Render()

I think "serialize" is probably the word you want. It means to produce a textual representation of data that can be exported (and imported) from the program.

The antonym of 'analyze' is 'synthesize'.

I would call it constructQuery.

Just to add some stuff.

Surely parse is a two way word.

You can parse an abstract into a query.

You can parse a query into an abstract.

The question should be, what do you name the latter part of the method, and because in this instance you're parsing an abstract to make a query you'd call it parseAbstract.

To answer the question, parsing has no opposite.

generateQuery, possibly? createQuery?

Take your pick

  • Generate
  • Dump
  • Serialize
  • Emit

They each have slightly different connotations.

compose, construct, generate, render,condense, reduce, toSQL, toString depending on the nature of the class and its related operators

A traditional compiler has two parts: a parser and a code generator.

So you could call it "Generate". Of course, it's a little bit different here because the compiler isn't writing source code. (unless it's a precompiler).

Possibly Format(). or ToSQL() in your instance?

unParse()? Just kidding, I would go with toQueryString()

flatten?

The parsed query object perhaps represents a condition hierarchy, which you are "flattening" back into a 1 dimensional string.

But given that you're going from object to string, really just use toString or toSQL() or something like that. Besides, if you designed it well and are using the right app, you can rename it later and just stick stuff in the comments on what it does.

I'd say serialize and deserialize, instead of parse and ...

I'd use render

> a = 'html': { 'head': {'title': 'My Page'}, 'body': { 'h1': 'Hello World', 'p': 'This is a Paragraph' } }

> b = render(a)

> console.log(b)

<html>
    <head>
        <title>My Page</title>
    </head>
    <body>
        <h1>Hello World</h1>
        <p>This is a Paragraph</p>
    </body>
</html>

Which is IMHO, the opposite to parse()

> c = parse(b)

{ 'html': {
    'head': {
        'title': 'My Page'
    }
    'body': {
        'h1': 'Hello World',
        'p': 'This is a Paragraph'
    }
}

+1 for Generate, but tack on what you're generating, i.e. GenerateSQL()

I voted for 'compose' but if you don't like that I would also suggest 'build'

writeQuery. Parse is the act of reading it from a string and creating the object (let's say 'actual') representation. The opposite would be writing the object into a string.

Related