What is the opposite of 'parse'?

ParsingLanguage AgnosticSemanticsNaming

Parsing Problem Overview


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?

Parsing Solutions


Solution 1 - Parsing

I think the verb you want is 'compose'.

Solution 2 - Parsing

The opposite of parse is serialize

Solution 3 - Parsing

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.

Solution 4 - Parsing

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.

Solution 5 - Parsing

To complement your existing naming, composeQuery looks best.

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

Solution 6 - Parsing

I would use one of these:

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

Solution 7 - Parsing

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.

Solution 8 - Parsing

The antonym of 'analyze' is 'synthesize'.

Solution 9 - Parsing

ToQueryString()

Solution 10 - Parsing

Definitely Render.

Solution 11 - Parsing

I would call it constructQuery.

Solution 12 - Parsing

generate or emit, possibly.

Solution 13 - Parsing

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.

Solution 14 - Parsing

generateQuery, possibly? createQuery?

Solution 15 - Parsing

Take your pick

  • Generate
  • Dump
  • Serialize
  • Emit

They each have slightly different connotations.

Solution 16 - Parsing

Solution 17 - Parsing

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

Solution 18 - Parsing

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).

Solution 19 - Parsing

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

Solution 20 - Parsing

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

Solution 21 - Parsing

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.

Solution 22 - Parsing

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

Solution 23 - Parsing

I would go for ToString(), since you can usually chain-nest them (opposite functions, that let you pass from Class1 to Class2 and vice-versa)

DateTime.Parse( DateTime.Parse( myDate.ToString() ).ToString() );

Serialize() looks like a nice choice, but it already has an opposite in Deserialize().

In your specific scenario, as other pointed out, ToSql() is another good choice.

Solution 24 - Parsing

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'
    }
}

Solution 25 - Parsing

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

Solution 26 - Parsing

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

Solution 27 - Parsing

What about asSQL() or even more asQuery()?

Solution 28 - Parsing

INHO Serialize, synthesize are good options. Also, as you have named parseQuery, i will go with codeQuery

Solution 29 - Parsing

I usually use "parse" as a conversion method and, therefore, i can't find a opposite word for "convert". (you can't "deconvert" something, as "unconvert" is a type of conversion itself).

thinking this way, the best solution (for me) is having two "parse" methods that receive different arguments. Example (Java):

public class FooBarParser{

    public Foo parse(Bar bar);
    public Bar parse(Foo foo); 
}

Solution 30 - Parsing

deparse

Deparse is to parse, as:

  • decompile is to compile
  • decompose is to compose
  • deserialize is to serialize
  • degroovy is to groovy :) ;)

Parsing / deparsing is not change of structure, but conversion. Precise conversion between equivalent text and abstract-syntax-tree formats, maintaining all relationships & structure.

"Compose" means change of structure, so is not quite right. It suggests combining from separate independent parts (usually for the first time). Just as "decompose" suggests splitting into independent parts. They change form, not just format.

A quick search show's the term's used within:

Solution 31 - Parsing

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.

Solution 32 - Parsing

.GetSqlQuery() would be my choice

Solution 33 - Parsing

I believe the answer you're looking for is: "Don't parse SQL or assemble SQL in the first place. Use an Object/Relational Mapper and stop wasting your employer's money by solving problems that have already been solved for quite some time."

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSimonView Question on Stackoverflow
Solution 1 - ParsingJoel CoehoornView Answer on Stackoverflow
Solution 2 - ParsingYuval AdamView Answer on Stackoverflow
Solution 3 - ParsingBarry KellyView Answer on Stackoverflow
Solution 4 - ParsingMichael BrownView Answer on Stackoverflow
Solution 5 - ParsingdanjaView Answer on Stackoverflow
Solution 6 - ParsingSklivvzView Answer on Stackoverflow
Solution 7 - ParsingKyle CroninView Answer on Stackoverflow
Solution 8 - ParsingMike FView Answer on Stackoverflow
Solution 9 - ParsingplinthView Answer on Stackoverflow
Solution 10 - ParsingAmanda MitchellView Answer on Stackoverflow
Solution 11 - ParsingSecView Answer on Stackoverflow
Solution 12 - ParsingDGentryView Answer on Stackoverflow
Solution 13 - ParsingHenry BView Answer on Stackoverflow
Solution 14 - ParsingDreView Answer on Stackoverflow
Solution 15 - ParsingMike GrahamView Answer on Stackoverflow
Solution 16 - ParsingfheView Answer on Stackoverflow
Solution 17 - ParsingMikeJView Answer on Stackoverflow
Solution 18 - ParsingWalter MittyView Answer on Stackoverflow
Solution 19 - ParsingOmar KoohejiView Answer on Stackoverflow
Solution 20 - ParsingBen HoffsteinView Answer on Stackoverflow
Solution 21 - ParsingJoshView Answer on Stackoverflow
Solution 22 - ParsingChristophe HerremanView Answer on Stackoverflow
Solution 23 - ParsingFiliniView Answer on Stackoverflow
Solution 24 - ParsingHerman JungeView Answer on Stackoverflow
Solution 25 - ParsingTom LahtiView Answer on Stackoverflow
Solution 26 - ParsingGuyView Answer on Stackoverflow
Solution 27 - ParsingMügeView Answer on Stackoverflow
Solution 28 - ParsingmbmihuraView Answer on Stackoverflow
Solution 29 - ParsingDavid PauloView Answer on Stackoverflow
Solution 30 - ParsingGlen BestView Answer on Stackoverflow
Solution 31 - ParsingheliosView Answer on Stackoverflow
Solution 32 - ParsingXaqronView Answer on Stackoverflow
Solution 33 - ParsingchadmyersView Answer on Stackoverflow