当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Parser.parse方法代码示例

本文整理汇总了TypeScript中et-parser.Parser.parse方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Parser.parse方法的具体用法?TypeScript Parser.parse怎么用?TypeScript Parser.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在et-parser.Parser的用法示例。


在下文中一共展示了Parser.parse方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: parseAttributes

export function parseAttributes (source: string) {
  let result = new AttributesResult()
  parser.parse(source, (state, token) => {
    switch (state) {
      case 'scan':
      case 'keyEnd':
      case 'ignore':
        break
      case '_str':
      case 'key':
      case 'value{{':
      case 'value':
      case 'value\'':
      case 'value"':
        result.addToken(token)
        break
      case 'keyStart':
        result.createOne()
        result.state = ATTRIBUTES_STATE.Key
        result.addToken(token)
        break
      case 'valueStart':
        result.state = ATTRIBUTES_STATE.Value
        break
      case 'valueEnd':
      case 'value\'End':
      case 'value"End':
        result.state = ATTRIBUTES_STATE.Scan
        break
      default:
        throw new Error(`The state: '${state}' is not defined.`)
    }
  })
  return result.getAttributes()
}
开发者ID:et-studio,项目名称:et-template,代码行数:35,代码来源:index.ts

示例2: parseFor

export function parseFor (source: string) {
  let item = '';
  let index = '';
  let expression = '';
  let trackBy = '';

  parser.parse(source, (state, token) => {
    switch (state) {
      case 'ignore':
      case 'indexPre':
      case 'indexEnd':
        break;
      case 'item':
        item += token;
        break;
      case 'index':
        index += token;
        break;
      case '_str1':
      case '_str2':
      case 'expression':
        expression += token;
        break;
      case 'trackBy':
        trackBy += token;
        break;
      default:
        throw new Error(`parse_for_${state}`)
    }
  })

  if (!index) index = '_index';
  return {item, index, expression, trackBy}
}
开发者ID:et-studio,项目名称:et-template,代码行数:34,代码来源:for.ts

示例3: parseValue

export function parseValue (source: string) {
  let result = new ValueResult()
  let value = ''

  parser.parse(source, (state, token) => {
    switch (state) {
      case '_str1':
      case '_str2':
      case 'text':
      case 'value':
      case 'method':
      case 'argument':
        result.addToken(token)
        break
      case 'start':
        result.state = VALUE_STATES.value
        result.addToken('')
        break
      case 'pipe':
        result.state = VALUE_STATES.pipe
        result.createPipe()
        break
      case 'split':
        result.splitPipe()
        break
      case 'end':
        result.state = VALUE_STATES.text
        break
      case 'cancel':
        result.cancel()
        result.state = VALUE_STATES.value
        break
      default:
        throw new Error(`parse_value_parse_${state}`)
    }
  })

  if (result.state !== VALUE_STATES.text) {
    result.cancel()
  }

  let re: IValueResult = result.format()
  return re
}
开发者ID:et-studio,项目名称:et-template,代码行数:44,代码来源:index.ts

示例4: wrap

export function wrap (source: string) {
  let result = ''
  wrapParser.parse(source, (state, token) => {
    switch (state) {
      case 'single':
        result += "\\'"
        break
      case 'break':
        result += '\\n'
        break
      case 'text':
        result += token
        break
      default:
        throw new Error(`parse_value_wrap_${state}`)
    }
  })
  return `'${result}'`
}
开发者ID:et-studio,项目名称:et-template,代码行数:19,代码来源:wrap.ts

示例5: parseDep

export function parseDep (source: string) {
  let result = ''
  let methods: string[] = []
  let method = '';
  parser.parse(source, function (state, token) {
    switch (state) {
      case '_str1':
      case '_str2':
      case 'text':
        result += token
        break;
      case 'start':
      case 'cancel':
        result += (method + token)
        method = '';
        break;
      case 'method':
        method += token;
        break;
      case 'end':
        result = result.substr(0, result.length - SYMBOL.length)
        result += `_dep_${method}${token}`
        methods.push(method.trim());
        method = '';
        break;
      default:
        throw new Error(`The state: '${state}' is not defined.`)
    }
  })

  forEachRight(uniq(methods), (item) => {
    if (item) {
      result = `var _dep_${item} = _dep.${item};\n` + result
    }
  })
  return result
}
开发者ID:et-studio,项目名称:et-template,代码行数:37,代码来源:dep.ts

示例6: parseOrigin

export function parseOrigin (source: string) {
  let root = new Node()
  let current = root
  let tail = ''

  parser.parse(source, (state: string, token: string, index: number) => {
    switch (state) {
      case '_ignore':
        break
      case 'text':
      case '_str[':
      case '_str{{':
      case '_str1':
      case '_str2':
      case 'name':
      case 'source':
      case 'etName':
      case 'etSource':
        current.addSource(token)
        break
      case 'start':
        current = current.createChild()
        current.addSource(token)
        current.state = 1
        break
      case 'etStart':
        current = current.createChild()
        current.addSource(token)
        current.nodeName = '#'
        current.state = NODE_STATE.NodeName
        break
      case 'nameEnd':
      case 'etNameEnd':
        current.state = NODE_STATE.Source
        current.addSource(token)
        break
      case 'nodeEnd':
      case 'etEnd':
        current.state = NODE_STATE.Header
        current.addSource(token)
        current.state = NODE_STATE.Body
        break
      case 'tail':
      case 'etTail':
        tail += token
        break
      case 'tailEnd':
        current = current.closeNode(tail + token)
        tail = ''
        break
      case 'etTailEnd':
        current = current.closeNode(tail + token)
        tail = ''
        if (current.state === NODE_STATE.Source) {
          // 如果关闭之后的父节点头还没有读完
          // 证明这是一个从中间分离出去的
          current.saveExpressions()
          return 'source'
        }
        break
      default:
        throw new Error(`The state: '${state}' is not defined.`)
    }
  })
  root.closeNode('')
  return translateNode(root, true)
}
开发者ID:et-studio,项目名称:et-template,代码行数:67,代码来源:index.ts


注:本文中的et-parser.Parser.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。