util.js
function parse (code) {
  Object.keys(syntax).forEach((s) => {
    code = code.replace(syntax[s], (_, m) => {
      // ensure if the regex only matches part of the string that we keep the leftover
      let leftOver = _.replace(m, '')
      // encode the string and class
      let parsed = `{#${s}#${encode(m)}#}`

      if (s === 'function' && leftOver) {
        // we want to parse sub commands and the easiest way to do that is to
        // run over the leftOver portion of the function call with the same regex
        let startingParenthesis = leftOver.indexOf('(')
        let endingParenthesis = leftOver.lastIndexOf(')')
        let endingComma = leftOver.lastIndexOf(';')

        // since we don't want to create a new string for every operation
        // we can simply walk the string and replace the character that needs it
        let subFunction = leftOver.replace(/./g, (c, i) => {
          // we can define a waterfall case that only replaces the three positions with nothing
          // leaving the other characters in their place
          switch (i) {
            case startingParenthesis:
            case endingParenthesis:
            case endingComma:
              return ''
            default:
              return c
          }
        })
        leftOver = `(${parse(subFunction)})${endingComma > -1 ? ';' : ''}`
      }
      return parsed + leftOver
    })
  })
  return code
}
function parse (code) {
  Object.keys(syntax).forEach((s) => {
    code = code.replace(syntax[s], (_, m) => {
      // ensure if the regex only matches part of the string that we keep the leftover
      let leftOver = _.replace(m, '')
      // encode the string and class
      let parsed = `{#${s}#${encode(m)}#}`

      if (s === 'function' && leftOver) {
        // we want to parse sub commands and the easiest way to do that is to
        // run over the leftOver portion of the function call with the same regex
        let startingParenthesis = leftOver.indexOf('(')
        let endingParenthesis = leftOver.lastIndexOf(')')
        let endingComma = leftOver.lastIndexOf(';')

        // since we don't want to create a new string for every operation
        // we can simply walk the string and replace the character that needs it
        let subFunction = leftOver.replace(/./g, (c, i) => {
          // we can define a waterfall case that only replaces the three positions with nothing
          // leaving the other characters in their place
          switch (i) {
            case startingParenthesis:
            case endingParenthesis:
            case endingComma:
              return ''
            default:
              return c
          }
        })
        leftOver = `(${parse(subFunction)})${endingComma > -1 ? ';' : ''}`
      }
      return parsed + leftOver
    })
  })
  return code
}
function parse ( code ) { Object . keys ( syntax ) . forEach ( ( s ) => { code = code . replace ( syntax [ s ] , ( _ , m ) => { // ensure if the regex only matches part of the string that we keep the leftover let leftOver = _ . replace ( m , '' ) // encode the string and class let parsed = ` ${ s } ${ encode ( m ) } ` if ( s === 'function' && leftOver ) { // we want to parse sub commands and the easiest way to do that is to // run over the leftOver portion of the function call with the same regex let startingParenthesis = leftOver . indexOf ( '(' ) let endingParenthesis = leftOver . lastIndexOf ( ')' ) let endingComma = leftOver . lastIndexOf ( ';' ) // since we don't want to create a new string for every operation // we can simply walk the string and replace the character that needs it let subFunction = leftOver . replace ( / . / g , ( c , i ) => { // we can define a waterfall case that only replaces the three positions with nothing // leaving the other characters in their place switch ( i ) { case startingParenthesis : case endingParenthesis : case endingComma : return '' default : return c } } ) leftOver = ` ${ parse ( subFunction ) } ${ endingComma > - 1 ? ';' : '' } ` } return parsed + leftOver } ) } ) return code }
walks through the syntaxes that we have and tokenizes the entities that correspond
@method parse
@param  {String} code - raw code string
@return {String} - encoded code string
walks through the syntaxes that we have and tokenizes the entities that correspond