Hacker News new | past | comments | ask | show | jobs | submit login

You should check out OMetaJS http://www.tinlizzie.org/ometa/ It's an object oriented parser-compiler for building languages (DSLs?) inside a host language. JS is a supported host language.

Ah, but I'm thinking real Javascript, J-expression[1] style. Something like this:

      `I stared at Monsieur Fogg.`,
        if: `know_about_wager`,
        then: [`<> "But surely you are not serious?" I demanded.`],
        else: [`<> "But there must be a reason for this trip," I observed.`]
      `He said nothing in reply, merely considering his newspaper with as much
      thoroughness as entomologist considering his latest pinned addition.`
Or, more complicated:

      `I looked at Monsieur Fogg `,
      {choose: [
        `... and I could contain myself no longer.`,
        `What is the purpose of our journey, Monsieur?`,
        `'A wager,' he replied.`,
        {choose: [
          `'A wager!'[] I returned.`,
          `He nodded.`,
          {choose: `'But surely that is foolishness!'`},
          {choose: [`'A most serious matter then!'`, `He nodded again.`]},
          {choose: [
            `'But can we win?'`,
            `'That is what we will endeavour to find out,' he answered.`
          {choose: [
            `'A modest wager, I trust?'`,
            `'Twenty thousand pounds,' he replied, quite flatly.`
          {choose: `I asked nothing further of him then[.], and after a final, polite cough, he offered nothing more to me. <>`}
        {choose: `'Ah[.'],' I replied, uncertain what I thought.`},
        `After that, <>`
      {choose: `... but I said nothing[] and <>`},
      `we passed the day in silence.`,
      {goto: 'END'}
[1]: http://sriku.org/blog/2012/04/15/j-expressions/

Maybe as a first step... but seems like a "real" DSL would have a lot of benefits... maybe it even compiles to something like your example? Anyway, just thinking out loud... not a critique.

I recommend Ohm instead (made by the same people who made OMeta), which I see as OMeta's successor: github.com/harc/ohm

Ah! I didn't know it existed... I will read about it. Thanks.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact