Workflowy selector parser

A parser for a DSL used to select specific items in a Workflowy hierarchy.

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.org/scripts/22247/141751/Workflowy%20selector%20parser.js

作者
fiatjaf
版本
0.0.1.20160814232256
创建于
2016-08-12
更新于
2016-08-14
许可证
暂无

Intended to be required by Workflowy userscripts.

pegjs source:

expr
  = s:selector _ ch:(connector? _ selector _)* {
    return [[null, s]].concat(ch.map(s => [s[0], s[2]]))
  }

selector
  = id:('#' [a-z0-9-]i+) { return {type: 'id', val: id[1].join('')} }
  / re:('/' [^/]+ '/') { return {type: 'regex', val: new RegExp(re[1].join(''))} }
  / name:("'" [^']i+ "'") { return {type: 'name', val: name[1].join('')} }
  / any:'*' { return {type: 'any'} }

connector
  = '>' { return 'directchild' }

_ = ' '*