@browserless.io/browserless 2.0.0-beta-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +674 -0
- package/LICENSE +6 -0
- package/README.md +132 -0
- package/assets/logo.png +0 -0
- package/bin/browserless.js +227 -0
- package/browser.json +7 -0
- package/build/browserless.d.ts +33 -0
- package/build/browserless.js +146 -0
- package/build/browsers/cdp-chromium.d.ts +41 -0
- package/build/browsers/cdp-chromium.js +287 -0
- package/build/browsers/index.d.ts +26 -0
- package/build/browsers/index.js +183 -0
- package/build/browsers/playwright-chromium.d.ts +34 -0
- package/build/browsers/playwright-chromium.js +106 -0
- package/build/browsers/playwright-firefox.d.ts +34 -0
- package/build/browsers/playwright-firefox.js +101 -0
- package/build/browsers/playwright-webkit.d.ts +34 -0
- package/build/browsers/playwright-webkit.js +101 -0
- package/build/config.d.ts +138 -0
- package/build/config.js +349 -0
- package/build/constants.d.ts +4 -0
- package/build/constants.js +4 -0
- package/build/data/classes.json +1 -0
- package/build/data/selectors.json +1 -0
- package/build/exports.d.ts +20 -0
- package/build/exports.js +22 -0
- package/build/file-system.d.ts +24 -0
- package/build/file-system.js +46 -0
- package/build/hooks.d.ts +5 -0
- package/build/hooks.js +20 -0
- package/build/http.d.ts +175 -0
- package/build/http.js +104 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +39 -0
- package/build/limiter.d.ts +24 -0
- package/build/limiter.js +147 -0
- package/build/limiter.spec.d.ts +1 -0
- package/build/limiter.spec.js +241 -0
- package/build/metrics.d.ts +24 -0
- package/build/metrics.js +86 -0
- package/build/metrics.spec.d.ts +1 -0
- package/build/metrics.spec.js +35 -0
- package/build/mime-types.d.ts +1 -0
- package/build/mime-types.js +328 -0
- package/build/monitoring.d.ts +13 -0
- package/build/monitoring.js +38 -0
- package/build/routes/chromium/http/content-post.body.json +514 -0
- package/build/routes/chromium/http/content-post.d.ts +34 -0
- package/build/routes/chromium/http/content-post.js +109 -0
- package/build/routes/chromium/http/content-post.query.json +183 -0
- package/build/routes/chromium/http/content-post.response.json +5 -0
- package/build/routes/chromium/http/download-post.body.json +32 -0
- package/build/routes/chromium/http/download-post.d.ts +16 -0
- package/build/routes/chromium/http/download-post.js +92 -0
- package/build/routes/chromium/http/download-post.query.json +120 -0
- package/build/routes/chromium/http/download-post.response.json +4 -0
- package/build/routes/chromium/http/function-post.body.json +32 -0
- package/build/routes/chromium/http/function-post.d.ts +18 -0
- package/build/routes/chromium/http/function-post.js +53 -0
- package/build/routes/chromium/http/function-post.query.json +120 -0
- package/build/routes/chromium/http/function-post.response.json +4 -0
- package/build/routes/chromium/http/pdf-post.body.json +654 -0
- package/build/routes/chromium/http/pdf-post.d.ts +35 -0
- package/build/routes/chromium/http/pdf-post.js +107 -0
- package/build/routes/chromium/http/pdf-post.query.json +120 -0
- package/build/routes/chromium/http/pdf-post.response.json +5 -0
- package/build/routes/chromium/http/performance.body.json +26 -0
- package/build/routes/chromium/http/performance.d.ts +17 -0
- package/build/routes/chromium/http/performance.js +30 -0
- package/build/routes/chromium/http/performance.query.json +120 -0
- package/build/routes/chromium/http/performance.response.json +7 -0
- package/build/routes/chromium/http/scrape-post.body.json +561 -0
- package/build/routes/chromium/http/scrape-post.d.ts +106 -0
- package/build/routes/chromium/http/scrape-post.js +205 -0
- package/build/routes/chromium/http/scrape-post.query.json +183 -0
- package/build/routes/chromium/http/scrape-post.response.json +325 -0
- package/build/routes/chromium/http/screenshot-post.body.json +604 -0
- package/build/routes/chromium/http/screenshot-post.d.ts +37 -0
- package/build/routes/chromium/http/screenshot-post.js +124 -0
- package/build/routes/chromium/http/screenshot-post.query.json +120 -0
- package/build/routes/chromium/http/screenshot-post.response.json +5 -0
- package/build/routes/chromium/tests/content.spec.d.ts +1 -0
- package/build/routes/chromium/tests/content.spec.js +285 -0
- package/build/routes/chromium/tests/download.spec.d.ts +1 -0
- package/build/routes/chromium/tests/download.spec.js +67 -0
- package/build/routes/chromium/tests/function.spec.d.ts +1 -0
- package/build/routes/chromium/tests/function.spec.js +245 -0
- package/build/routes/chromium/tests/pdf.spec.d.ts +1 -0
- package/build/routes/chromium/tests/pdf.spec.js +333 -0
- package/build/routes/chromium/tests/performance.spec.d.ts +1 -0
- package/build/routes/chromium/tests/performance.spec.js +124 -0
- package/build/routes/chromium/tests/scrape.spec.d.ts +1 -0
- package/build/routes/chromium/tests/scrape.spec.js +354 -0
- package/build/routes/chromium/tests/screenshot.spec.d.ts +1 -0
- package/build/routes/chromium/tests/screenshot.spec.js +339 -0
- package/build/routes/chromium/tests/websocket.spec.d.ts +1 -0
- package/build/routes/chromium/tests/websocket.spec.js +309 -0
- package/build/routes/chromium/utils/function/client.d.ts +26 -0
- package/build/routes/chromium/utils/function/client.js +66 -0
- package/build/routes/chromium/utils/function/handler.d.ts +18 -0
- package/build/routes/chromium/utils/function/handler.js +95 -0
- package/build/routes/chromium/utils/performance/child.d.ts +1 -0
- package/build/routes/chromium/utils/performance/child.js +29 -0
- package/build/routes/chromium/utils/performance/main.d.ts +3 -0
- package/build/routes/chromium/utils/performance/main.js +65 -0
- package/build/routes/chromium/utils/performance/types.d.ts +21 -0
- package/build/routes/chromium/utils/performance/types.js +1 -0
- package/build/routes/chromium/ws/browser.d.ts +6 -0
- package/build/routes/chromium/ws/browser.js +11 -0
- package/build/routes/chromium/ws/browser.query.json +120 -0
- package/build/routes/chromium/ws/cdp-chromium.d.ts +6 -0
- package/build/routes/chromium/ws/cdp-chromium.js +11 -0
- package/build/routes/chromium/ws/cdp-chromium.query.json +120 -0
- package/build/routes/chromium/ws/page.d.ts +6 -0
- package/build/routes/chromium/ws/page.js +11 -0
- package/build/routes/chromium/ws/page.query.json +120 -0
- package/build/routes/chromium/ws/playwright-chromium.d.ts +6 -0
- package/build/routes/chromium/ws/playwright-chromium.js +19 -0
- package/build/routes/chromium/ws/playwright-chromium.query.json +100 -0
- package/build/routes/firefox/tests/websocket.spec.d.ts +1 -0
- package/build/routes/firefox/tests/websocket.spec.js +104 -0
- package/build/routes/firefox/ws/playwright-firefox.d.ts +6 -0
- package/build/routes/firefox/ws/playwright-firefox.js +19 -0
- package/build/routes/firefox/ws/playwright-firefox.query.json +100 -0
- package/build/routes/management/http/config-get.d.ts +25 -0
- package/build/routes/management/http/config-get.js +43 -0
- package/build/routes/management/http/config-get.response.json +107 -0
- package/build/routes/management/http/metrics-get.d.ts +4 -0
- package/build/routes/management/http/metrics-get.js +24 -0
- package/build/routes/management/http/metrics-get.response.json +94 -0
- package/build/routes/management/http/metrics-total-get.d.ts +4 -0
- package/build/routes/management/http/metrics-total-get.js +60 -0
- package/build/routes/management/http/metrics-total-get.response.json +72 -0
- package/build/routes/management/http/sessions-get.d.ts +4 -0
- package/build/routes/management/http/sessions-get.js +21 -0
- package/build/routes/management/http/sessions-get.response.json +221 -0
- package/build/routes/management/http/static-get.d.ts +3 -0
- package/build/routes/management/http/static-get.js +67 -0
- package/build/routes/management/tests/management.spec.d.ts +1 -0
- package/build/routes/management/tests/management.spec.js +41 -0
- package/build/routes/webkit/tests/websocket.spec.d.ts +1 -0
- package/build/routes/webkit/tests/websocket.spec.js +104 -0
- package/build/routes/webkit/ws/playwright-webkit.d.ts +6 -0
- package/build/routes/webkit/ws/playwright-webkit.js +19 -0
- package/build/routes/webkit/ws/playwright-webkit.query.json +100 -0
- package/build/server.d.ts +38 -0
- package/build/server.js +365 -0
- package/build/shim.d.ts +9 -0
- package/build/shim.js +54 -0
- package/build/shim.spec.d.ts +1 -0
- package/build/shim.spec.js +114 -0
- package/build/types.d.ts +360 -0
- package/build/types.js +6 -0
- package/build/utils.d.ts +111 -0
- package/build/utils.js +570 -0
- package/build/webhooks.d.ts +11 -0
- package/build/webhooks.js +43 -0
- package/docker/base/.dockerignore +16 -0
- package/docker/base/Dockerfile +70 -0
- package/docker/chrome/.dockerignore +16 -0
- package/docker/chrome/Dockerfile +40 -0
- package/docker/firefox/.dockerignore +16 -0
- package/docker/firefox/Dockerfile +39 -0
- package/docker/multi/.dockerignore +16 -0
- package/docker/multi/Dockerfile +37 -0
- package/docker/sdk/.dockerignore +16 -0
- package/docker/sdk/Dockerfile +34 -0
- package/docker/webkit/.dockerignore +16 -0
- package/docker/webkit/Dockerfile +40 -0
- package/extensions/screencast/background.js +143 -0
- package/extensions/screencast/content_script.js +18 -0
- package/extensions/screencast/manifest.json +19 -0
- package/extensions/ublock/1p-filters.html +69 -0
- package/extensions/ublock/3p-filters.html +119 -0
- package/extensions/ublock/LICENSE.txt +674 -0
- package/extensions/ublock/_locales/ar/messages.json +1290 -0
- package/extensions/ublock/_locales/az/messages.json +1290 -0
- package/extensions/ublock/_locales/be/messages.json +1290 -0
- package/extensions/ublock/_locales/bg/messages.json +1290 -0
- package/extensions/ublock/_locales/bn/messages.json +1290 -0
- package/extensions/ublock/_locales/br_FR/messages.json +1290 -0
- package/extensions/ublock/_locales/bs/messages.json +1290 -0
- package/extensions/ublock/_locales/ca/messages.json +1290 -0
- package/extensions/ublock/_locales/cs/messages.json +1290 -0
- package/extensions/ublock/_locales/cv/messages.json +1290 -0
- package/extensions/ublock/_locales/da/messages.json +1290 -0
- package/extensions/ublock/_locales/de/messages.json +1290 -0
- package/extensions/ublock/_locales/el/messages.json +1290 -0
- package/extensions/ublock/_locales/en/messages.json +1292 -0
- package/extensions/ublock/_locales/en_GB/messages.json +1290 -0
- package/extensions/ublock/_locales/eo/messages.json +1290 -0
- package/extensions/ublock/_locales/es/messages.json +1290 -0
- package/extensions/ublock/_locales/et/messages.json +1290 -0
- package/extensions/ublock/_locales/eu/messages.json +1290 -0
- package/extensions/ublock/_locales/fa/messages.json +1290 -0
- package/extensions/ublock/_locales/fi/messages.json +1290 -0
- package/extensions/ublock/_locales/fil/messages.json +1290 -0
- package/extensions/ublock/_locales/fr/messages.json +1290 -0
- package/extensions/ublock/_locales/fy/messages.json +1290 -0
- package/extensions/ublock/_locales/gl/messages.json +1290 -0
- package/extensions/ublock/_locales/gu/messages.json +1290 -0
- package/extensions/ublock/_locales/he/messages.json +1290 -0
- package/extensions/ublock/_locales/hi/messages.json +1290 -0
- package/extensions/ublock/_locales/hr/messages.json +1290 -0
- package/extensions/ublock/_locales/hu/messages.json +1290 -0
- package/extensions/ublock/_locales/hy/messages.json +1290 -0
- package/extensions/ublock/_locales/id/messages.json +1290 -0
- package/extensions/ublock/_locales/it/messages.json +1290 -0
- package/extensions/ublock/_locales/ja/messages.json +1290 -0
- package/extensions/ublock/_locales/ka/messages.json +1290 -0
- package/extensions/ublock/_locales/kk/messages.json +1290 -0
- package/extensions/ublock/_locales/kn/messages.json +1290 -0
- package/extensions/ublock/_locales/ko/messages.json +1290 -0
- package/extensions/ublock/_locales/ku/messages.json +1290 -0
- package/extensions/ublock/_locales/lt/messages.json +1290 -0
- package/extensions/ublock/_locales/lv/messages.json +1290 -0
- package/extensions/ublock/_locales/mk/messages.json +1290 -0
- package/extensions/ublock/_locales/ml/messages.json +1290 -0
- package/extensions/ublock/_locales/mr/messages.json +1290 -0
- package/extensions/ublock/_locales/ms/messages.json +1290 -0
- package/extensions/ublock/_locales/nb/messages.json +1290 -0
- package/extensions/ublock/_locales/nl/messages.json +1290 -0
- package/extensions/ublock/_locales/no/messages.json +1290 -0
- package/extensions/ublock/_locales/oc/messages.json +1290 -0
- package/extensions/ublock/_locales/pa/messages.json +1290 -0
- package/extensions/ublock/_locales/pl/messages.json +1290 -0
- package/extensions/ublock/_locales/pt_BR/messages.json +1290 -0
- package/extensions/ublock/_locales/pt_PT/messages.json +1290 -0
- package/extensions/ublock/_locales/ro/messages.json +1290 -0
- package/extensions/ublock/_locales/ru/messages.json +1290 -0
- package/extensions/ublock/_locales/si/messages.json +1290 -0
- package/extensions/ublock/_locales/sk/messages.json +1290 -0
- package/extensions/ublock/_locales/sl/messages.json +1290 -0
- package/extensions/ublock/_locales/so/messages.json +1290 -0
- package/extensions/ublock/_locales/sq/messages.json +1290 -0
- package/extensions/ublock/_locales/sr/messages.json +1290 -0
- package/extensions/ublock/_locales/sv/messages.json +1290 -0
- package/extensions/ublock/_locales/sw/messages.json +1290 -0
- package/extensions/ublock/_locales/ta/messages.json +1290 -0
- package/extensions/ublock/_locales/te/messages.json +1290 -0
- package/extensions/ublock/_locales/th/messages.json +1290 -0
- package/extensions/ublock/_locales/tr/messages.json +1290 -0
- package/extensions/ublock/_locales/uk/messages.json +1290 -0
- package/extensions/ublock/_locales/ur/messages.json +1290 -0
- package/extensions/ublock/_locales/vi/messages.json +1290 -0
- package/extensions/ublock/_locales/zh_CN/messages.json +1290 -0
- package/extensions/ublock/_locales/zh_TW/messages.json +1290 -0
- package/extensions/ublock/about.html +63 -0
- package/extensions/ublock/advanced-settings.html +42 -0
- package/extensions/ublock/asset-viewer.html +50 -0
- package/extensions/ublock/assets/assets.json +903 -0
- package/extensions/ublock/assets/resources/scriptlets.js +4255 -0
- package/extensions/ublock/assets/thirdparties/easylist/easylist.txt +65576 -0
- package/extensions/ublock/assets/thirdparties/easylist/easyprivacy.txt +33219 -0
- package/extensions/ublock/assets/thirdparties/pgl.yoyo.org/as/README.md +29 -0
- package/extensions/ublock/assets/thirdparties/pgl.yoyo.org/as/serverlist +3732 -0
- package/extensions/ublock/assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat +15431 -0
- package/extensions/ublock/assets/thirdparties/urlhaus-filter/LICENSE.md +42 -0
- package/extensions/ublock/assets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt +1970 -0
- package/extensions/ublock/assets/ublock/badlists.txt +77 -0
- package/extensions/ublock/assets/ublock/badware.min.txt +3033 -0
- package/extensions/ublock/assets/ublock/filters.min.txt +23419 -0
- package/extensions/ublock/assets/ublock/privacy.min.txt +575 -0
- package/extensions/ublock/assets/ublock/quick-fixes.min.txt +99 -0
- package/extensions/ublock/assets/ublock/unbreak.min.txt +2448 -0
- package/extensions/ublock/background.html +12 -0
- package/extensions/ublock/cloud-ui.html +23 -0
- package/extensions/ublock/code-viewer.html +53 -0
- package/extensions/ublock/css/1p-filters.css +26 -0
- package/extensions/ublock/css/3p-filters.css +250 -0
- package/extensions/ublock/css/about.css +3 -0
- package/extensions/ublock/css/advanced-settings.css +26 -0
- package/extensions/ublock/css/asset-viewer.css +79 -0
- package/extensions/ublock/css/click2load.css +53 -0
- package/extensions/ublock/css/cloud-ui.css +104 -0
- package/extensions/ublock/css/code-viewer.css +67 -0
- package/extensions/ublock/css/codemirror.css +326 -0
- package/extensions/ublock/css/common.css +347 -0
- package/extensions/ublock/css/dashboard-common.css +55 -0
- package/extensions/ublock/css/dashboard.css +115 -0
- package/extensions/ublock/css/devtools.css +22 -0
- package/extensions/ublock/css/document-blocked.css +146 -0
- package/extensions/ublock/css/dyna-rules.css +79 -0
- package/extensions/ublock/css/epicker-ui.css +270 -0
- package/extensions/ublock/css/fa-icons.css +149 -0
- package/extensions/ublock/css/fonts/Inter/Inter-Regular.woff2 +0 -0
- package/extensions/ublock/css/fonts/Inter/Inter-SemiBold.woff2 +0 -0
- package/extensions/ublock/css/fonts/Inter/LICENSE.txt +93 -0
- package/extensions/ublock/css/fonts/Metropolis/Metropolis-Regular.woff2 +0 -0
- package/extensions/ublock/css/fonts/Metropolis/Metropolis-SemiBold.woff2 +0 -0
- package/extensions/ublock/css/fonts/Metropolis/README.md +25 -0
- package/extensions/ublock/css/fonts/Metropolis/UNLICENSE +24 -0
- package/extensions/ublock/css/logger-ui-inspector.css +116 -0
- package/extensions/ublock/css/logger-ui.css +978 -0
- package/extensions/ublock/css/popup-fenix.css +778 -0
- package/extensions/ublock/css/settings.css +74 -0
- package/extensions/ublock/css/support.css +110 -0
- package/extensions/ublock/css/themes/default.css +526 -0
- package/extensions/ublock/css/whitelist.css +22 -0
- package/extensions/ublock/dashboard.html +47 -0
- package/extensions/ublock/devtools.html +58 -0
- package/extensions/ublock/document-blocked.html +64 -0
- package/extensions/ublock/dyna-rules.html +67 -0
- package/extensions/ublock/img/cloud.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/README +9 -0
- package/extensions/ublock/img/flags-of-the-world/ad.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ae.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/af.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ag.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ai.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/al.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/am.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ao.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/aq.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ar.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/as.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/at.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/au.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/aw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ax.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/az.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ba.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bb.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bd.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/be.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bf.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bh.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bi.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bj.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bl.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bo.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bq.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/br.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bs.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bt.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bv.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/by.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ca.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cc.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cd.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cf.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ch.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ci.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ck.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cl.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/co.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cu.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cv.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cx.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cy.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/de.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/dj.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/dk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/dm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/do.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/dz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ec.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ee.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/eg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/eh.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/er.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/es.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/et.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/fi.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/fj.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/fk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/fm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/fo.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/fr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ga.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gb-eng.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gb-nir.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gb-sct.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gb-wls.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gb.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gd.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ge.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gf.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gh.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gi.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gl.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gp.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gq.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gs.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gt.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gu.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gy.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/hk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/hm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/hn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/hr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ht.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/hu.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/id.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ie.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/il.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/im.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/in.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/io.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/iq.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ir.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/is.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/it.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/je.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/jm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/jo.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/jp.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ke.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/kg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/kh.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ki.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/km.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/kn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/kp.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/kr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/kw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ky.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/kz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/la.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/lb.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/lc.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/li.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/lk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/lr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ls.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/lt.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/lu.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/lv.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ly.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ma.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mc.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/md.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/me.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mf.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mh.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ml.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mo.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mp.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mq.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ms.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mt.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mu.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mv.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mx.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/my.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/na.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/nc.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ne.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/nf.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ng.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ni.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/nl.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/no.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/np.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/nr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/nu.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/nz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/om.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pa.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pe.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pf.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ph.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pl.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ps.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pt.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/py.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/qa.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/re.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ro.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/rs.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ru.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/rw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sa.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sb.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sc.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sd.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/se.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sh.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/si.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sj.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sl.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/so.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ss.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/st.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sv.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sx.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sy.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tc.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/td.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tf.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/th.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tj.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tl.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/to.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tt.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tv.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ua.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ug.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/um.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/us.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/uy.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/uz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/va.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/vc.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ve.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/vg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/vi.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/vn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/vu.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/wf.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ws.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/xk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ye.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/yt.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/za.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/zm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/zw.png +0 -0
- package/extensions/ublock/img/fontawesome/LICENSE.txt +25 -0
- package/extensions/ublock/img/fontawesome/fontawesome-defs.svg +79 -0
- package/extensions/ublock/img/help16.png +0 -0
- package/extensions/ublock/img/icon_128.png +0 -0
- package/extensions/ublock/img/icon_16-loading.png +0 -0
- package/extensions/ublock/img/icon_16-off.png +0 -0
- package/extensions/ublock/img/icon_16.png +0 -0
- package/extensions/ublock/img/icon_32-loading.png +0 -0
- package/extensions/ublock/img/icon_32-off.png +0 -0
- package/extensions/ublock/img/icon_32.png +0 -0
- package/extensions/ublock/img/icon_64-loading.png +0 -0
- package/extensions/ublock/img/icon_64-off.png +0 -0
- package/extensions/ublock/img/icon_64.png +0 -0
- package/extensions/ublock/img/material-design.svg +16 -0
- package/extensions/ublock/img/photon.svg +16 -0
- package/extensions/ublock/img/ublock-defs.svg +27 -0
- package/extensions/ublock/img/ublock.svg +44 -0
- package/extensions/ublock/is-webrtc-supported.html +9 -0
- package/extensions/ublock/js/1p-filters.js +336 -0
- package/extensions/ublock/js/3p-filters.js +867 -0
- package/extensions/ublock/js/about.js +34 -0
- package/extensions/ublock/js/advanced-settings.js +194 -0
- package/extensions/ublock/js/asset-viewer.js +112 -0
- package/extensions/ublock/js/assets.js +1448 -0
- package/extensions/ublock/js/background.js +404 -0
- package/extensions/ublock/js/base64-custom.js +246 -0
- package/extensions/ublock/js/benchmarks.js +421 -0
- package/extensions/ublock/js/biditrie.js +947 -0
- package/extensions/ublock/js/cachestorage.js +510 -0
- package/extensions/ublock/js/click2load.js +60 -0
- package/extensions/ublock/js/cloud-ui.js +238 -0
- package/extensions/ublock/js/code-viewer.js +311 -0
- package/extensions/ublock/js/codemirror/search-thread.js +199 -0
- package/extensions/ublock/js/codemirror/search.js +504 -0
- package/extensions/ublock/js/codemirror/ubo-dynamic-filtering.js +239 -0
- package/extensions/ublock/js/codemirror/ubo-static-filtering.js +1126 -0
- package/extensions/ublock/js/commands.js +181 -0
- package/extensions/ublock/js/console.js +59 -0
- package/extensions/ublock/js/contentscript-extra.js +662 -0
- package/extensions/ublock/js/contentscript.js +1366 -0
- package/extensions/ublock/js/contextmenu.js +270 -0
- package/extensions/ublock/js/cosmetic-filtering.js +983 -0
- package/extensions/ublock/js/dashboard-common.js +215 -0
- package/extensions/ublock/js/dashboard.js +166 -0
- package/extensions/ublock/js/devtools.js +184 -0
- package/extensions/ublock/js/diff-updater.js +288 -0
- package/extensions/ublock/js/document-blocked.js +230 -0
- package/extensions/ublock/js/dom.js +213 -0
- package/extensions/ublock/js/dyna-rules.js +678 -0
- package/extensions/ublock/js/dynamic-net-filtering.js +488 -0
- package/extensions/ublock/js/epicker-ui.js +924 -0
- package/extensions/ublock/js/fa-icons.js +129 -0
- package/extensions/ublock/js/filtering-context.js +461 -0
- package/extensions/ublock/js/filtering-engines.js +50 -0
- package/extensions/ublock/js/hnswitches.js +289 -0
- package/extensions/ublock/js/hntrie.js +780 -0
- package/extensions/ublock/js/html-filtering.js +465 -0
- package/extensions/ublock/js/httpheader-filtering.js +213 -0
- package/extensions/ublock/js/i18n.js +346 -0
- package/extensions/ublock/js/is-webrtc-supported.js +52 -0
- package/extensions/ublock/js/logger-ui-inspector.js +652 -0
- package/extensions/ublock/js/logger-ui.js +3028 -0
- package/extensions/ublock/js/logger.js +84 -0
- package/extensions/ublock/js/lz4.js +190 -0
- package/extensions/ublock/js/messaging.js +2095 -0
- package/extensions/ublock/js/pagestore.js +1140 -0
- package/extensions/ublock/js/popup-fenix.js +1529 -0
- package/extensions/ublock/js/redirect-engine.js +494 -0
- package/extensions/ublock/js/redirect-resources.js +193 -0
- package/extensions/ublock/js/reverselookup-worker.js +287 -0
- package/extensions/ublock/js/reverselookup.js +223 -0
- package/extensions/ublock/js/scriptlet-filtering.js +556 -0
- package/extensions/ublock/js/scriptlets/cosmetic-logger.js +376 -0
- package/extensions/ublock/js/scriptlets/cosmetic-off.js +48 -0
- package/extensions/ublock/js/scriptlets/cosmetic-on.js +48 -0
- package/extensions/ublock/js/scriptlets/cosmetic-report.js +142 -0
- package/extensions/ublock/js/scriptlets/dom-inspector.js +906 -0
- package/extensions/ublock/js/scriptlets/dom-survey-elements.js +72 -0
- package/extensions/ublock/js/scriptlets/dom-survey-scripts.js +126 -0
- package/extensions/ublock/js/scriptlets/epicker.js +1365 -0
- package/extensions/ublock/js/scriptlets/load-3p-css.js +67 -0
- package/extensions/ublock/js/scriptlets/load-large-media-all.js +62 -0
- package/extensions/ublock/js/scriptlets/load-large-media-interactive.js +299 -0
- package/extensions/ublock/js/scriptlets/noscript-spoof.js +89 -0
- package/extensions/ublock/js/scriptlets/should-inject-contentscript.js +40 -0
- package/extensions/ublock/js/scriptlets/subscriber.js +113 -0
- package/extensions/ublock/js/scriptlets/updater.js +101 -0
- package/extensions/ublock/js/settings.js +317 -0
- package/extensions/ublock/js/start.js +509 -0
- package/extensions/ublock/js/static-dnr-filtering.js +497 -0
- package/extensions/ublock/js/static-ext-filtering-db.js +171 -0
- package/extensions/ublock/js/static-ext-filtering.js +184 -0
- package/extensions/ublock/js/static-filtering-io.js +144 -0
- package/extensions/ublock/js/static-filtering-parser.js +4459 -0
- package/extensions/ublock/js/static-net-filtering.js +5631 -0
- package/extensions/ublock/js/storage.js +1683 -0
- package/extensions/ublock/js/support.js +335 -0
- package/extensions/ublock/js/tab.js +1178 -0
- package/extensions/ublock/js/tasks.js +42 -0
- package/extensions/ublock/js/text-encode.js +275 -0
- package/extensions/ublock/js/text-utils.js +107 -0
- package/extensions/ublock/js/theme.js +151 -0
- package/extensions/ublock/js/traffic.js +1260 -0
- package/extensions/ublock/js/ublock.js +696 -0
- package/extensions/ublock/js/uri-utils.js +175 -0
- package/extensions/ublock/js/url-net-filtering.js +336 -0
- package/extensions/ublock/js/utils.js +208 -0
- package/extensions/ublock/js/vapi-background-ext.js +254 -0
- package/extensions/ublock/js/vapi-background.js +1802 -0
- package/extensions/ublock/js/vapi-client-extra.js +312 -0
- package/extensions/ublock/js/vapi-client.js +280 -0
- package/extensions/ublock/js/vapi-common.js +308 -0
- package/extensions/ublock/js/vapi.js +89 -0
- package/extensions/ublock/js/wasm/README.md +24 -0
- package/extensions/ublock/js/wasm/biditrie.wasm +0 -0
- package/extensions/ublock/js/wasm/biditrie.wat +728 -0
- package/extensions/ublock/js/wasm/hntrie.wasm +0 -0
- package/extensions/ublock/js/wasm/hntrie.wat +724 -0
- package/extensions/ublock/js/webext.js +164 -0
- package/extensions/ublock/js/whitelist.js +258 -0
- package/extensions/ublock/lib/codemirror/LICENSE +21 -0
- package/extensions/ublock/lib/codemirror/README.md +47 -0
- package/extensions/ublock/lib/codemirror/addon/comment/comment.js +211 -0
- package/extensions/ublock/lib/codemirror/addon/display/panel.js +133 -0
- package/extensions/ublock/lib/codemirror/addon/edit/closebrackets.js +201 -0
- package/extensions/ublock/lib/codemirror/addon/edit/matchbrackets.js +160 -0
- package/extensions/ublock/lib/codemirror/addon/fold/foldcode.js +157 -0
- package/extensions/ublock/lib/codemirror/addon/fold/foldgutter.css +20 -0
- package/extensions/ublock/lib/codemirror/addon/fold/foldgutter.js +163 -0
- package/extensions/ublock/lib/codemirror/addon/hint/show-hint.css +36 -0
- package/extensions/ublock/lib/codemirror/addon/hint/show-hint.js +509 -0
- package/extensions/ublock/lib/codemirror/addon/merge/merge.css +119 -0
- package/extensions/ublock/lib/codemirror/addon/merge/merge.js +1006 -0
- package/extensions/ublock/lib/codemirror/addon/scroll/annotatescrollbar.js +128 -0
- package/extensions/ublock/lib/codemirror/addon/search/matchesonscrollbar.css +8 -0
- package/extensions/ublock/lib/codemirror/addon/search/searchcursor.js +296 -0
- package/extensions/ublock/lib/codemirror/addon/selection/active-line.js +72 -0
- package/extensions/ublock/lib/codemirror/lib/codemirror.css +350 -0
- package/extensions/ublock/lib/codemirror/lib/codemirror.js +9800 -0
- package/extensions/ublock/lib/codemirror/mode/css/css.js +864 -0
- package/extensions/ublock/lib/codemirror/mode/htmlmixed/htmlmixed.js +153 -0
- package/extensions/ublock/lib/codemirror/mode/javascript/javascript.js +942 -0
- package/extensions/ublock/lib/codemirror/mode/xml/xml.js +413 -0
- package/extensions/ublock/lib/codemirror/theme/night.css +27 -0
- package/extensions/ublock/lib/csstree/LICENSE +19 -0
- package/extensions/ublock/lib/csstree/css-tree.js +17 -0
- package/extensions/ublock/lib/diff/README.md +34 -0
- package/extensions/ublock/lib/diff/swatinem_diff.js +272 -0
- package/extensions/ublock/lib/hsluv/LICENSE +20 -0
- package/extensions/ublock/lib/hsluv/README +3 -0
- package/extensions/ublock/lib/hsluv/hsluv-0.1.0.min.js +8 -0
- package/extensions/ublock/lib/js-beautify/LICENSE +9 -0
- package/extensions/ublock/lib/js-beautify/README +5 -0
- package/extensions/ublock/lib/js-beautify/beautifier.min.js +2 -0
- package/extensions/ublock/lib/lz4/README.md +52 -0
- package/extensions/ublock/lib/lz4/lz4-block-codec-any.js +151 -0
- package/extensions/ublock/lib/lz4/lz4-block-codec-js.js +297 -0
- package/extensions/ublock/lib/lz4/lz4-block-codec-wasm.js +195 -0
- package/extensions/ublock/lib/lz4/lz4-block-codec.wasm +0 -0
- package/extensions/ublock/lib/lz4/lz4-block-codec.wat +745 -0
- package/extensions/ublock/lib/publicsuffixlist/publicsuffixlist.js +641 -0
- package/extensions/ublock/lib/publicsuffixlist/wasm/README.md +29 -0
- package/extensions/ublock/lib/publicsuffixlist/wasm/publicsuffixlist.wasm +0 -0
- package/extensions/ublock/lib/publicsuffixlist/wasm/publicsuffixlist.wat +322 -0
- package/extensions/ublock/lib/punycode.js +493 -0
- package/extensions/ublock/lib/regexanalyzer/CHANGES.md +15 -0
- package/extensions/ublock/lib/regexanalyzer/README.md +14 -0
- package/extensions/ublock/lib/regexanalyzer/regex.js +2276 -0
- package/extensions/ublock/logger-ui.html +232 -0
- package/extensions/ublock/managed_storage.json +73 -0
- package/extensions/ublock/manifest.json +115 -0
- package/extensions/ublock/no-dashboard.html +27 -0
- package/extensions/ublock/popup-fenix.html +114 -0
- package/extensions/ublock/settings.html +98 -0
- package/extensions/ublock/support.html +131 -0
- package/extensions/ublock/web_accessible_resources/1x1.gif +0 -0
- package/extensions/ublock/web_accessible_resources/2x2.png +0 -0
- package/extensions/ublock/web_accessible_resources/32x32.png +0 -0
- package/extensions/ublock/web_accessible_resources/3x2.png +0 -0
- package/extensions/ublock/web_accessible_resources/README.txt +11 -0
- package/extensions/ublock/web_accessible_resources/addthis_widget.js +39 -0
- package/extensions/ublock/web_accessible_resources/amazon_ads.js +70 -0
- package/extensions/ublock/web_accessible_resources/amazon_apstag.js +62 -0
- package/extensions/ublock/web_accessible_resources/ampproject_v0.js +34 -0
- package/extensions/ublock/web_accessible_resources/chartbeat.js +30 -0
- package/extensions/ublock/web_accessible_resources/click2load.html +28 -0
- package/extensions/ublock/web_accessible_resources/doubleclick_instream_ad_status.js +1 -0
- package/extensions/ublock/web_accessible_resources/empty +0 -0
- package/extensions/ublock/web_accessible_resources/epicker-ui.html +76 -0
- package/extensions/ublock/web_accessible_resources/fingerprint2.js +55 -0
- package/extensions/ublock/web_accessible_resources/fingerprint3.js +45 -0
- package/extensions/ublock/web_accessible_resources/google-analytics_analytics.js +110 -0
- package/extensions/ublock/web_accessible_resources/google-analytics_cx_api.js +36 -0
- package/extensions/ublock/web_accessible_resources/google-analytics_ga.js +130 -0
- package/extensions/ublock/web_accessible_resources/google-analytics_inpage_linkid.js +28 -0
- package/extensions/ublock/web_accessible_resources/google-ima.js +855 -0
- package/extensions/ublock/web_accessible_resources/googlesyndication_adsbygoogle.js +56 -0
- package/extensions/ublock/web_accessible_resources/googletagmanager_gtm.js +43 -0
- package/extensions/ublock/web_accessible_resources/googletagservices_gpt.js +153 -0
- package/extensions/ublock/web_accessible_resources/hd-main.js +46 -0
- package/extensions/ublock/web_accessible_resources/ligatus_angular-tag.js +29 -0
- package/extensions/ublock/web_accessible_resources/monkeybroker.js +43 -0
- package/extensions/ublock/web_accessible_resources/mxpnl_mixpanel.js +51 -0
- package/extensions/ublock/web_accessible_resources/nobab.js +87 -0
- package/extensions/ublock/web_accessible_resources/nobab2.js +42 -0
- package/extensions/ublock/web_accessible_resources/noeval-silent.js +28 -0
- package/extensions/ublock/web_accessible_resources/noeval.js +30 -0
- package/extensions/ublock/web_accessible_resources/nofab.js +67 -0
- package/extensions/ublock/web_accessible_resources/noop-0.1s.mp3 +0 -0
- package/extensions/ublock/web_accessible_resources/noop-0.5s.mp3 +0 -0
- package/extensions/ublock/web_accessible_resources/noop-1s.mp4 +0 -0
- package/extensions/ublock/web_accessible_resources/noop-vmap1.0.xml +1 -0
- package/extensions/ublock/web_accessible_resources/noop.css +1 -0
- package/extensions/ublock/web_accessible_resources/noop.html +5 -0
- package/extensions/ublock/web_accessible_resources/noop.js +3 -0
- package/extensions/ublock/web_accessible_resources/noop.json +1 -0
- package/extensions/ublock/web_accessible_resources/noop.txt +1 -0
- package/extensions/ublock/web_accessible_resources/outbrain-widget.js +72 -0
- package/extensions/ublock/web_accessible_resources/popads-dummy.js +30 -0
- package/extensions/ublock/web_accessible_resources/popads.js +40 -0
- package/extensions/ublock/web_accessible_resources/prebid-ads.js +26 -0
- package/extensions/ublock/web_accessible_resources/scorecardresearch_beacon.js +31 -0
- package/extensions/ublock/whitelist.html +63 -0
- package/external/.gitkeep +0 -0
- package/fonts/Calibri Bold Italic.ttf +0 -0
- package/fonts/Calibri Bold.TTF +0 -0
- package/fonts/Calibri Italic.ttf +0 -0
- package/fonts/Calibri Light Italic.ttf +0 -0
- package/fonts/Calibri Light.ttf +0 -0
- package/fonts/Calibri Regular.ttf +0 -0
- package/fonts/Emoji.ttf +0 -0
- package/fonts/SegoeUI-Bold.ttf +0 -0
- package/fonts/SegoeUI-Light.ttf +0 -0
- package/fonts/SegoeUI-Regular.ttf +0 -0
- package/fonts/SegoeUI-Semibold.ttf +0 -0
- package/fonts/SegoeUI-Semilight.ttf +0 -0
- package/fonts/Tahoma Bold.ttf +0 -0
- package/fonts/Tahoma.ttf +0 -0
- package/fonts/fonts.conf +21 -0
- package/package.json +177 -0
- package/scripts/build-function.js +18 -0
- package/scripts/build-open-api.js +274 -0
- package/scripts/build-schemas.js +86 -0
- package/scripts/build-selectors.js +36 -0
- package/scripts/clean.js +7 -0
- package/scripts/install-adblock.js +45 -0
- package/scripts/install-cdp-json.js +37 -0
- package/scripts/start.sh +30 -0
- package/scripts/test.sh +17 -0
- package/src/browserless.ts +253 -0
- package/src/browsers/cdp-chromium.ts +422 -0
- package/src/browsers/index.ts +296 -0
- package/src/browsers/playwright-chromium.ts +168 -0
- package/src/browsers/playwright-firefox.ts +161 -0
- package/src/browsers/playwright-webkit.ts +161 -0
- package/src/config.ts +426 -0
- package/src/constants.ts +4 -0
- package/src/exports.ts +23 -0
- package/src/file-system.ts +54 -0
- package/src/hooks.ts +37 -0
- package/src/http.ts +157 -0
- package/src/index.ts +41 -0
- package/src/limiter.spec.ts +365 -0
- package/src/limiter.ts +225 -0
- package/src/metrics.spec.ts +49 -0
- package/src/metrics.ts +108 -0
- package/src/mime-types.ts +332 -0
- package/src/monitoring.ts +53 -0
- package/src/routes/chromium/http/content-post.ts +238 -0
- package/src/routes/chromium/http/download-post.ts +162 -0
- package/src/routes/chromium/http/function-post.ts +98 -0
- package/src/routes/chromium/http/pdf-post.ts +234 -0
- package/src/routes/chromium/http/performance.ts +71 -0
- package/src/routes/chromium/http/scrape-post.ts +439 -0
- package/src/routes/chromium/http/screenshot-post.ts +262 -0
- package/src/routes/chromium/tests/content.spec.ts +340 -0
- package/src/routes/chromium/tests/download.spec.ts +77 -0
- package/src/routes/chromium/tests/function.spec.ts +279 -0
- package/src/routes/chromium/tests/pdf.spec.ts +375 -0
- package/src/routes/chromium/tests/performance.spec.ts +155 -0
- package/src/routes/chromium/tests/scrape.spec.ts +414 -0
- package/src/routes/chromium/tests/screenshot.spec.ts +387 -0
- package/src/routes/chromium/tests/websocket.spec.ts +407 -0
- package/src/routes/chromium/utils/function/client.ts +99 -0
- package/src/routes/chromium/utils/function/handler.ts +172 -0
- package/src/routes/chromium/utils/performance/child.ts +38 -0
- package/src/routes/chromium/utils/performance/main.ts +90 -0
- package/src/routes/chromium/utils/performance/types.ts +24 -0
- package/src/routes/chromium/ws/browser.ts +31 -0
- package/src/routes/chromium/ws/cdp-chromium.ts +31 -0
- package/src/routes/chromium/ws/page.ts +31 -0
- package/src/routes/chromium/ws/playwright-chromium.ts +44 -0
- package/src/routes/firefox/tests/websocket.spec.ts +146 -0
- package/src/routes/firefox/ws/playwright-firefox.ts +44 -0
- package/src/routes/management/http/config-get.ts +82 -0
- package/src/routes/management/http/metrics-get.ts +43 -0
- package/src/routes/management/http/metrics-total-get.ts +89 -0
- package/src/routes/management/http/sessions-get.ts +39 -0
- package/src/routes/management/http/static-get.ts +109 -0
- package/src/routes/management/tests/management.spec.ts +71 -0
- package/src/routes/webkit/tests/websocket.spec.ts +146 -0
- package/src/routes/webkit/ws/playwright-webkit.ts +44 -0
- package/src/server.ts +609 -0
- package/src/shim.spec.ts +154 -0
- package/src/shim.ts +78 -0
- package/src/types.ts +470 -0
- package/src/utils.ts +787 -0
- package/src/webhooks.ts +50 -0
- package/static/docs/browserless-logo.png +0 -0
- package/static/docs/docs.js +2 -0
- package/static/docs/index.html +71 -0
- package/static/docs/swagger.json +4232 -0
- package/static/favicon-32x32.png +0 -0
- package/static/function/client.js +31623 -0
- package/static/function/index.html +12 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,2276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Regex
|
|
4
|
+
* @version: 1.2.0
|
|
5
|
+
*
|
|
6
|
+
* A simple & generic Regular Expression Analyzer & Composer for PHP, Python, Javascript
|
|
7
|
+
* https://github.com/foo123/RegexAnalyzer
|
|
8
|
+
*
|
|
9
|
+
**/
|
|
10
|
+
export default (function(root, name, factory) {
|
|
11
|
+
"use strict";
|
|
12
|
+
var __version__ = "1.2.0",
|
|
13
|
+
|
|
14
|
+
PROTO = 'prototype', OP = Object[PROTO], AP = Array[PROTO],
|
|
15
|
+
Keys = Object.keys, to_string = OP.toString, HAS = OP.hasOwnProperty,
|
|
16
|
+
fromCharCode = String.fromCharCode,
|
|
17
|
+
fromCodePoint = String.fromCodePoint || String.fromCharCode,
|
|
18
|
+
CHAR = 'charAt', CHARCODE = 'charCodeAt',
|
|
19
|
+
CODEPOINT = String.prototype.codePointAt ? 'codePointAt' : CHARCODE,
|
|
20
|
+
toJSON = JSON.stringify,
|
|
21
|
+
INF = Infinity, ESC = '\\',
|
|
22
|
+
specialChars = {
|
|
23
|
+
"." : "MatchAnyChar",
|
|
24
|
+
"|" : "MatchEither",
|
|
25
|
+
"?" : "MatchZeroOrOne",
|
|
26
|
+
"*" : "MatchZeroOrMore",
|
|
27
|
+
"+" : "MatchOneOrMore",
|
|
28
|
+
"^" : "MatchStart",
|
|
29
|
+
"$" : "MatchEnd",
|
|
30
|
+
"{" : "StartRepeats",
|
|
31
|
+
"}" : "EndRepeats",
|
|
32
|
+
"(" : "StartGroup",
|
|
33
|
+
")" : "EndGroup",
|
|
34
|
+
"[" : "StartCharGroup",
|
|
35
|
+
"]" : "EndCharGroup"
|
|
36
|
+
},
|
|
37
|
+
/*
|
|
38
|
+
http://www.javascriptkit.com/javatutors/redev2.shtml
|
|
39
|
+
|
|
40
|
+
\f matches form-feed.
|
|
41
|
+
\r matches carriage return.
|
|
42
|
+
\n matches linefeed.
|
|
43
|
+
\t matches horizontal tab.
|
|
44
|
+
\v matches vertical tab.
|
|
45
|
+
\0 matches NUL character.
|
|
46
|
+
[\b] matches backspace.
|
|
47
|
+
\s matches whitespace (short for [\f\n\r\t\v\u00A0\u2028\u2029]).
|
|
48
|
+
\S matches anything but a whitespace (short for [^\f\n\r\t\v\u00A0\u2028\u2029]).
|
|
49
|
+
\w matches any alphanumerical character (word characters) including underscore (short for [a-zA-Z0-9_]).
|
|
50
|
+
\W matches any non-word characters (short for [^a-zA-Z0-9_]).
|
|
51
|
+
\d matches any digit (short for [0-9]).
|
|
52
|
+
\D matches any non-digit (short for [^0-9]).
|
|
53
|
+
\b matches a word boundary (the position between a word and a space).
|
|
54
|
+
\B matches a non-word boundary (short for [^\b]).
|
|
55
|
+
\cX matches a control character. E.g: \cm matches control-M.
|
|
56
|
+
\xhh matches the character with two characters of hexadecimal code hh.
|
|
57
|
+
\uhhhh matches the Unicode character with four characters of hexadecimal code hhhh.
|
|
58
|
+
*/
|
|
59
|
+
specialCharsEscaped = {
|
|
60
|
+
"\\" : "ESC",
|
|
61
|
+
"/" : "/",
|
|
62
|
+
"0" : "NULChar",
|
|
63
|
+
"f" : "FormFeed",
|
|
64
|
+
"n" : "LineFeed",
|
|
65
|
+
"r" : "CarriageReturn",
|
|
66
|
+
"t" : "HorizontalTab",
|
|
67
|
+
"v" : "VerticalTab",
|
|
68
|
+
"b" : "MatchWordBoundary",
|
|
69
|
+
"B" : "MatchNonWordBoundary",
|
|
70
|
+
"s" : "MatchSpaceChar",
|
|
71
|
+
"S" : "MatchNonSpaceChar",
|
|
72
|
+
"w" : "MatchWordChar",
|
|
73
|
+
"W" : "MatchNonWordChar",
|
|
74
|
+
"d" : "MatchDigitChar",
|
|
75
|
+
"D" : "MatchNonDigitChar"
|
|
76
|
+
},
|
|
77
|
+
T_SEQUENCE = 1,
|
|
78
|
+
T_ALTERNATION = 2,
|
|
79
|
+
T_GROUP = 4,
|
|
80
|
+
T_CHARGROUP = 8,
|
|
81
|
+
T_QUANTIFIER = 16,
|
|
82
|
+
T_UNICODECHAR = 32,
|
|
83
|
+
T_HEXCHAR = 64,
|
|
84
|
+
T_SPECIAL = 128,
|
|
85
|
+
T_CHARS = 256,
|
|
86
|
+
T_CHARRANGE = 512,
|
|
87
|
+
T_STRING = 1024,
|
|
88
|
+
T_COMMENT = 2048
|
|
89
|
+
;
|
|
90
|
+
|
|
91
|
+
function is_array(x)
|
|
92
|
+
{
|
|
93
|
+
return (x instanceof Array) || ('[object Array]' === to_string.call(x));
|
|
94
|
+
}
|
|
95
|
+
function is_string(x)
|
|
96
|
+
{
|
|
97
|
+
return (x instanceof String) || ('[object String]' === to_string.call(x));
|
|
98
|
+
}
|
|
99
|
+
function is_regexp(x)
|
|
100
|
+
{
|
|
101
|
+
return (x instanceof RegExp) || ('[object RegExp]' === to_string.call(x));
|
|
102
|
+
}
|
|
103
|
+
function array(x)
|
|
104
|
+
{
|
|
105
|
+
return is_array(x) ? x : [x];
|
|
106
|
+
}
|
|
107
|
+
function clone(obj, cloned)
|
|
108
|
+
{
|
|
109
|
+
cloned = cloned || {};
|
|
110
|
+
for (var p in obj) if (HAS.call(obj,p)) cloned[p] = obj[p];
|
|
111
|
+
return cloned;
|
|
112
|
+
}
|
|
113
|
+
function RE_OBJ(re, flags, flavor)
|
|
114
|
+
{
|
|
115
|
+
var self = this;
|
|
116
|
+
self.re = re;
|
|
117
|
+
self.flags = flags;
|
|
118
|
+
self.flavor = flavor;
|
|
119
|
+
self.len = re.length;
|
|
120
|
+
self.pos = 0;
|
|
121
|
+
self.index = 0;
|
|
122
|
+
self.groupIndex = 0;
|
|
123
|
+
self.group = {};
|
|
124
|
+
self.inGroup = 0;
|
|
125
|
+
}
|
|
126
|
+
RE_OBJ[PROTO] = {
|
|
127
|
+
constructor: RE_OBJ
|
|
128
|
+
,re: null
|
|
129
|
+
,flags: null
|
|
130
|
+
,flavor: ''
|
|
131
|
+
,len: null
|
|
132
|
+
,pos: null
|
|
133
|
+
,index: null
|
|
134
|
+
,groupIndex: null
|
|
135
|
+
,inGroup: null
|
|
136
|
+
,groups: null
|
|
137
|
+
,dispose: function() {
|
|
138
|
+
var self = this;
|
|
139
|
+
self.re = null;
|
|
140
|
+
self.flags = null;
|
|
141
|
+
self.flavor = null;
|
|
142
|
+
self.len = null;
|
|
143
|
+
self.pos = null;
|
|
144
|
+
self.index = null;
|
|
145
|
+
self.groupIndex = null;
|
|
146
|
+
self.group = null;
|
|
147
|
+
self.inGroup = null;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
function Node(type, value, flags)
|
|
151
|
+
{
|
|
152
|
+
var self = this;
|
|
153
|
+
if (!(self instanceof Node)) return new Node(type, value, flags);
|
|
154
|
+
self.type = type;
|
|
155
|
+
self.val = value;
|
|
156
|
+
self.flags = flags || {};
|
|
157
|
+
switch (type)
|
|
158
|
+
{
|
|
159
|
+
case T_SEQUENCE:
|
|
160
|
+
self.typeName = "Sequence"; break;
|
|
161
|
+
case T_ALTERNATION:
|
|
162
|
+
self.typeName = "Alternation"; break;
|
|
163
|
+
case T_GROUP:
|
|
164
|
+
self.typeName = "Group"; break;
|
|
165
|
+
case T_CHARGROUP:
|
|
166
|
+
self.typeName = "CharacterGroup"; break;
|
|
167
|
+
case T_CHARS:
|
|
168
|
+
self.typeName = "Characters"; break;
|
|
169
|
+
case T_CHARRANGE:
|
|
170
|
+
self.typeName = "CharacterRange"; break;
|
|
171
|
+
case T_STRING:
|
|
172
|
+
self.typeName = "String"; break;
|
|
173
|
+
case T_QUANTIFIER:
|
|
174
|
+
self.typeName = "Quantifier"; break;
|
|
175
|
+
case T_UNICODECHAR:
|
|
176
|
+
self.typeName = "UnicodeChar"; break;
|
|
177
|
+
case T_HEXCHAR:
|
|
178
|
+
self.typeName = "HexChar"; break;
|
|
179
|
+
case T_SPECIAL:
|
|
180
|
+
self.typeName = "Special"; break;
|
|
181
|
+
case T_COMMENT:
|
|
182
|
+
self.typeName = "Comment"; break;
|
|
183
|
+
default:
|
|
184
|
+
self.typeName = "unspecified"; break;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
Node.toObjectStatic = function toObject(v) {
|
|
188
|
+
if (v instanceof Node)
|
|
189
|
+
{
|
|
190
|
+
return v.flags && Object.keys(v.flags).length ? {
|
|
191
|
+
type: v.typeName,
|
|
192
|
+
value: toObject(v.val),
|
|
193
|
+
flags: v.flags
|
|
194
|
+
} : {
|
|
195
|
+
type: v.typeName,
|
|
196
|
+
value: toObject(v.val)
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
else if (is_array(v))
|
|
200
|
+
{
|
|
201
|
+
return v.map(toObject);
|
|
202
|
+
}
|
|
203
|
+
return v;
|
|
204
|
+
};
|
|
205
|
+
Node[PROTO] = {
|
|
206
|
+
constructor: Node
|
|
207
|
+
,type: null
|
|
208
|
+
,typeName: null
|
|
209
|
+
,val: null
|
|
210
|
+
,flags: null
|
|
211
|
+
,dispose: function() {
|
|
212
|
+
var self = this;
|
|
213
|
+
self.val = null;
|
|
214
|
+
self.flags = null;
|
|
215
|
+
self.type = null;
|
|
216
|
+
self.typeName = null;
|
|
217
|
+
return self;
|
|
218
|
+
}
|
|
219
|
+
,toObject: function() {
|
|
220
|
+
return Node.toObjectStatic(this);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
var rnd = function(a, b) {return Math.round((b-a)*Math.random()+a);},
|
|
225
|
+
RE = function(re, fl) {return new RegExp(re, fl||'');},
|
|
226
|
+
slice = function(a) {return AP.slice.apply(a, AP.slice.call(arguments, 1));},
|
|
227
|
+
flatten = function(a) {
|
|
228
|
+
var r = [], i = 0;
|
|
229
|
+
while (i < a.length) r = r.concat(a[i++]);
|
|
230
|
+
return r;
|
|
231
|
+
},
|
|
232
|
+
getArgs = function(args, asArray) {
|
|
233
|
+
/*var a = slice(args);
|
|
234
|
+
if ( asArray && a[0] &&
|
|
235
|
+
( a[0] instanceof Array || '[object Array]' == to_string.call(a[0]) )
|
|
236
|
+
)
|
|
237
|
+
a = a[0];*/
|
|
238
|
+
return flatten(slice(args)); //a;
|
|
239
|
+
},
|
|
240
|
+
esc_re = function(s, esc, chargroup) {
|
|
241
|
+
var es = '', l = s.length, i=0, c;
|
|
242
|
+
//escaped_re = /([.*+?^${}()|[\]\/\\\-])/g
|
|
243
|
+
if (chargroup)
|
|
244
|
+
{
|
|
245
|
+
while (i < l)
|
|
246
|
+
{
|
|
247
|
+
c = s[CHAR](i++);
|
|
248
|
+
es += (/*('?' === c) || ('*' === c) || ('+' === c) ||*/
|
|
249
|
+
('-' === c) || /*('.' === c) ||*/ ('^' === c) || ('$' === c) || ('|' === c) ||
|
|
250
|
+
('{' === c) || ('}' === c) || ('(' === c) || (')' === c) ||
|
|
251
|
+
('[' === c) || (']' === c) || ('/' === c) || (esc === c) ? esc : '') + c;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else
|
|
255
|
+
{
|
|
256
|
+
while (i < l)
|
|
257
|
+
{
|
|
258
|
+
c = s[CHAR](i++);
|
|
259
|
+
es += (('?' === c) || ('*' === c) || ('+' === c) ||
|
|
260
|
+
/*('-' === c) ||*/ ('.' === c) || ('^' === c) || ('$' === c) || ('|' === c) ||
|
|
261
|
+
('{' === c) || ('}' === c) || ('(' === c) || (')' === c) ||
|
|
262
|
+
('[' === c) || (']' === c) || ('/' === c) || (esc === c) ? esc : '') + c;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return es;
|
|
266
|
+
},
|
|
267
|
+
pad = function(s, n, z) {
|
|
268
|
+
var ps = String(s);
|
|
269
|
+
z = z || '0';
|
|
270
|
+
while (ps.length < n) ps = z + ps;
|
|
271
|
+
return ps;
|
|
272
|
+
},
|
|
273
|
+
char_code = function(c) {return c[CODEPOINT](0);},
|
|
274
|
+
char_code_range = function(s) {return [s[CODEPOINT](0), s[CODEPOINT](s.length-1)];},
|
|
275
|
+
//char_codes = function( s_or_a ) { return (s_or_a.substr ? s_or_a.split("") : s_or_a).map( char_code ); },
|
|
276
|
+
// http://stackoverflow.com/questions/12376870/create-an-array-of-characters-from-specified-range
|
|
277
|
+
character_range = function(first, last) {
|
|
278
|
+
if (first && is_array(first)) {last = first[1]; first = first[0];}
|
|
279
|
+
var ch, chars, start = first[CODEPOINT](0), end = last[CODEPOINT](0);
|
|
280
|
+
|
|
281
|
+
if (end === start) return [fromCodePoint(start)];
|
|
282
|
+
|
|
283
|
+
chars = [];
|
|
284
|
+
for (ch = start; ch <= end; ++ch) chars.push(fromCodePoint(ch));
|
|
285
|
+
return chars;
|
|
286
|
+
},
|
|
287
|
+
concat = function(p1, p2) {
|
|
288
|
+
if (p2)
|
|
289
|
+
{
|
|
290
|
+
var p, l;
|
|
291
|
+
if (is_array(p2))
|
|
292
|
+
{
|
|
293
|
+
for (p=0,l=p2.length; p<l; ++p) p1[p2[p]] = 1;
|
|
294
|
+
}
|
|
295
|
+
else
|
|
296
|
+
{
|
|
297
|
+
for (p in p2) if (HAS.call(p2, p)) p1[p] = 1;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return p1;
|
|
301
|
+
},
|
|
302
|
+
|
|
303
|
+
BSPACES = "\r\n", SPACES = " \t\v", PUNCTS = "~!@#$%^&*()-+=[]{}\\|;:,./<>?",
|
|
304
|
+
DIGITS = "0123456789", DIGITS_RANGE = char_code_range(DIGITS),
|
|
305
|
+
HEXDIGITS_RANGES = [DIGITS_RANGE, [char_code("a"), char_code("f")], [char_code("A"), char_code("F")]],
|
|
306
|
+
ALPHAS = "_"+(character_range("a", "z").join(""))+(character_range("A", "Z").join("")),
|
|
307
|
+
ALL = SPACES+PUNCTS+DIGITS+ALPHAS, ALL_ARY = ALL.split(""),
|
|
308
|
+
|
|
309
|
+
match_chars = function(CHARS, s, pos, minlen, maxlen) {
|
|
310
|
+
pos = pos || 0;
|
|
311
|
+
minlen = minlen || 1;
|
|
312
|
+
maxlen = maxlen || INF;
|
|
313
|
+
var lp = pos, l = 0, sl = s.length, ch;
|
|
314
|
+
while ((lp < sl) && (l <= maxlen) && -1 < CHARS.indexOf(ch=s[CHAR](lp)))
|
|
315
|
+
{
|
|
316
|
+
++lp; ++l;
|
|
317
|
+
}
|
|
318
|
+
return l >= minlen ? l : false;
|
|
319
|
+
},
|
|
320
|
+
match_char_range = function(RANGE, s, pos, minlen, maxlen) {
|
|
321
|
+
pos = pos || 0;
|
|
322
|
+
minlen = minlen || 1;
|
|
323
|
+
maxlen = maxlen || INF;
|
|
324
|
+
var lp = pos, l = 0, sl = s.length, ch;
|
|
325
|
+
while ((lp < sl) && (l <= maxlen) && ((ch=s[CHARCODE](lp)) >= RANGE[0] && ch <= RANGE[1]))
|
|
326
|
+
{
|
|
327
|
+
++lp; ++l;
|
|
328
|
+
}
|
|
329
|
+
return l >= minlen ? l : false;
|
|
330
|
+
},
|
|
331
|
+
match_char_ranges = function(RANGES, s, pos, minlen, maxlen) {
|
|
332
|
+
pos = pos || 0;
|
|
333
|
+
minlen = minlen || 1;
|
|
334
|
+
maxlen = maxlen || INF;
|
|
335
|
+
var lp = pos, l = 0, sl = s.length, ch,
|
|
336
|
+
i, Rl = RANGES.length, RANGE, found = true;
|
|
337
|
+
while ((lp < sl) && (l <= maxlen) && found)
|
|
338
|
+
{
|
|
339
|
+
ch = s[CHARCODE](lp); found = false;
|
|
340
|
+
for (i=0; i<Rl; ++i)
|
|
341
|
+
{
|
|
342
|
+
RANGE = RANGES[i];
|
|
343
|
+
if (ch >= RANGE[0] && ch <= RANGE[1])
|
|
344
|
+
{
|
|
345
|
+
++lp; ++l; found = true;
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return l >= minlen ? l : false;
|
|
351
|
+
},
|
|
352
|
+
|
|
353
|
+
punct = function() {
|
|
354
|
+
return PUNCTS[CHAR](rnd(0, PUNCTS.length-1));
|
|
355
|
+
},
|
|
356
|
+
space = function(positive) {
|
|
357
|
+
return false !== positive
|
|
358
|
+
? SPACES[CHAR](rnd(0, SPACES.length-1))
|
|
359
|
+
: (punct()+digit()+alpha())[CHAR](rnd(0, 2))
|
|
360
|
+
;
|
|
361
|
+
},
|
|
362
|
+
digit = function(positive) {
|
|
363
|
+
return false !== positive
|
|
364
|
+
? DIGITS[CHAR](rnd(0, DIGITS.length-1))
|
|
365
|
+
: (punct()+space()+alpha())[CHAR](rnd(0, 2))
|
|
366
|
+
;
|
|
367
|
+
},
|
|
368
|
+
alpha = function(positive) {
|
|
369
|
+
return false !== positive
|
|
370
|
+
? ALPHAS[CHAR](rnd(0, ALPHAS.length-1))
|
|
371
|
+
: (punct()+space()+digit())[CHAR](rnd(0, 2))
|
|
372
|
+
;
|
|
373
|
+
},
|
|
374
|
+
word = function(positive) {
|
|
375
|
+
return false !== positive
|
|
376
|
+
? (ALPHAS+DIGITS)[CHAR](rnd(0, ALPHAS.length+DIGITS.length-1))
|
|
377
|
+
: (punct()+space())[CHAR](rnd(0, 1))
|
|
378
|
+
;
|
|
379
|
+
},
|
|
380
|
+
any = function() {
|
|
381
|
+
return ALL[CHAR](rnd(0, ALL.length-1));
|
|
382
|
+
},
|
|
383
|
+
character = function(chars, positive) {
|
|
384
|
+
if (false !== positive) return chars.length ? chars[rnd(0, chars.length-1)] : '';
|
|
385
|
+
var choices = ALL_ARY.filter(function(c) {return 0 > chars.indexOf(c);});
|
|
386
|
+
return choices.length ? choices[rnd(0, choices.length-1)] : '';
|
|
387
|
+
},
|
|
388
|
+
random_upper_or_lower = function(c) {return 0.5 < Math.random() ? c.toLowerCase() : c.toUpperCase();},
|
|
389
|
+
case_insensitive = function(chars, asArray) {
|
|
390
|
+
if (asArray)
|
|
391
|
+
{
|
|
392
|
+
if (chars[CHAR]) chars = chars.split('');
|
|
393
|
+
chars = chars.map(random_upper_or_lower);
|
|
394
|
+
//if ( !asArray ) chars = chars.join('');
|
|
395
|
+
return chars;
|
|
396
|
+
}
|
|
397
|
+
else
|
|
398
|
+
{
|
|
399
|
+
return random_upper_or_lower(chars);
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
|
|
403
|
+
walk = function walk(ret, node, state) {
|
|
404
|
+
if ((null == node) || !state) return ret;
|
|
405
|
+
|
|
406
|
+
var i, l, r, type = node instanceof Node ? node.type : null;
|
|
407
|
+
|
|
408
|
+
// walk the tree
|
|
409
|
+
if (null === type)
|
|
410
|
+
{
|
|
411
|
+
// custom, let reduce handle it
|
|
412
|
+
ret = state.reduce(ret, node, state);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
else if (state.IGNORE & type)
|
|
416
|
+
{
|
|
417
|
+
/* nothing */
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
else if (state.MAP & type)
|
|
421
|
+
{
|
|
422
|
+
r = state.map(ret, node, state);
|
|
423
|
+
if (null != state.ret)
|
|
424
|
+
{
|
|
425
|
+
ret = state.reduce(ret, node, state);
|
|
426
|
+
state.ret = null;
|
|
427
|
+
}
|
|
428
|
+
else if (null != r)
|
|
429
|
+
{
|
|
430
|
+
r = array(r);
|
|
431
|
+
for (i=0,l=r?r.length:0; i<l; ++i)
|
|
432
|
+
{
|
|
433
|
+
state.node = node;
|
|
434
|
+
ret = walk(ret, r[i], state);
|
|
435
|
+
if (state.stop)
|
|
436
|
+
{
|
|
437
|
+
state.stop = null;
|
|
438
|
+
return ret;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
else if (state.REDUCE & type)
|
|
445
|
+
{
|
|
446
|
+
ret = state.reduce(ret, node, state);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
state.node = null;
|
|
450
|
+
return ret;
|
|
451
|
+
},
|
|
452
|
+
/*map_all = function map_all( ret, node, state ) {
|
|
453
|
+
return node.val;
|
|
454
|
+
},*/
|
|
455
|
+
map_src = function map_src(ret, node, state) {
|
|
456
|
+
var type = node.type;
|
|
457
|
+
if (T_ALTERNATION === type)
|
|
458
|
+
{
|
|
459
|
+
var r = [];
|
|
460
|
+
for (var i=0,l=node.val.length-1; i<l; ++i) r.push(node.val[i], '|');
|
|
461
|
+
r.push(node.val[l]);
|
|
462
|
+
return r;
|
|
463
|
+
}
|
|
464
|
+
else if (T_CHARGROUP === type)
|
|
465
|
+
{
|
|
466
|
+
return [].concat('['+(node.flags.NegativeMatch?'^':'')).concat(array(node.val)).concat(']');
|
|
467
|
+
}
|
|
468
|
+
else if (T_QUANTIFIER === type)
|
|
469
|
+
{
|
|
470
|
+
var q = '';
|
|
471
|
+
if (node.flags.MatchZeroOrOne) q = '?';
|
|
472
|
+
else if (node.flags.MatchZeroOrMore) q = '*';
|
|
473
|
+
else if (node.flags.MatchOneOrMore) q = '+';
|
|
474
|
+
else q = node.flags.min === node.flags.max ? ('{'+node.flags.min+'}') : ('{'+node.flags.min+','+(-1===node.flags.max?'':node.flags.max)+'}');
|
|
475
|
+
if ((node.flags.min !== node.flags.max) && !node.flags.isGreedy) q += '?';
|
|
476
|
+
return [].concat(array(node.val)).concat(q);
|
|
477
|
+
}
|
|
478
|
+
else if (T_GROUP === type)
|
|
479
|
+
{
|
|
480
|
+
var g = null;
|
|
481
|
+
if (node.flags.NotCaptured)
|
|
482
|
+
{
|
|
483
|
+
g = [].concat('(?:').concat(array(node.val)).concat(')');
|
|
484
|
+
}
|
|
485
|
+
else if (node.flags.LookAhead)
|
|
486
|
+
{
|
|
487
|
+
g = [].concat('(?=').concat(array(node.val)).concat(')');
|
|
488
|
+
}
|
|
489
|
+
else if (node.flags.NegativeLookAhead)
|
|
490
|
+
{
|
|
491
|
+
g = [].concat('(?!').concat(array(node.val)).concat(')');
|
|
492
|
+
}
|
|
493
|
+
else if (node.flags.LookBehind)
|
|
494
|
+
{
|
|
495
|
+
g = [].concat('(?<=').concat(array(node.val)).concat(')');
|
|
496
|
+
}
|
|
497
|
+
else if (node.flags.NegativeLookBehind)
|
|
498
|
+
{
|
|
499
|
+
g = [].concat('(?<!').concat(array(node.val)).concat(')');
|
|
500
|
+
}
|
|
501
|
+
else if (node.flags.NamedGroup && !state.compatibility)
|
|
502
|
+
{
|
|
503
|
+
g = [].concat('(?<'+node.flags.GroupName+'>').concat(array(node.val)).concat(')');
|
|
504
|
+
}
|
|
505
|
+
else
|
|
506
|
+
{
|
|
507
|
+
g = [].concat('(').concat(array(node.val)).concat(')');
|
|
508
|
+
}
|
|
509
|
+
if (null != node.flags.GroupIndex)
|
|
510
|
+
{
|
|
511
|
+
ret.group[node.flags.GroupIndex] = node.flags.GroupIndex;
|
|
512
|
+
if (node.flags.GroupName) ret.group[node.flags.GroupName] = node.flags.GroupIndex;
|
|
513
|
+
}
|
|
514
|
+
return g;
|
|
515
|
+
}
|
|
516
|
+
return node.val;
|
|
517
|
+
},
|
|
518
|
+
map_any = function map_any(ret, node, state) {
|
|
519
|
+
var type = node.type;
|
|
520
|
+
if ((T_ALTERNATION === type) || (T_CHARGROUP === type))
|
|
521
|
+
{
|
|
522
|
+
return node.val.length ? node.val[rnd(0, node.val.length-1)] : null;
|
|
523
|
+
}
|
|
524
|
+
else if (T_QUANTIFIER === type)
|
|
525
|
+
{
|
|
526
|
+
var numrepeats, mmin, mmax, repeats;
|
|
527
|
+
if (ret.length >= state.maxLength)
|
|
528
|
+
{
|
|
529
|
+
numrepeats = node.flags.min;
|
|
530
|
+
}
|
|
531
|
+
else
|
|
532
|
+
{
|
|
533
|
+
mmin = node.flags.min;
|
|
534
|
+
mmax = -1 === node.flags.max ? (mmin+1+2*state.maxLength) : node.flags.max;
|
|
535
|
+
numrepeats = rnd(mmin, mmax);
|
|
536
|
+
}
|
|
537
|
+
if (numrepeats)
|
|
538
|
+
{
|
|
539
|
+
repeats = new Array(numrepeats);
|
|
540
|
+
for (var i=0; i<numrepeats; ++i) repeats[i] = node.val;
|
|
541
|
+
return repeats;
|
|
542
|
+
}
|
|
543
|
+
else
|
|
544
|
+
{
|
|
545
|
+
return null;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
else if ((T_GROUP === type) && node.flags.GroupIndex)
|
|
549
|
+
{
|
|
550
|
+
var sample = walk('', node.val, state);
|
|
551
|
+
state.group[node.flags.GroupIndex] = sample;
|
|
552
|
+
state.ret = sample;
|
|
553
|
+
return null;
|
|
554
|
+
}
|
|
555
|
+
else
|
|
556
|
+
{
|
|
557
|
+
return node.val;
|
|
558
|
+
}
|
|
559
|
+
},
|
|
560
|
+
map_min = function map_min(ret, node, state) {
|
|
561
|
+
var type = node.type;
|
|
562
|
+
if (T_ALTERNATION === type)
|
|
563
|
+
{
|
|
564
|
+
var i, l = node.val.length, cur,
|
|
565
|
+
min = l ? walk(0, node.val[0], state) : 0;
|
|
566
|
+
for (i=1; i<l; ++i)
|
|
567
|
+
{
|
|
568
|
+
cur = walk(0, node.val[i], state);
|
|
569
|
+
if (cur < min) min = cur;
|
|
570
|
+
}
|
|
571
|
+
if (l) state.ret = min;
|
|
572
|
+
return null;
|
|
573
|
+
}
|
|
574
|
+
else if (T_CHARGROUP === type)
|
|
575
|
+
{
|
|
576
|
+
return node.val.length ? node.val[0] : null;
|
|
577
|
+
}
|
|
578
|
+
else if (T_QUANTIFIER === type)
|
|
579
|
+
{
|
|
580
|
+
if (0 === node.flags.min) return null;
|
|
581
|
+
var i, nrepeats = node.flags.min, repeats = new Array(nrepeats);
|
|
582
|
+
for (i=0; i<nrepeats; ++i) repeats[i] = node.val;
|
|
583
|
+
return repeats;
|
|
584
|
+
}
|
|
585
|
+
else if ((T_GROUP === type) && node.flags.GroupIndex)
|
|
586
|
+
{
|
|
587
|
+
var min = walk(0, node.val, state);
|
|
588
|
+
state.group[node.flags.GroupIndex] = min;
|
|
589
|
+
state.ret = min;
|
|
590
|
+
return null;
|
|
591
|
+
}
|
|
592
|
+
else
|
|
593
|
+
{
|
|
594
|
+
return node.val;
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
map_max = function map_max(ret, node, state) {
|
|
598
|
+
var type = node.type;
|
|
599
|
+
if (T_ALTERNATION === type)
|
|
600
|
+
{
|
|
601
|
+
var i, l = node.val.length, cur, max = l ? walk(0, node.val[0], state) : 0;
|
|
602
|
+
if (-1 !== max)
|
|
603
|
+
{
|
|
604
|
+
for (i=1; i<l; ++i)
|
|
605
|
+
{
|
|
606
|
+
cur = walk(0, node.val[i], state);
|
|
607
|
+
if (-1 === cur)
|
|
608
|
+
{
|
|
609
|
+
max = -1;
|
|
610
|
+
break;
|
|
611
|
+
}
|
|
612
|
+
else if (cur > max)
|
|
613
|
+
{
|
|
614
|
+
max = cur;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
if (l) state.ret = max;
|
|
619
|
+
return null;
|
|
620
|
+
}
|
|
621
|
+
else if (T_CHARGROUP === type)
|
|
622
|
+
{
|
|
623
|
+
return node.val.length ? node.val[0] : null;
|
|
624
|
+
}
|
|
625
|
+
else if (T_QUANTIFIER === type)
|
|
626
|
+
{
|
|
627
|
+
max = walk(0, node.val, state);
|
|
628
|
+
if (-1 === max)
|
|
629
|
+
{
|
|
630
|
+
state.ret = -1;
|
|
631
|
+
}
|
|
632
|
+
else if (0 < max)
|
|
633
|
+
{
|
|
634
|
+
if (-1 === node.flags.max)
|
|
635
|
+
{
|
|
636
|
+
state.ret = -1;
|
|
637
|
+
}
|
|
638
|
+
else if (0 < node.flags.max)
|
|
639
|
+
{
|
|
640
|
+
state.ret = node.flags.max*max;
|
|
641
|
+
}
|
|
642
|
+
else
|
|
643
|
+
{
|
|
644
|
+
state.ret = max;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return null;
|
|
648
|
+
}
|
|
649
|
+
else if ((T_GROUP === type) && node.flags.GroupIndex)
|
|
650
|
+
{
|
|
651
|
+
var max = walk(0, node.val, state);
|
|
652
|
+
state.group[node.flags.GroupIndex] = max;
|
|
653
|
+
state.ret = max;
|
|
654
|
+
return null;
|
|
655
|
+
}
|
|
656
|
+
else
|
|
657
|
+
{
|
|
658
|
+
return node.val;
|
|
659
|
+
}
|
|
660
|
+
},
|
|
661
|
+
map_1st = function map_1st(ret, node, state) {
|
|
662
|
+
var type = node.type;
|
|
663
|
+
if (T_SEQUENCE === type)
|
|
664
|
+
{
|
|
665
|
+
var seq=[], i=0, l=node.val.length, n;
|
|
666
|
+
for (i=0; i<l; ++i)
|
|
667
|
+
{
|
|
668
|
+
n = node.val[i];
|
|
669
|
+
seq.push( n );
|
|
670
|
+
if ((T_QUANTIFIER === n.type) && (0 === n.flags.min))
|
|
671
|
+
continue;
|
|
672
|
+
else if ((T_SPECIAL === n.type) && (n.flags.MatchStart || n.flags.MatchEnd))
|
|
673
|
+
continue;
|
|
674
|
+
break;
|
|
675
|
+
}
|
|
676
|
+
return seq.length ? seq : null;
|
|
677
|
+
}
|
|
678
|
+
else
|
|
679
|
+
{
|
|
680
|
+
return node.val;
|
|
681
|
+
}
|
|
682
|
+
},
|
|
683
|
+
reduce_len = function reduce_len(ret, node, state) {
|
|
684
|
+
if (null != state.ret)
|
|
685
|
+
{
|
|
686
|
+
if (-1 === state.ret) ret = -1;
|
|
687
|
+
else ret += state.ret;
|
|
688
|
+
return ret;
|
|
689
|
+
}
|
|
690
|
+
if (-1 === ret) return ret;
|
|
691
|
+
|
|
692
|
+
if (node === +node)
|
|
693
|
+
{
|
|
694
|
+
ret += node;
|
|
695
|
+
return ret;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
if ((T_SPECIAL === node.type) && node.flags.MatchEnd)
|
|
699
|
+
{
|
|
700
|
+
state.stop = 1;
|
|
701
|
+
return ret;
|
|
702
|
+
}
|
|
703
|
+
var type = node.type;
|
|
704
|
+
|
|
705
|
+
if (
|
|
706
|
+
(T_CHARS === type) || (T_CHARRANGE === type) ||
|
|
707
|
+
(T_UNICODECHAR === type) || (T_HEXCHAR === type) ||
|
|
708
|
+
((T_SPECIAL === type) && !node.flags.MatchStart && !node.flags.MatchEnd)
|
|
709
|
+
)
|
|
710
|
+
{
|
|
711
|
+
ret += node.flags.BackReference ? state.group[node.flags.GroupIndex]||0 : 1;
|
|
712
|
+
}
|
|
713
|
+
else if (T_STRING === type)
|
|
714
|
+
{
|
|
715
|
+
ret += node.val.length;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
return ret;
|
|
719
|
+
},
|
|
720
|
+
reduce_str = function reduce_str(ret, node, state) {
|
|
721
|
+
if (null != state.ret)
|
|
722
|
+
{
|
|
723
|
+
ret += state.ret;
|
|
724
|
+
return ret;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
if (is_string(node))
|
|
728
|
+
{
|
|
729
|
+
ret += node;
|
|
730
|
+
return ret;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
if ((T_SPECIAL === node.type) && node.flags.MatchEnd)
|
|
734
|
+
{
|
|
735
|
+
state.stop = 1;
|
|
736
|
+
return ret;
|
|
737
|
+
}
|
|
738
|
+
var type = node.type, sample = null;
|
|
739
|
+
|
|
740
|
+
if (T_CHARS === type)
|
|
741
|
+
{
|
|
742
|
+
sample = node.val;
|
|
743
|
+
}
|
|
744
|
+
else if (T_CHARRANGE === type)
|
|
745
|
+
{
|
|
746
|
+
var range = [node.val[0], node.val[1]];
|
|
747
|
+
if (T_UNICODECHAR === range[0].type || T_HEXCHAR === range[0].type) range[0] = range[0].flags.Char;
|
|
748
|
+
if (T_UNICODECHAR === range[1].type || T_HEXCHAR === range[1].type) range[1] = range[1].flags.Char;
|
|
749
|
+
sample = character_range(range);
|
|
750
|
+
}
|
|
751
|
+
else if ((T_UNICODECHAR === type) || (T_HEXCHAR === type))
|
|
752
|
+
{
|
|
753
|
+
sample = [node.flags.Char];
|
|
754
|
+
}
|
|
755
|
+
else if ((T_SPECIAL === type) && !node.flags.MatchStart && !node.flags.MatchEnd)
|
|
756
|
+
{
|
|
757
|
+
var part = node.val;
|
|
758
|
+
if (node.flags.BackReference)
|
|
759
|
+
{
|
|
760
|
+
part = node.flags.GroupIndex;
|
|
761
|
+
ret += HAS.call(state.group, part) ? state.group[part] : '';
|
|
762
|
+
return ret;
|
|
763
|
+
}
|
|
764
|
+
else if ('D' === part)
|
|
765
|
+
{
|
|
766
|
+
sample = [digit(false)];
|
|
767
|
+
}
|
|
768
|
+
else if ('W' === part)
|
|
769
|
+
{
|
|
770
|
+
sample = [word(false)];
|
|
771
|
+
}
|
|
772
|
+
else if ('S' === part)
|
|
773
|
+
{
|
|
774
|
+
sample = [space(false)];
|
|
775
|
+
}
|
|
776
|
+
else if ('d' === part)
|
|
777
|
+
{
|
|
778
|
+
sample = [digit()];
|
|
779
|
+
}
|
|
780
|
+
else if ('w' === part)
|
|
781
|
+
{
|
|
782
|
+
sample = [word()];
|
|
783
|
+
}
|
|
784
|
+
else if ('s' === part)
|
|
785
|
+
{
|
|
786
|
+
sample = [space()];
|
|
787
|
+
}
|
|
788
|
+
else if (('.' === part) && node.flags.MatchAnyChar)
|
|
789
|
+
{
|
|
790
|
+
sample = [any()];
|
|
791
|
+
}
|
|
792
|
+
else
|
|
793
|
+
{
|
|
794
|
+
sample = [ESC + part];
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
else if (T_STRING === type)
|
|
798
|
+
{
|
|
799
|
+
sample = node.val;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
if (sample)
|
|
803
|
+
{
|
|
804
|
+
ret += T_STRING === type ?
|
|
805
|
+
(state.isCaseInsensitive ? case_insensitive(sample) : sample) :
|
|
806
|
+
(character(state.isCaseInsensitive ? case_insensitive(sample, true) : sample, !state.node || !state.node.flags.NegativeMatch))
|
|
807
|
+
;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
return ret;
|
|
811
|
+
},
|
|
812
|
+
reduce_src = function reduce_src(ret, node, state) {
|
|
813
|
+
if (null != state.ret)
|
|
814
|
+
{
|
|
815
|
+
if (state.ret.src) ret.src += state.ret.src;
|
|
816
|
+
if (state.ret.group) ret.group = clone(state.ret.group, ret.group);
|
|
817
|
+
return ret;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
if (is_string(node))
|
|
821
|
+
{
|
|
822
|
+
ret.src += node;
|
|
823
|
+
return ret;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
var type = node.type;
|
|
827
|
+
if (T_CHARS === type)
|
|
828
|
+
{
|
|
829
|
+
ret.src += state.escaped ? esc_re(node.val.join(''), ESC, 1) : node.val.join('');
|
|
830
|
+
}
|
|
831
|
+
else if (T_CHARRANGE === type)
|
|
832
|
+
{
|
|
833
|
+
var range = [node.val[0], node.val[1]];
|
|
834
|
+
if (state.escaped)
|
|
835
|
+
{
|
|
836
|
+
if (T_UNICODECHAR === range[0].type) range[0] = range[0].flags.UnicodePoint ? ESC+'u{'+range[0].flags.Code+'}' : ESC+'u'+pad(range[0].flags.Code,4);
|
|
837
|
+
else if (T_HEXCHAR === range[0].type) range[0] = ESC+'x'+pad(range[0].flags.Code,2);
|
|
838
|
+
else range[0] = esc_re(range[0], ESC, 1);
|
|
839
|
+
if (T_UNICODECHAR === range[1].type) range[1] = range[1].flags.UnicodePoint ? ESC+'u{'+range[1].flags.Code+'}' : ESC+'u'+pad(range[1].flags.Code,4);
|
|
840
|
+
else if (T_HEXCHAR === range[1].type) range[1] = ESC+'x'+pad(range[1].flags.Code,2);
|
|
841
|
+
else range[1] = esc_re(range[1], ESC, 1);
|
|
842
|
+
}
|
|
843
|
+
else
|
|
844
|
+
{
|
|
845
|
+
if (T_UNICODECHAR === range[0].type || T_HEXCHAR === range[0].type) range[0] = range[0].flags.Char;
|
|
846
|
+
if (T_UNICODECHAR === range[1].type || T_HEXCHAR === range[1].type) range[1] = range[1].flags.Char;
|
|
847
|
+
}
|
|
848
|
+
ret.src += range[0]+'-'+range[1];
|
|
849
|
+
}
|
|
850
|
+
else if (T_UNICODECHAR === type)
|
|
851
|
+
{
|
|
852
|
+
ret.src += node.flags.UnicodePoint ? ESC+'u{'+node.flags.Code+'}' : (state.escaped ? ESC+'u'+pad(node.flags.Code,4) : node.flags.Char);
|
|
853
|
+
}
|
|
854
|
+
else if (T_HEXCHAR === type)
|
|
855
|
+
{
|
|
856
|
+
ret.src += state.escaped ? ESC+'x'+pad(node.flags.Code,2) : node.flags.Char;
|
|
857
|
+
}
|
|
858
|
+
else if (T_SPECIAL === type)
|
|
859
|
+
{
|
|
860
|
+
if (node.flags.BackReference)
|
|
861
|
+
{
|
|
862
|
+
if (state.compatibility || (node.flags.GroupIndex === node.flags.GroupName))
|
|
863
|
+
{
|
|
864
|
+
ret.src += ESC+node.flags.GroupIndex;
|
|
865
|
+
}
|
|
866
|
+
else
|
|
867
|
+
{
|
|
868
|
+
ret.src += ESC+'k<'+node.flags.GroupName+'>';
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
else
|
|
872
|
+
{
|
|
873
|
+
ret.src += node.flags.MatchAnyChar || node.flags.MatchStart || node.flags.MatchEnd ? (''+node.val) : (ESC+node.val);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
else if (T_STRING === type)
|
|
877
|
+
{
|
|
878
|
+
ret.src += state.escaped ? esc_re(node.val, ESC) : node.val;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
return ret;
|
|
882
|
+
},
|
|
883
|
+
reduce_peek = function reduce_peek(ret, node, state) {
|
|
884
|
+
if (null != state.ret)
|
|
885
|
+
{
|
|
886
|
+
ret.positive = concat(ret.positive, state.ret.positive);
|
|
887
|
+
ret.negative = concat(ret.negative, state.ret.negative);
|
|
888
|
+
return ret;
|
|
889
|
+
}
|
|
890
|
+
if ((T_SPECIAL === node.type) && node.flags.MatchEnd)
|
|
891
|
+
{
|
|
892
|
+
state.stop = 1;
|
|
893
|
+
return ret;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
var type = node.type, inCharGroup = state.node && (T_CHARGROUP === state.node.type),
|
|
897
|
+
inNegativeCharGroup = inCharGroup && state.node.flags.NegativeMatch,
|
|
898
|
+
peek = inNegativeCharGroup ? "negative" : "positive";
|
|
899
|
+
|
|
900
|
+
if (T_CHARS === type)
|
|
901
|
+
{
|
|
902
|
+
ret[peek] = concat(ret[peek], node.val);
|
|
903
|
+
}
|
|
904
|
+
else if (T_CHARRANGE === type)
|
|
905
|
+
{
|
|
906
|
+
var range = [node.val[0],node.val[1]];
|
|
907
|
+
if (T_UNICODECHAR === range[0].type || T_HEXCHAR === range[0].type) range[0] = range[0].flags.Char;
|
|
908
|
+
if (T_UNICODECHAR === range[1].type || T_HEXCHAR === range[1].type) range[1] = range[1].flags.Char;
|
|
909
|
+
ret[peek] = concat(ret[peek], character_range(range));
|
|
910
|
+
}
|
|
911
|
+
else if ((T_UNICODECHAR === type) || (T_HEXCHAR === type))
|
|
912
|
+
{
|
|
913
|
+
ret[peek][node.flags.Char] = 1;
|
|
914
|
+
}
|
|
915
|
+
else if ((T_SPECIAL === type) && !node.flags.BackReference && !node.flags.MatchStart && !node.flags.MatchEnd)
|
|
916
|
+
{
|
|
917
|
+
var part = node.val;
|
|
918
|
+
if ('D' === part)
|
|
919
|
+
{
|
|
920
|
+
ret[inNegativeCharGroup?"positive":"negative"][ '\\d' ] = 1;
|
|
921
|
+
}
|
|
922
|
+
else if ('W' === part)
|
|
923
|
+
{
|
|
924
|
+
ret[inNegativeCharGroup?"positive":"negative"][ '\\w' ] = 1;
|
|
925
|
+
}
|
|
926
|
+
else if ('S' === part)
|
|
927
|
+
{
|
|
928
|
+
ret[inNegativeCharGroup?"positive":"negative"][ '\\s' ] = 1;
|
|
929
|
+
}
|
|
930
|
+
else if ('B' === part)
|
|
931
|
+
{
|
|
932
|
+
ret[inNegativeCharGroup?"positive":"negative"][ '\\b' ] = 1;
|
|
933
|
+
}
|
|
934
|
+
else
|
|
935
|
+
{
|
|
936
|
+
ret[peek][ESC + part] = 1;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
else if (T_STRING === type)
|
|
940
|
+
{
|
|
941
|
+
ret["positive"][node.val[CHAR](0)] = 1;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
return ret;
|
|
945
|
+
},
|
|
946
|
+
|
|
947
|
+
match_hex = function(s) {
|
|
948
|
+
var m = false;
|
|
949
|
+
if ((s.length > 2) && ('x' === s[CHAR](0)))
|
|
950
|
+
{
|
|
951
|
+
if (match_char_ranges(HEXDIGITS_RANGES, s, 1, 2, 2)) return [m=s.slice(0,3), m.slice(1)];
|
|
952
|
+
}
|
|
953
|
+
return false;
|
|
954
|
+
},
|
|
955
|
+
match_unicode = function(s, flags) {
|
|
956
|
+
var m = false, l;
|
|
957
|
+
if ((s.length > 3) && ('u' === s[CHAR](0)))
|
|
958
|
+
{
|
|
959
|
+
if (flags.u && '{' === s[CHAR](1) && (l=match_char_ranges(HEXDIGITS_RANGES, s, 2, 1, 6)) && '}' === s[CHAR](l+2))
|
|
960
|
+
{
|
|
961
|
+
return [m=s.slice(0,l+3), m.slice(2, -1), 1];
|
|
962
|
+
}
|
|
963
|
+
else if (l=match_char_ranges(HEXDIGITS_RANGES, s, 1, 4, 4))
|
|
964
|
+
{
|
|
965
|
+
return [m=s.slice(0,l+1), m.slice(1), 0];
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
return false;
|
|
969
|
+
},
|
|
970
|
+
match_repeats = function(s) {
|
|
971
|
+
var l, sl = s.length, pos = 0, m = false, hasComma = false;
|
|
972
|
+
if ((sl > 2) && ('{' === s[CHAR](pos)))
|
|
973
|
+
{
|
|
974
|
+
m = ['', '', null];
|
|
975
|
+
++pos;
|
|
976
|
+
if (l=match_chars(SPACES, s, pos)) pos += l;
|
|
977
|
+
if (l=match_char_range(DIGITS_RANGE, s, pos))
|
|
978
|
+
{
|
|
979
|
+
m[1] = s.slice(pos, pos+l);
|
|
980
|
+
pos += l;
|
|
981
|
+
}
|
|
982
|
+
else
|
|
983
|
+
{
|
|
984
|
+
return false;
|
|
985
|
+
}
|
|
986
|
+
if (l=match_chars(SPACES, s, pos)) pos += l;
|
|
987
|
+
if ((pos < sl) && (',' === s[CHAR](pos))) {pos += 1; hasComma = true;}
|
|
988
|
+
if (l=match_chars(SPACES, s, pos)) pos += l;
|
|
989
|
+
if (l=match_char_range(DIGITS_RANGE, s, pos))
|
|
990
|
+
{
|
|
991
|
+
m[2] = s.slice(pos, pos+l);
|
|
992
|
+
pos += l;
|
|
993
|
+
}
|
|
994
|
+
if (l=match_chars(SPACES, s, pos)) pos += l;
|
|
995
|
+
if ((pos < sl) && ('}' === s[CHAR](pos)))
|
|
996
|
+
{
|
|
997
|
+
pos++;
|
|
998
|
+
m[0] = s.slice(0, pos);
|
|
999
|
+
if (!hasComma) m[2] = m[1];
|
|
1000
|
+
return m;
|
|
1001
|
+
}
|
|
1002
|
+
else
|
|
1003
|
+
{
|
|
1004
|
+
return false;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
return false;
|
|
1008
|
+
},
|
|
1009
|
+
chargroup = function chargroup(re_obj) {
|
|
1010
|
+
var sequence = [], chars = [], allchars = [], flags = {}, flag, ch, lre,
|
|
1011
|
+
prevch = null, range, isRange = false, m, isUnicode, isHex, isSpecial, escaped = false;
|
|
1012
|
+
|
|
1013
|
+
if ('^' === re_obj.re[CHAR](re_obj.pos))
|
|
1014
|
+
{
|
|
1015
|
+
flags["NegativeMatch"] = 1;
|
|
1016
|
+
++re_obj.pos;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
lre = re_obj.len;
|
|
1020
|
+
while (re_obj.pos < lre)
|
|
1021
|
+
{
|
|
1022
|
+
isUnicode = false;
|
|
1023
|
+
isHex = false;
|
|
1024
|
+
isSpecial = false;
|
|
1025
|
+
m = null;
|
|
1026
|
+
prevch = ch;
|
|
1027
|
+
ch = re_obj.re[CHAR](re_obj.pos++);
|
|
1028
|
+
|
|
1029
|
+
escaped = ESC === ch;
|
|
1030
|
+
if (escaped) ch = re_obj.re[CHAR](re_obj.pos++);
|
|
1031
|
+
|
|
1032
|
+
if (escaped)
|
|
1033
|
+
{
|
|
1034
|
+
// unicode character
|
|
1035
|
+
if ('u' === ch)
|
|
1036
|
+
{
|
|
1037
|
+
m = match_unicode(re_obj.re.substr(re_obj.pos-1), re_obj.flags);
|
|
1038
|
+
if (m)
|
|
1039
|
+
{
|
|
1040
|
+
re_obj.pos += m[0].length-1;
|
|
1041
|
+
ch = Node(T_UNICODECHAR, m[0], {"Char": m[2] ? fromCodePoint(parseInt(m[1], 16)) : fromCharCode(parseInt(m[1], 16)), "Code": m[1], "UnicodePoint": !!m[2]});
|
|
1042
|
+
isUnicode = true; isHex = false;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
// hex character
|
|
1047
|
+
else if ('x' === ch)
|
|
1048
|
+
{
|
|
1049
|
+
m = match_hex(re_obj.re.substr(re_obj.pos-1));
|
|
1050
|
+
if (m)
|
|
1051
|
+
{
|
|
1052
|
+
re_obj.pos += m[0].length-1;
|
|
1053
|
+
ch = Node(T_HEXCHAR, m[0], {"Char": fromCharCode(parseInt(m[1], 16)), "Code": m[1]});
|
|
1054
|
+
isUnicode = true; isHex = true;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
// special character
|
|
1059
|
+
else if (HAS.call(specialCharsEscaped, ch) && ('/' !== ch))
|
|
1060
|
+
{
|
|
1061
|
+
isSpecial = true;
|
|
1062
|
+
flag = {};
|
|
1063
|
+
flag[specialCharsEscaped[ch]] = 1;
|
|
1064
|
+
ch = Node(T_SPECIAL, ch, flag);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
if (isRange)
|
|
1069
|
+
{
|
|
1070
|
+
if (
|
|
1071
|
+
(ch instanceof Node) &&
|
|
1072
|
+
(ch.type === T_SPECIAL) &&
|
|
1073
|
+
(-1 !== ['s','S','d','D','w','W'].indexOf(ch.val))
|
|
1074
|
+
)
|
|
1075
|
+
{
|
|
1076
|
+
if (range[0] instanceof Node)
|
|
1077
|
+
{
|
|
1078
|
+
sequence.push(range[0]);
|
|
1079
|
+
}
|
|
1080
|
+
else
|
|
1081
|
+
{
|
|
1082
|
+
chars.push(range[0]);
|
|
1083
|
+
}
|
|
1084
|
+
chars.push('-');
|
|
1085
|
+
sequence.push(ch);
|
|
1086
|
+
}
|
|
1087
|
+
else
|
|
1088
|
+
{
|
|
1089
|
+
if (chars.length)
|
|
1090
|
+
{
|
|
1091
|
+
allchars = allchars.concat(chars);
|
|
1092
|
+
chars = [];
|
|
1093
|
+
}
|
|
1094
|
+
range[1] = ch;
|
|
1095
|
+
sequence.push(Node(T_CHARRANGE, range));
|
|
1096
|
+
}
|
|
1097
|
+
isRange = false;
|
|
1098
|
+
}
|
|
1099
|
+
else
|
|
1100
|
+
{
|
|
1101
|
+
if (escaped)
|
|
1102
|
+
{
|
|
1103
|
+
if (isUnicode)
|
|
1104
|
+
{
|
|
1105
|
+
if (chars.length)
|
|
1106
|
+
{
|
|
1107
|
+
allchars = allchars.concat(chars);
|
|
1108
|
+
chars = [];
|
|
1109
|
+
}
|
|
1110
|
+
sequence.push(ch);
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
else if (isSpecial)
|
|
1114
|
+
{
|
|
1115
|
+
if (chars.length)
|
|
1116
|
+
{
|
|
1117
|
+
allchars = allchars.concat(chars);
|
|
1118
|
+
chars = [];
|
|
1119
|
+
}
|
|
1120
|
+
sequence.push(ch);
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
else
|
|
1124
|
+
{
|
|
1125
|
+
chars.push(ch);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
else
|
|
1130
|
+
{
|
|
1131
|
+
// end of char group
|
|
1132
|
+
if (']' === ch)
|
|
1133
|
+
{
|
|
1134
|
+
if (chars.length)
|
|
1135
|
+
{
|
|
1136
|
+
allchars = allchars.concat(chars);
|
|
1137
|
+
chars = [];
|
|
1138
|
+
}
|
|
1139
|
+
// map all chars into one node
|
|
1140
|
+
if (allchars.length) sequence.push(Node(T_CHARS, allchars));
|
|
1141
|
+
return Node(T_CHARGROUP, sequence, flags);
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
else if ('-' === ch)
|
|
1145
|
+
{
|
|
1146
|
+
if (
|
|
1147
|
+
null == prevch ||
|
|
1148
|
+
']' === re_obj.re[CHAR](re_obj.pos) ||
|
|
1149
|
+
(
|
|
1150
|
+
(prevch instanceof Node) &&
|
|
1151
|
+
(prevch.type === T_SPECIAL) &&
|
|
1152
|
+
(-1 !== ['s','S','d','D','w','W'].indexOf(prevch.val))
|
|
1153
|
+
)
|
|
1154
|
+
)
|
|
1155
|
+
{
|
|
1156
|
+
// take it as literal
|
|
1157
|
+
// https://github.com/foo123/RegexAnalyzer/issues/5
|
|
1158
|
+
chars.push(ch);
|
|
1159
|
+
}
|
|
1160
|
+
else
|
|
1161
|
+
{
|
|
1162
|
+
range = [prevch, ''];
|
|
1163
|
+
if (prevch instanceof Node) sequence.pop(); else chars.pop();
|
|
1164
|
+
isRange = true;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
else
|
|
1169
|
+
{
|
|
1170
|
+
chars.push(ch);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
if (chars.length)
|
|
1176
|
+
{
|
|
1177
|
+
allchars = allchars.concat(chars);
|
|
1178
|
+
chars = [];
|
|
1179
|
+
}
|
|
1180
|
+
// map all chars into one node
|
|
1181
|
+
if (allchars.length) sequence.push(Node(T_CHARS, allchars));
|
|
1182
|
+
return Node(T_CHARGROUP, sequence, flags);
|
|
1183
|
+
},
|
|
1184
|
+
|
|
1185
|
+
analyze_re = function analyze_re(re_obj) {
|
|
1186
|
+
var lre, ch, m, word = '', wordlen = 0,
|
|
1187
|
+
alternation = [], sequence = [], flags = {},
|
|
1188
|
+
flag, escaped = false, pre, pre3, captured;
|
|
1189
|
+
|
|
1190
|
+
if (re_obj.inGroup > 0)
|
|
1191
|
+
{
|
|
1192
|
+
pre = re_obj.re.substr(re_obj.pos, 2);
|
|
1193
|
+
pre3 = re_obj.re.substr(re_obj.pos, 3);
|
|
1194
|
+
captured = 1;
|
|
1195
|
+
|
|
1196
|
+
if ("?P=" === pre3)
|
|
1197
|
+
{
|
|
1198
|
+
flags["BackReference"] = 1;
|
|
1199
|
+
flags["GroupName"] = '';
|
|
1200
|
+
re_obj.pos += 3;
|
|
1201
|
+
lre = re_obj.len;
|
|
1202
|
+
while (re_obj.pos < lre)
|
|
1203
|
+
{
|
|
1204
|
+
ch = re_obj.re[CHAR](re_obj.pos++);
|
|
1205
|
+
if (")" === ch) break;
|
|
1206
|
+
flags["GroupName"] += ch;
|
|
1207
|
+
}
|
|
1208
|
+
flags["GroupIndex"] = HAS.call(re_obj.group, flags["GroupName"]) ? re_obj.group[flags["GroupName"]] : null;
|
|
1209
|
+
return Node(T_SPECIAL, flags["GroupName"], flags);
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
else if ("?#" === pre)
|
|
1213
|
+
{
|
|
1214
|
+
flags["Comment"] = 1;
|
|
1215
|
+
re_obj.pos += 2;
|
|
1216
|
+
word = '';
|
|
1217
|
+
lre = re_obj.len;
|
|
1218
|
+
while (re_obj.pos < lre)
|
|
1219
|
+
{
|
|
1220
|
+
ch = re_obj.re[CHAR](re_obj.pos++);
|
|
1221
|
+
if (")" === ch) break;
|
|
1222
|
+
word += ch;
|
|
1223
|
+
}
|
|
1224
|
+
return Node(T_COMMENT, word);
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
else if ("?:" === pre)
|
|
1228
|
+
{
|
|
1229
|
+
flags["NotCaptured"] = 1;
|
|
1230
|
+
re_obj.pos += 2;
|
|
1231
|
+
captured = 0;
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
else if ("?=" === pre)
|
|
1235
|
+
{
|
|
1236
|
+
flags["LookAhead"] = 1;
|
|
1237
|
+
re_obj.pos += 2;
|
|
1238
|
+
captured = 0;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
else if ("?!" === pre)
|
|
1242
|
+
{
|
|
1243
|
+
flags["NegativeLookAhead"] = 1;
|
|
1244
|
+
re_obj.pos += 2;
|
|
1245
|
+
captured = 0;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
else if ("?<=" === pre3)
|
|
1249
|
+
{
|
|
1250
|
+
flags["LookBehind"] = 1;
|
|
1251
|
+
re_obj.pos += 3;
|
|
1252
|
+
captured = 0;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
else if ("?<!" === pre3)
|
|
1256
|
+
{
|
|
1257
|
+
flags["NegativeLookBehind"] = 1;
|
|
1258
|
+
re_obj.pos += 3;
|
|
1259
|
+
captured = 0;
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
else if (("?<" === pre) || ("?P<" === pre3))
|
|
1263
|
+
{
|
|
1264
|
+
// https://github.com/foo123/RegexAnalyzer/issues/6
|
|
1265
|
+
flags["NamedGroup"] = 1;
|
|
1266
|
+
flags["GroupName"] = '';
|
|
1267
|
+
re_obj.pos += "?<" === pre ? 2 : 3;
|
|
1268
|
+
lre = re_obj.len;
|
|
1269
|
+
while (re_obj.pos < lre)
|
|
1270
|
+
{
|
|
1271
|
+
ch = re_obj.re[CHAR](re_obj.pos++);
|
|
1272
|
+
if (">" === ch) break;
|
|
1273
|
+
flags["GroupName"] += ch;
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
++re_obj.index;
|
|
1278
|
+
if (captured)
|
|
1279
|
+
{
|
|
1280
|
+
++re_obj.groupIndex;
|
|
1281
|
+
flags["GroupIndex"] = re_obj.groupIndex;
|
|
1282
|
+
re_obj.group[flags["GroupIndex"]] = flags["GroupIndex"];
|
|
1283
|
+
if (flags["GroupName"]) re_obj.group[flags["GroupName"]] = flags["GroupIndex"];
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
lre = re_obj.len;
|
|
1288
|
+
while (re_obj.pos < lre)
|
|
1289
|
+
{
|
|
1290
|
+
ch = re_obj.re[CHAR](re_obj.pos++);
|
|
1291
|
+
|
|
1292
|
+
// \\abc
|
|
1293
|
+
escaped = ESC === ch;
|
|
1294
|
+
if (escaped) ch = re_obj.re[CHAR](re_obj.pos++);
|
|
1295
|
+
|
|
1296
|
+
if (escaped)
|
|
1297
|
+
{
|
|
1298
|
+
// unicode character
|
|
1299
|
+
if ('u' === ch)
|
|
1300
|
+
{
|
|
1301
|
+
m = match_unicode(re_obj.re.substr(re_obj.pos-1), re_obj.flags);
|
|
1302
|
+
if (m)
|
|
1303
|
+
{
|
|
1304
|
+
if (wordlen)
|
|
1305
|
+
{
|
|
1306
|
+
sequence.push(Node(T_STRING, word));
|
|
1307
|
+
word = '';
|
|
1308
|
+
wordlen = 0;
|
|
1309
|
+
}
|
|
1310
|
+
re_obj.pos += m[0].length-1;
|
|
1311
|
+
sequence.push(Node(T_UNICODECHAR, m[0], {"Char": m[2] ? fromCodePoint(parseInt(m[1], 16)) : fromCharCode(parseInt(m[1], 16)), "Code": m[1], "UnicodePoint": !!m[2]}));
|
|
1312
|
+
}
|
|
1313
|
+
else
|
|
1314
|
+
{
|
|
1315
|
+
word += ch;
|
|
1316
|
+
wordlen += 1;
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
// hex character
|
|
1321
|
+
else if ('x' === ch)
|
|
1322
|
+
{
|
|
1323
|
+
m = match_hex(re_obj.re.substr(re_obj.pos-1));
|
|
1324
|
+
if (m)
|
|
1325
|
+
{
|
|
1326
|
+
if (wordlen)
|
|
1327
|
+
{
|
|
1328
|
+
sequence.push(Node(T_STRING, word));
|
|
1329
|
+
word = '';
|
|
1330
|
+
wordlen = 0;
|
|
1331
|
+
}
|
|
1332
|
+
re_obj.pos += m[0].length-1;
|
|
1333
|
+
sequence.push(Node(T_HEXCHAR, m[0], {"Char": fromCharCode(parseInt(m[1], 16)), "Code": m[1]}));
|
|
1334
|
+
}
|
|
1335
|
+
else
|
|
1336
|
+
{
|
|
1337
|
+
word += ch;
|
|
1338
|
+
wordlen += 1;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
// js back-reference
|
|
1343
|
+
else if ('k' === ch && '<' === re_obj.re[CHAR](re_obj.pos))
|
|
1344
|
+
{
|
|
1345
|
+
// https://github.com/foo123/RegexAnalyzer/issues/6
|
|
1346
|
+
if (wordlen)
|
|
1347
|
+
{
|
|
1348
|
+
sequence.push(Node(T_STRING, word));
|
|
1349
|
+
word = '';
|
|
1350
|
+
wordlen = 0;
|
|
1351
|
+
}
|
|
1352
|
+
re_obj.pos++;
|
|
1353
|
+
word = '';
|
|
1354
|
+
while (re_obj.pos < lre)
|
|
1355
|
+
{
|
|
1356
|
+
ch = re_obj.re[CHAR](re_obj.pos);
|
|
1357
|
+
if ('>' === ch) {re_obj.pos++; break;}
|
|
1358
|
+
else {word += ch; re_obj.pos++;}
|
|
1359
|
+
}
|
|
1360
|
+
flag = {};
|
|
1361
|
+
flag["BackReference"] = 1;
|
|
1362
|
+
flag["GroupName"] = word;
|
|
1363
|
+
flag["GroupIndex"] = HAS.call(re_obj.group, word) ? re_obj.group[word] : null;
|
|
1364
|
+
sequence.push(Node(T_SPECIAL, word, flag));
|
|
1365
|
+
word = '';
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
else if (HAS.call(specialCharsEscaped, ch) && ('/' !== ch))
|
|
1369
|
+
{
|
|
1370
|
+
if (wordlen)
|
|
1371
|
+
{
|
|
1372
|
+
sequence.push( Node(T_STRING, word) );
|
|
1373
|
+
word = '';
|
|
1374
|
+
wordlen = 0;
|
|
1375
|
+
}
|
|
1376
|
+
flag = {};
|
|
1377
|
+
flag[ specialCharsEscaped[ch] ] = 1;
|
|
1378
|
+
sequence.push( Node(T_SPECIAL, ch, flag) );
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
else if (('1' <= ch) && ('9' >= ch))
|
|
1382
|
+
{
|
|
1383
|
+
if (wordlen)
|
|
1384
|
+
{
|
|
1385
|
+
sequence.push(Node(T_STRING, word));
|
|
1386
|
+
word = '';
|
|
1387
|
+
wordlen = 0;
|
|
1388
|
+
}
|
|
1389
|
+
word = ch;
|
|
1390
|
+
while (re_obj.pos < lre)
|
|
1391
|
+
{
|
|
1392
|
+
ch = re_obj.re[CHAR](re_obj.pos);
|
|
1393
|
+
if (('0' <= ch) && ('9' >= ch)) {word += ch; re_obj.pos++;}
|
|
1394
|
+
else break;
|
|
1395
|
+
}
|
|
1396
|
+
flag = {};
|
|
1397
|
+
flag['BackReference'] = 1;
|
|
1398
|
+
flag['GroupName'] = word;
|
|
1399
|
+
flag['GroupIndex'] = parseInt(word, 10);
|
|
1400
|
+
sequence.push(Node(T_SPECIAL, word, flag));
|
|
1401
|
+
word = '';
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
else
|
|
1405
|
+
{
|
|
1406
|
+
word += ch;
|
|
1407
|
+
wordlen += 1;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
else
|
|
1412
|
+
{
|
|
1413
|
+
// group end
|
|
1414
|
+
if ((re_obj.inGroup > 0) && (')' === ch))
|
|
1415
|
+
{
|
|
1416
|
+
if (wordlen)
|
|
1417
|
+
{
|
|
1418
|
+
sequence.push(Node(T_STRING, word));
|
|
1419
|
+
word = '';
|
|
1420
|
+
wordlen = 0;
|
|
1421
|
+
}
|
|
1422
|
+
if (alternation.length)
|
|
1423
|
+
{
|
|
1424
|
+
alternation.push(Node(T_SEQUENCE, sequence));
|
|
1425
|
+
sequence = [];
|
|
1426
|
+
flag = {};
|
|
1427
|
+
flag[specialChars['|']] = 1;
|
|
1428
|
+
return Node(T_GROUP, Node(T_ALTERNATION, alternation, flag), flags);
|
|
1429
|
+
}
|
|
1430
|
+
else
|
|
1431
|
+
{
|
|
1432
|
+
return Node(T_GROUP, Node(T_SEQUENCE, sequence), flags);
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
// parse alternation
|
|
1437
|
+
else if ('|' === ch)
|
|
1438
|
+
{
|
|
1439
|
+
if (wordlen)
|
|
1440
|
+
{
|
|
1441
|
+
sequence.push(Node(T_STRING, word));
|
|
1442
|
+
word = '';
|
|
1443
|
+
wordlen = 0;
|
|
1444
|
+
}
|
|
1445
|
+
alternation.push(Node(T_SEQUENCE, sequence));
|
|
1446
|
+
sequence = [];
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
// parse character group
|
|
1450
|
+
else if ('[' === ch)
|
|
1451
|
+
{
|
|
1452
|
+
if (wordlen)
|
|
1453
|
+
{
|
|
1454
|
+
sequence.push(Node(T_STRING, word));
|
|
1455
|
+
word = '';
|
|
1456
|
+
wordlen = 0;
|
|
1457
|
+
}
|
|
1458
|
+
sequence.push(chargroup(re_obj));
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
// parse sub-group
|
|
1462
|
+
else if ('(' === ch)
|
|
1463
|
+
{
|
|
1464
|
+
if (wordlen)
|
|
1465
|
+
{
|
|
1466
|
+
sequence.push(Node(T_STRING, word));
|
|
1467
|
+
word = '';
|
|
1468
|
+
wordlen = 0;
|
|
1469
|
+
}
|
|
1470
|
+
re_obj.inGroup += 1;
|
|
1471
|
+
sequence.push(analyze_re(re_obj));
|
|
1472
|
+
re_obj.inGroup -= 1;
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
// parse num repeats
|
|
1476
|
+
else if ('{' === ch)
|
|
1477
|
+
{
|
|
1478
|
+
if (wordlen)
|
|
1479
|
+
{
|
|
1480
|
+
sequence.push(Node(T_STRING, word));
|
|
1481
|
+
word = '';
|
|
1482
|
+
wordlen = 0;
|
|
1483
|
+
}
|
|
1484
|
+
m = match_repeats(re_obj.re.substr(re_obj.pos-1));
|
|
1485
|
+
re_obj.pos += m[0].length-1;
|
|
1486
|
+
flag = {val: m[0], "MatchMinimum": m[1], "MatchMaximum": m[2] || "unlimited", "min": parseInt(m[1],10), "max": m[2] ? parseInt(m[2],10) : -1};
|
|
1487
|
+
flag[specialChars[ch]] = 1;
|
|
1488
|
+
if ((re_obj.pos < lre) && ('?' === re_obj.re[CHAR](re_obj.pos)))
|
|
1489
|
+
{
|
|
1490
|
+
flag["isGreedy"] = 0;
|
|
1491
|
+
re_obj.pos++;
|
|
1492
|
+
}
|
|
1493
|
+
else
|
|
1494
|
+
{
|
|
1495
|
+
flag["isGreedy"] = 1;
|
|
1496
|
+
}
|
|
1497
|
+
var prev = sequence.pop();
|
|
1498
|
+
if ((T_STRING === prev.type) && (prev.val.length > 1))
|
|
1499
|
+
{
|
|
1500
|
+
sequence.push(Node(T_STRING, prev.val.slice(0, -1)));
|
|
1501
|
+
prev.val = prev.val.slice(-1);
|
|
1502
|
+
}
|
|
1503
|
+
sequence.push(Node(T_QUANTIFIER, prev, flag));
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
// quantifiers
|
|
1507
|
+
else if (('*' === ch) || ('+' === ch) || ('?' === ch))
|
|
1508
|
+
{
|
|
1509
|
+
if (wordlen)
|
|
1510
|
+
{
|
|
1511
|
+
sequence.push(Node(T_STRING, word));
|
|
1512
|
+
word = '';
|
|
1513
|
+
wordlen = 0;
|
|
1514
|
+
}
|
|
1515
|
+
flag = {};
|
|
1516
|
+
flag[specialChars[ch]] = 1;
|
|
1517
|
+
flag["min"] = '+' === ch ? 1 : 0;
|
|
1518
|
+
flag["max"] = '?' === ch ? 1 : -1;
|
|
1519
|
+
if ((re_obj.pos < lre) && ('?' === re_obj.re[CHAR](re_obj.pos)))
|
|
1520
|
+
{
|
|
1521
|
+
flag["isGreedy"] = 0;
|
|
1522
|
+
re_obj.pos++;
|
|
1523
|
+
}
|
|
1524
|
+
else
|
|
1525
|
+
{
|
|
1526
|
+
flag["isGreedy"] = 1;
|
|
1527
|
+
}
|
|
1528
|
+
var prev = sequence.pop();
|
|
1529
|
+
if ((T_STRING === prev.type) && (prev.val.length > 1))
|
|
1530
|
+
{
|
|
1531
|
+
sequence.push(Node(T_STRING, prev.val.slice(0, -1)));
|
|
1532
|
+
prev.val = prev.val.slice(-1);
|
|
1533
|
+
}
|
|
1534
|
+
sequence.push(Node(T_QUANTIFIER, prev, flag));
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
// special characters like ^, $, ., etc..
|
|
1538
|
+
else if (HAS.call(specialChars,ch))
|
|
1539
|
+
{
|
|
1540
|
+
if (wordlen)
|
|
1541
|
+
{
|
|
1542
|
+
sequence.push(Node(T_STRING, word));
|
|
1543
|
+
word = '';
|
|
1544
|
+
wordlen = 0;
|
|
1545
|
+
}
|
|
1546
|
+
flag = {};
|
|
1547
|
+
flag[specialChars[ch]] = 1;
|
|
1548
|
+
sequence.push(Node(T_SPECIAL, ch, flag));
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
else
|
|
1552
|
+
{
|
|
1553
|
+
word += ch;
|
|
1554
|
+
wordlen += 1;
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
if (wordlen)
|
|
1560
|
+
{
|
|
1561
|
+
sequence.push(Node(T_STRING, word));
|
|
1562
|
+
word = '';
|
|
1563
|
+
wordlen = 0;
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
if (alternation.length)
|
|
1567
|
+
{
|
|
1568
|
+
alternation.push(Node(T_SEQUENCE, sequence));
|
|
1569
|
+
sequence = [];
|
|
1570
|
+
flag = {};
|
|
1571
|
+
flags[specialChars['|']] = 1;
|
|
1572
|
+
return Node(T_ALTERNATION, alternation, flag);
|
|
1573
|
+
}
|
|
1574
|
+
return Node(T_SEQUENCE, sequence);
|
|
1575
|
+
}
|
|
1576
|
+
;
|
|
1577
|
+
|
|
1578
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
|
|
1579
|
+
// https://docs.python.org/3/library/re.html
|
|
1580
|
+
// http://php.net/manual/en/reference.pcre.pattern.syntax.php
|
|
1581
|
+
// A simple regular expression analyzer
|
|
1582
|
+
function Analyzer(re, delim, flavor)
|
|
1583
|
+
{
|
|
1584
|
+
if (!(this instanceof Analyzer)) return new Analyzer(re, delim, flavor);
|
|
1585
|
+
if (re) this.input(re, delim, flavor);
|
|
1586
|
+
}
|
|
1587
|
+
Analyzer.VERSION = __version__;
|
|
1588
|
+
Analyzer[PROTO] = {
|
|
1589
|
+
|
|
1590
|
+
constructor: Analyzer,
|
|
1591
|
+
|
|
1592
|
+
ast: null,
|
|
1593
|
+
flavor: '',
|
|
1594
|
+
re: null,
|
|
1595
|
+
fl: null,
|
|
1596
|
+
src: null,
|
|
1597
|
+
grp: null,
|
|
1598
|
+
min: null,
|
|
1599
|
+
max: null,
|
|
1600
|
+
ch: null,
|
|
1601
|
+
bc: true,
|
|
1602
|
+
|
|
1603
|
+
dispose: function() {
|
|
1604
|
+
var self = this;
|
|
1605
|
+
self.ast = null;
|
|
1606
|
+
self.flavor = null;
|
|
1607
|
+
self.re = null;
|
|
1608
|
+
self.fl = null;
|
|
1609
|
+
self.src = null;
|
|
1610
|
+
self.grp = null;
|
|
1611
|
+
self.min = null;
|
|
1612
|
+
self.max = null;
|
|
1613
|
+
self.ch = null;
|
|
1614
|
+
return self;
|
|
1615
|
+
},
|
|
1616
|
+
|
|
1617
|
+
reset: function() {
|
|
1618
|
+
var self = this;
|
|
1619
|
+
self.ast = null;
|
|
1620
|
+
self.src = null;
|
|
1621
|
+
self.grp = null;
|
|
1622
|
+
self.min = null;
|
|
1623
|
+
self.max = null;
|
|
1624
|
+
self.ch = null;
|
|
1625
|
+
return self;
|
|
1626
|
+
},
|
|
1627
|
+
|
|
1628
|
+
backwardsCompatible: function(enable) {
|
|
1629
|
+
this.bc = !!enable;
|
|
1630
|
+
return this;
|
|
1631
|
+
},
|
|
1632
|
+
|
|
1633
|
+
input: function(re, delim, flavor) {
|
|
1634
|
+
var self = this;
|
|
1635
|
+
if (!arguments.length) return self.re;
|
|
1636
|
+
if (re)
|
|
1637
|
+
{
|
|
1638
|
+
delim = false === delim ? false : (delim || '/');
|
|
1639
|
+
var l, ch, fl = {};
|
|
1640
|
+
re = re.toString();
|
|
1641
|
+
l = re.length;
|
|
1642
|
+
|
|
1643
|
+
if (delim)
|
|
1644
|
+
{
|
|
1645
|
+
// parse re flags, if any
|
|
1646
|
+
while (0 < l)
|
|
1647
|
+
{
|
|
1648
|
+
ch = re[CHAR](l-1);
|
|
1649
|
+
if (delim === ch) break;
|
|
1650
|
+
else {fl[ch] = 1; --l;}
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
if (0 < l)
|
|
1654
|
+
{
|
|
1655
|
+
// remove re delimiters
|
|
1656
|
+
if ((delim === re[CHAR](0)) && (delim === re[CHAR](l-1))) re = re.slice(1, l-1);
|
|
1657
|
+
else re = re.slice(0, l);
|
|
1658
|
+
}
|
|
1659
|
+
else
|
|
1660
|
+
{
|
|
1661
|
+
re = '';
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
// re is different, reset the ast, etc
|
|
1666
|
+
if (self.re !== re) self.reset();
|
|
1667
|
+
self.re = re; self.fl = fl; self.flavor = String(flavor || '');
|
|
1668
|
+
}
|
|
1669
|
+
return self;
|
|
1670
|
+
},
|
|
1671
|
+
|
|
1672
|
+
analyze: function() {
|
|
1673
|
+
var self = this;
|
|
1674
|
+
if ((null != self.re) && (null === self.ast))
|
|
1675
|
+
{
|
|
1676
|
+
var re = new RE_OBJ(self.re, self.fl, self.flavor);
|
|
1677
|
+
self.ast = analyze_re(re);
|
|
1678
|
+
re.dispose();
|
|
1679
|
+
}
|
|
1680
|
+
return self;
|
|
1681
|
+
},
|
|
1682
|
+
|
|
1683
|
+
synthesize: function(escaped) {
|
|
1684
|
+
var self = this, state, re;
|
|
1685
|
+
if (null == self.re) return self;
|
|
1686
|
+
if (null === self.ast)
|
|
1687
|
+
{
|
|
1688
|
+
self.analyze();
|
|
1689
|
+
self.src = null;
|
|
1690
|
+
self.grp = null;
|
|
1691
|
+
}
|
|
1692
|
+
if (null === self.src)
|
|
1693
|
+
{
|
|
1694
|
+
state = {
|
|
1695
|
+
MAP : T_SEQUENCE|T_ALTERNATION|T_GROUP|T_CHARGROUP|T_QUANTIFIER,
|
|
1696
|
+
REDUCE : T_UNICODECHAR|T_HEXCHAR|T_SPECIAL|T_CHARS|T_CHARRANGE|T_STRING,
|
|
1697
|
+
IGNORE : T_COMMENT,
|
|
1698
|
+
map : map_src,
|
|
1699
|
+
reduce : reduce_src,
|
|
1700
|
+
escaped : false !== escaped,
|
|
1701
|
+
compatibility : self.bc,
|
|
1702
|
+
group : {}
|
|
1703
|
+
};
|
|
1704
|
+
re = walk({src:'',group:{}}, self.ast, state);
|
|
1705
|
+
self.src = re.src; self.grp = re.group;
|
|
1706
|
+
}
|
|
1707
|
+
return self;
|
|
1708
|
+
},
|
|
1709
|
+
|
|
1710
|
+
source: function() {
|
|
1711
|
+
var self = this;
|
|
1712
|
+
if (null == self.re) return null;
|
|
1713
|
+
if (null === self.src) self.synthesize();
|
|
1714
|
+
return self.src;
|
|
1715
|
+
},
|
|
1716
|
+
|
|
1717
|
+
groups: function(raw) {
|
|
1718
|
+
var self = this;
|
|
1719
|
+
if (null == self.re) return null;
|
|
1720
|
+
if (null === self.grp) self.synthesize();
|
|
1721
|
+
return true === raw ? sel.grp : clone(self.grp);
|
|
1722
|
+
},
|
|
1723
|
+
|
|
1724
|
+
compile: function(flags, notBackwardsCompatible) {
|
|
1725
|
+
var self = this;
|
|
1726
|
+
if (null == self.re) return null;
|
|
1727
|
+
flags = flags || self.fl || {};
|
|
1728
|
+
return new RegExp(self.source(), (flags.g||flags.G?'g':'')+(flags.i||flags.I?'i':'')+(flags.m||flags.M?'m':'')+(flags.y||flags.Y?'y':'')+(flags.u?'u':'')+(flags.d?'d':'')+(flags.s?'s':''));
|
|
1729
|
+
},
|
|
1730
|
+
|
|
1731
|
+
tree: function(flat) {
|
|
1732
|
+
var self = this;
|
|
1733
|
+
if (null == self.re) return null;
|
|
1734
|
+
if (null === self.ast) self.analyze();
|
|
1735
|
+
return true===flat ? self.ast.toObject() : self.ast;
|
|
1736
|
+
},
|
|
1737
|
+
|
|
1738
|
+
// experimental feature
|
|
1739
|
+
sample: function(maxlen, numsamples) {
|
|
1740
|
+
var self = this, state;
|
|
1741
|
+
if (null == self.re) return null;
|
|
1742
|
+
if (null === self.ast) self.analyze();
|
|
1743
|
+
state = {
|
|
1744
|
+
MAP : T_SEQUENCE|T_ALTERNATION|T_GROUP|T_CHARGROUP|T_QUANTIFIER,
|
|
1745
|
+
REDUCE : T_UNICODECHAR|T_HEXCHAR|T_SPECIAL|T_CHARS|T_CHARRANGE|T_STRING,
|
|
1746
|
+
IGNORE : T_COMMENT,
|
|
1747
|
+
map : map_any,
|
|
1748
|
+
reduce : reduce_str,
|
|
1749
|
+
maxLength : (maxlen|0) || 1,
|
|
1750
|
+
isCaseInsensitive : null != self.fl.i,
|
|
1751
|
+
group : {}
|
|
1752
|
+
};
|
|
1753
|
+
numsamples = (numsamples|0) || 1;
|
|
1754
|
+
if (1 < numsamples)
|
|
1755
|
+
{
|
|
1756
|
+
var samples = new Array(numsamples);
|
|
1757
|
+
for (var i=0; i<numsamples; ++i) samples[i] = walk('', self.ast, state);
|
|
1758
|
+
return samples;
|
|
1759
|
+
}
|
|
1760
|
+
return walk('', self.ast, state);
|
|
1761
|
+
},
|
|
1762
|
+
|
|
1763
|
+
// experimental feature
|
|
1764
|
+
minimum: function() {
|
|
1765
|
+
var self = this, state;
|
|
1766
|
+
if (null == self.re) return 0;
|
|
1767
|
+
if (null === self.ast)
|
|
1768
|
+
{
|
|
1769
|
+
self.analyze( );
|
|
1770
|
+
self.min = null;
|
|
1771
|
+
}
|
|
1772
|
+
if (null === self.min)
|
|
1773
|
+
{
|
|
1774
|
+
state = {
|
|
1775
|
+
MAP : T_SEQUENCE|T_ALTERNATION|T_GROUP|T_CHARGROUP|T_QUANTIFIER,
|
|
1776
|
+
REDUCE : T_UNICODECHAR|T_HEXCHAR|T_SPECIAL|T_CHARS|T_CHARRANGE|T_STRING,
|
|
1777
|
+
IGNORE : T_COMMENT,
|
|
1778
|
+
map : map_min,
|
|
1779
|
+
reduce : reduce_len,
|
|
1780
|
+
group : {}
|
|
1781
|
+
};
|
|
1782
|
+
self.min = walk(0, self.ast, state)|0;
|
|
1783
|
+
}
|
|
1784
|
+
return self.min;
|
|
1785
|
+
},
|
|
1786
|
+
|
|
1787
|
+
// experimental feature
|
|
1788
|
+
maximum: function() {
|
|
1789
|
+
var self = this, state;
|
|
1790
|
+
if (null == self.re) return 0;
|
|
1791
|
+
if (null === self.ast)
|
|
1792
|
+
{
|
|
1793
|
+
self.analyze();
|
|
1794
|
+
self.max = null;
|
|
1795
|
+
}
|
|
1796
|
+
if (null === self.max)
|
|
1797
|
+
{
|
|
1798
|
+
state = {
|
|
1799
|
+
MAP : T_SEQUENCE|T_ALTERNATION|T_GROUP|T_CHARGROUP|T_QUANTIFIER,
|
|
1800
|
+
REDUCE : T_UNICODECHAR|T_HEXCHAR|T_SPECIAL|T_CHARS|T_CHARRANGE|T_STRING,
|
|
1801
|
+
IGNORE : T_COMMENT,
|
|
1802
|
+
map : map_max,
|
|
1803
|
+
reduce : reduce_len,
|
|
1804
|
+
group : {}
|
|
1805
|
+
};
|
|
1806
|
+
self.max = walk(0, self.ast, state);
|
|
1807
|
+
}
|
|
1808
|
+
return self.max;
|
|
1809
|
+
},
|
|
1810
|
+
|
|
1811
|
+
// experimental feature
|
|
1812
|
+
peek: function() {
|
|
1813
|
+
var self = this, state, isCaseInsensitive, peek, n, c, p, cases;
|
|
1814
|
+
if (null == self.re) return null;
|
|
1815
|
+
if (null === self.ast)
|
|
1816
|
+
{
|
|
1817
|
+
self.analyze();
|
|
1818
|
+
self.ch = null;
|
|
1819
|
+
}
|
|
1820
|
+
if (null === self.ch)
|
|
1821
|
+
{
|
|
1822
|
+
state = {
|
|
1823
|
+
MAP : T_SEQUENCE|T_ALTERNATION|T_GROUP|T_CHARGROUP|T_QUANTIFIER,
|
|
1824
|
+
REDUCE : T_UNICODECHAR|T_HEXCHAR|T_SPECIAL|T_CHARS|T_CHARRANGE|T_STRING,
|
|
1825
|
+
IGNORE : T_COMMENT,
|
|
1826
|
+
map : map_1st,
|
|
1827
|
+
reduce : reduce_peek,
|
|
1828
|
+
group : {},
|
|
1829
|
+
};
|
|
1830
|
+
self.ch = walk({positive:{},negative:{}}, self.ast, state);
|
|
1831
|
+
}
|
|
1832
|
+
peek = {positive:clone(self.ch.positive), negative:clone(self.ch.negative)};
|
|
1833
|
+
isCaseInsensitive = null != self.fl.i;
|
|
1834
|
+
for (n in peek)
|
|
1835
|
+
{
|
|
1836
|
+
cases = {};
|
|
1837
|
+
// either positive or negative
|
|
1838
|
+
p = peek[n];
|
|
1839
|
+
for (c in p)
|
|
1840
|
+
{
|
|
1841
|
+
if ('\\d' === c)
|
|
1842
|
+
{
|
|
1843
|
+
delete p[c];
|
|
1844
|
+
cases = concat(cases, character_range('0', '9'));
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1847
|
+
else if ('\\s' === c)
|
|
1848
|
+
{
|
|
1849
|
+
delete p[c];
|
|
1850
|
+
cases = concat(cases, ['\f','\n','\r','\t','\v','\u00A0','\u2028','\u2029']);
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
else if ('\\w' === c)
|
|
1854
|
+
{
|
|
1855
|
+
delete p[c];
|
|
1856
|
+
cases = concat(cases, ['_'].concat(character_range('0', '9')).concat(character_range('a', 'z')).concat(character_range('A', 'Z')));
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
else if ('\\b' === c)
|
|
1860
|
+
{
|
|
1861
|
+
delete p[c];
|
|
1862
|
+
cases[ specialChars['b'] ] = 1;
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
else if ('\\.' === c)
|
|
1866
|
+
{
|
|
1867
|
+
delete p[c];
|
|
1868
|
+
cases[ specialChars['.'] ] = 1;
|
|
1869
|
+
}
|
|
1870
|
+
|
|
1871
|
+
/*else if ('\\^' === c)
|
|
1872
|
+
{
|
|
1873
|
+
delete p[c];
|
|
1874
|
+
cases[ specialChars['^'] ] = 1;
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
else if ('\\$' === c)
|
|
1878
|
+
{
|
|
1879
|
+
delete p[c];
|
|
1880
|
+
cases[ specialChars['$'] ] = 1;
|
|
1881
|
+
}*/
|
|
1882
|
+
|
|
1883
|
+
else if ( (ESC !== c[CHAR](0)) && isCaseInsensitive )
|
|
1884
|
+
{
|
|
1885
|
+
cases[ c.toLowerCase() ] = 1;
|
|
1886
|
+
cases[ c.toUpperCase() ] = 1;
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
else if ( ESC === c[CHAR](0) )
|
|
1890
|
+
{
|
|
1891
|
+
delete p[c];
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
peek[n] = concat(p, cases);
|
|
1895
|
+
}
|
|
1896
|
+
return peek;
|
|
1897
|
+
}
|
|
1898
|
+
};
|
|
1899
|
+
// alias
|
|
1900
|
+
Analyzer[PROTO].set = Analyzer[PROTO].input;
|
|
1901
|
+
/*
|
|
1902
|
+
// custom method to access named groups feature, if any
|
|
1903
|
+
RegExp[PROTO].$group = null;
|
|
1904
|
+
RegExp[PROTO].group = function( group ){
|
|
1905
|
+
group = group || 0;
|
|
1906
|
+
return this.$group && this.$group.hasOwnProperty(group) ? this.$group[group] : group;
|
|
1907
|
+
};
|
|
1908
|
+
*/
|
|
1909
|
+
|
|
1910
|
+
// A simple regular expression composer
|
|
1911
|
+
function Composer()
|
|
1912
|
+
{
|
|
1913
|
+
var self = this;
|
|
1914
|
+
if (!(self instanceof Composer)) return new Composer();
|
|
1915
|
+
self.re = null;
|
|
1916
|
+
self.reset();
|
|
1917
|
+
}
|
|
1918
|
+
Composer.VERSION = __version__;
|
|
1919
|
+
Composer[PROTO] = {
|
|
1920
|
+
|
|
1921
|
+
constructor: Composer,
|
|
1922
|
+
|
|
1923
|
+
re: null,
|
|
1924
|
+
g: 0,
|
|
1925
|
+
grp: null,
|
|
1926
|
+
level: 0,
|
|
1927
|
+
ast: null,
|
|
1928
|
+
|
|
1929
|
+
dispose: function() {
|
|
1930
|
+
var self = this;
|
|
1931
|
+
self.re = null;
|
|
1932
|
+
self.g = null;
|
|
1933
|
+
self.grp = null;
|
|
1934
|
+
self.level = null;
|
|
1935
|
+
self.ast = null;
|
|
1936
|
+
return self;
|
|
1937
|
+
},
|
|
1938
|
+
|
|
1939
|
+
reset: function() {
|
|
1940
|
+
var self = this;
|
|
1941
|
+
self.g = 0;
|
|
1942
|
+
self.grp = {};
|
|
1943
|
+
self.level = 0;
|
|
1944
|
+
self.ast = [{node: [], type: T_SEQUENCE, flag: ''}];
|
|
1945
|
+
return self;
|
|
1946
|
+
},
|
|
1947
|
+
|
|
1948
|
+
compose: function(/* flags */) {
|
|
1949
|
+
var self = this,
|
|
1950
|
+
fl = slice(arguments).join(''),
|
|
1951
|
+
src = self.ast[0].node.join('');
|
|
1952
|
+
self.re = {
|
|
1953
|
+
source : src,
|
|
1954
|
+
flags : fl,
|
|
1955
|
+
groups : self.grp,
|
|
1956
|
+
pattern : RE(src, fl)
|
|
1957
|
+
};
|
|
1958
|
+
self.reset();
|
|
1959
|
+
return self.re;
|
|
1960
|
+
},
|
|
1961
|
+
|
|
1962
|
+
partial: function(reset) {
|
|
1963
|
+
var self = this, re = self.ast[0].node.join('');
|
|
1964
|
+
if (false !== reset) self.reset();
|
|
1965
|
+
return re;
|
|
1966
|
+
},
|
|
1967
|
+
|
|
1968
|
+
token: function(token, escaped) {
|
|
1969
|
+
var self = this;
|
|
1970
|
+
if (null != token)
|
|
1971
|
+
self.ast[self.level].node.push(escaped ? esc_re(String(token), ESC) : String(token));
|
|
1972
|
+
return self;
|
|
1973
|
+
},
|
|
1974
|
+
|
|
1975
|
+
literal: function(literal) {
|
|
1976
|
+
return this.token(String(literal), true);
|
|
1977
|
+
},
|
|
1978
|
+
|
|
1979
|
+
regexp: function(re) {
|
|
1980
|
+
return this.token(String(re), false);
|
|
1981
|
+
},
|
|
1982
|
+
|
|
1983
|
+
SOL: function() {
|
|
1984
|
+
var self = this;
|
|
1985
|
+
self.ast[self.level].node.push('^');
|
|
1986
|
+
return self;
|
|
1987
|
+
},
|
|
1988
|
+
|
|
1989
|
+
SOF: function() {
|
|
1990
|
+
return this.SOL();
|
|
1991
|
+
},
|
|
1992
|
+
|
|
1993
|
+
EOL: function() {
|
|
1994
|
+
var self = this;
|
|
1995
|
+
self.ast[self.level].node.push('$');
|
|
1996
|
+
return self;
|
|
1997
|
+
},
|
|
1998
|
+
|
|
1999
|
+
EOF: function() {
|
|
2000
|
+
return this.EOL();
|
|
2001
|
+
},
|
|
2002
|
+
|
|
2003
|
+
LF: function() {
|
|
2004
|
+
var self = this;
|
|
2005
|
+
self.ast[self.level].node.push(ESC+'n');
|
|
2006
|
+
return self;
|
|
2007
|
+
},
|
|
2008
|
+
|
|
2009
|
+
CR: function() {
|
|
2010
|
+
var self = this;
|
|
2011
|
+
self.ast[self.level].node.push(ESC+'r');
|
|
2012
|
+
return self;
|
|
2013
|
+
},
|
|
2014
|
+
|
|
2015
|
+
TAB: function() {
|
|
2016
|
+
var self = this;
|
|
2017
|
+
self.ast[self.level].node.push(ESC+'t');
|
|
2018
|
+
return self;
|
|
2019
|
+
},
|
|
2020
|
+
|
|
2021
|
+
CTRL: function(code) {
|
|
2022
|
+
var self = this;
|
|
2023
|
+
self.ast[self.level].node.push(ESC+'c'+(code||0));
|
|
2024
|
+
return self;
|
|
2025
|
+
},
|
|
2026
|
+
|
|
2027
|
+
HEX: function(code) {
|
|
2028
|
+
var self = this;
|
|
2029
|
+
self.ast[self.level].node.push(ESC+'x'+pad(code||0, 2));
|
|
2030
|
+
return self;
|
|
2031
|
+
},
|
|
2032
|
+
|
|
2033
|
+
UNICODE: function(code, uni) {
|
|
2034
|
+
var self = this;
|
|
2035
|
+
self.ast[self.level].node.push(true === uni ? ESC+'u{'+String(code||0)+'}' : ESC+'u'+pad(code||0, 4));
|
|
2036
|
+
return self;
|
|
2037
|
+
},
|
|
2038
|
+
|
|
2039
|
+
backSpace: function() {
|
|
2040
|
+
var self = this;
|
|
2041
|
+
self.ast[self.level].node.push('['+ESC+'b]');
|
|
2042
|
+
return self;
|
|
2043
|
+
},
|
|
2044
|
+
|
|
2045
|
+
any: function(multiline) {
|
|
2046
|
+
var self = this;
|
|
2047
|
+
self.ast[self.level].node.push(multiline ? '['+ESC+'s'+ESC+'S]' : '.');
|
|
2048
|
+
return self;
|
|
2049
|
+
},
|
|
2050
|
+
|
|
2051
|
+
space: function(positive) {
|
|
2052
|
+
var self = this;
|
|
2053
|
+
if (arguments.length < 1) positive = true;
|
|
2054
|
+
self.ast[self.level].node.push(!positive ? ESC+'S' : ESC+'s');
|
|
2055
|
+
return self;
|
|
2056
|
+
},
|
|
2057
|
+
|
|
2058
|
+
digit: function(positive) {
|
|
2059
|
+
var self = this;
|
|
2060
|
+
if (arguments.length < 1) positive = true;
|
|
2061
|
+
self.ast[self.level].node.push(!positive ? ESC+'D' : ESC+'d');
|
|
2062
|
+
return self;
|
|
2063
|
+
},
|
|
2064
|
+
|
|
2065
|
+
word: function(positive) {
|
|
2066
|
+
var self = this;
|
|
2067
|
+
if (arguments.length < 1) positive = true;
|
|
2068
|
+
self.ast[self.level].node.push(!positive ? ESC+'W' : ESC+'w');
|
|
2069
|
+
return self;
|
|
2070
|
+
},
|
|
2071
|
+
|
|
2072
|
+
boundary: function(positive) {
|
|
2073
|
+
var self = this;
|
|
2074
|
+
if (arguments.length < 1) positive = true;
|
|
2075
|
+
self.ast[self.level].node.push(!positive ? ESC+'B' : ESC+'b');
|
|
2076
|
+
return self;
|
|
2077
|
+
},
|
|
2078
|
+
|
|
2079
|
+
characters: function() {
|
|
2080
|
+
var self = this;
|
|
2081
|
+
if (T_CHARGROUP === self.ast[self.level].type)
|
|
2082
|
+
self.ast[self.level].node.push(getArgs(arguments,1).map(function(c){ return esc_re(String(c), ESC, 1); }).join(''));
|
|
2083
|
+
return self;
|
|
2084
|
+
},
|
|
2085
|
+
|
|
2086
|
+
range: function(start, end) {
|
|
2087
|
+
var self = this;
|
|
2088
|
+
if (null != start && null != end && T_CHARGROUP === self.ast[self.level].type)
|
|
2089
|
+
self.ast[self.level].node.push(esc_re(String(start), ESC, 1)+'-'+esc_re(String(end), ESC, 1));
|
|
2090
|
+
return self;
|
|
2091
|
+
},
|
|
2092
|
+
|
|
2093
|
+
backReference: function(n) {
|
|
2094
|
+
var self = this;
|
|
2095
|
+
self.ast[self.level].node.push(ESC+(HAS.call(self.grp, n) ? self.grp[n] : n|0));
|
|
2096
|
+
return self;
|
|
2097
|
+
},
|
|
2098
|
+
|
|
2099
|
+
repeat: function(min, max, greedy) {
|
|
2100
|
+
var self = this;
|
|
2101
|
+
if (null == min) return self;
|
|
2102
|
+
if (arguments.length < 3) greedy = true;
|
|
2103
|
+
var repeat = (null==max || min===max ? ('{'+String(min)+'}') : ('{'+String(min)+','+String(max)+'}')) + (!greedy ? '?' : '');
|
|
2104
|
+
self.ast[self.level].node[self.ast[self.level].node.length-1] += repeat;
|
|
2105
|
+
return self;
|
|
2106
|
+
},
|
|
2107
|
+
|
|
2108
|
+
zeroOrOne: function(greedy) {
|
|
2109
|
+
var self = this;
|
|
2110
|
+
if (arguments.length < 1) greedy = true;
|
|
2111
|
+
self.ast[self.level].node[self.ast[self.level].node.length-1] += (!greedy ? '??' : '?');
|
|
2112
|
+
return self;
|
|
2113
|
+
},
|
|
2114
|
+
|
|
2115
|
+
zeroOrMore: function(greedy) {
|
|
2116
|
+
var self = this;
|
|
2117
|
+
if (arguments.length < 1) greedy = true;
|
|
2118
|
+
self.ast[self.level].node[self.ast[self.level].node.length-1] += (!greedy ? '*?' : '*');
|
|
2119
|
+
return self;
|
|
2120
|
+
},
|
|
2121
|
+
|
|
2122
|
+
oneOrMore: function(greedy) {
|
|
2123
|
+
var self = this;
|
|
2124
|
+
if (arguments.length < 1) greedy = true;
|
|
2125
|
+
self.ast[self.level].node[self.ast[self.level].node.length-1] += (!greedy ? '+?' : '+');
|
|
2126
|
+
return self;
|
|
2127
|
+
},
|
|
2128
|
+
|
|
2129
|
+
alternate: function() {
|
|
2130
|
+
var self = this;
|
|
2131
|
+
self.level++;
|
|
2132
|
+
self.ast.push({node: [], type: T_ALTERNATION, flag: '', sequences: []});
|
|
2133
|
+
return self;
|
|
2134
|
+
},
|
|
2135
|
+
|
|
2136
|
+
either: function() {
|
|
2137
|
+
return this.alternate();
|
|
2138
|
+
},
|
|
2139
|
+
|
|
2140
|
+
or_: function() {
|
|
2141
|
+
var self = this, ast = self.ast[self.level];
|
|
2142
|
+
if ((T_ALTERNATION === ast.type) && ast.node.length)
|
|
2143
|
+
{
|
|
2144
|
+
ast.sequences.push(ast.node.join(''));
|
|
2145
|
+
ast.node = [];
|
|
2146
|
+
}
|
|
2147
|
+
return self;
|
|
2148
|
+
},
|
|
2149
|
+
|
|
2150
|
+
group: function(opts, v) {
|
|
2151
|
+
var self = this, type = T_GROUP, fl = '';
|
|
2152
|
+
if (is_string(opts))
|
|
2153
|
+
{
|
|
2154
|
+
fl = opts; opts = {};
|
|
2155
|
+
opts[fl] = v; fl = '';
|
|
2156
|
+
}
|
|
2157
|
+
else
|
|
2158
|
+
{
|
|
2159
|
+
opts = opts || {};
|
|
2160
|
+
}
|
|
2161
|
+
if (!!opts['name'] || !!opts['named'])
|
|
2162
|
+
{
|
|
2163
|
+
self.g++;
|
|
2164
|
+
self.grp[self.g] = self.g;
|
|
2165
|
+
self.grp[opts.name||opts.named] = self.g;
|
|
2166
|
+
}
|
|
2167
|
+
else if ((true === opts['lookahead']) || (false === opts['lookahead']))
|
|
2168
|
+
{
|
|
2169
|
+
fl = false === opts['lookahead'] ? '?!' : '?=';
|
|
2170
|
+
}
|
|
2171
|
+
else if ((true === opts['lookbehind']) || (false === opts['lookbehind']))
|
|
2172
|
+
{
|
|
2173
|
+
fl = false === opts['lookbehind'] ? '?<!' : '?<=';
|
|
2174
|
+
}
|
|
2175
|
+
else if (true === opts['nocapture'])
|
|
2176
|
+
{
|
|
2177
|
+
fl = '?:';
|
|
2178
|
+
}
|
|
2179
|
+
else if ((true === opts['characters']) || (false === opts['characters']))
|
|
2180
|
+
{
|
|
2181
|
+
type = T_CHARGROUP;
|
|
2182
|
+
fl = false === opts['characters'] ? '^' : '';
|
|
2183
|
+
}
|
|
2184
|
+
else
|
|
2185
|
+
{
|
|
2186
|
+
self.g++;
|
|
2187
|
+
self.grp[self.g] = self.g;
|
|
2188
|
+
}
|
|
2189
|
+
self.level++;
|
|
2190
|
+
self.ast.push({node: [], type: type, flag: fl});
|
|
2191
|
+
return self;
|
|
2192
|
+
},
|
|
2193
|
+
|
|
2194
|
+
subGroup: function(opts) {
|
|
2195
|
+
return this.group(opts);
|
|
2196
|
+
},
|
|
2197
|
+
|
|
2198
|
+
characterGroup: function(positive) {
|
|
2199
|
+
return this.group({'characters':false!==positive});
|
|
2200
|
+
},
|
|
2201
|
+
|
|
2202
|
+
namedGroup: function(name) {
|
|
2203
|
+
return this.group({'name':name});
|
|
2204
|
+
},
|
|
2205
|
+
|
|
2206
|
+
nonCaptureGroup: function() {
|
|
2207
|
+
return this.group({'nocapture':true});
|
|
2208
|
+
},
|
|
2209
|
+
|
|
2210
|
+
lookAheadGroup: function(positive) {
|
|
2211
|
+
return this.group({'lookahead':false!==positive});
|
|
2212
|
+
},
|
|
2213
|
+
|
|
2214
|
+
lookBehindGroup: function(positive) {
|
|
2215
|
+
return this.group({'lookbehind':false!==positive});
|
|
2216
|
+
},
|
|
2217
|
+
|
|
2218
|
+
end: function(n) {
|
|
2219
|
+
var self = this, prev, type, flag, part, sequences;
|
|
2220
|
+
n = (arguments.length ? n|0 : 1) || 1;
|
|
2221
|
+
// support ending multiple blocks at once
|
|
2222
|
+
while (n--)
|
|
2223
|
+
{
|
|
2224
|
+
prev = self.ast.length ? self.ast.pop() : null;
|
|
2225
|
+
type = prev ? prev.type : 0;
|
|
2226
|
+
flag = prev ? prev.flag : '';
|
|
2227
|
+
part = prev ? prev.node : [];
|
|
2228
|
+
if (T_ALTERNATION === type)
|
|
2229
|
+
{
|
|
2230
|
+
sequences = prev ? prev.sequences : [];
|
|
2231
|
+
part = !part.length ? sequences : sequences.concat(part.join(''));
|
|
2232
|
+
}
|
|
2233
|
+
if (0 < self.level)
|
|
2234
|
+
{
|
|
2235
|
+
--self.level;
|
|
2236
|
+
if (T_ALTERNATION === type)
|
|
2237
|
+
self.ast[self.level].node.push(part.join('|'));
|
|
2238
|
+
else if (T_GROUP === type)
|
|
2239
|
+
self.ast[self.level].node.push('('+flag+part.join('')+')');
|
|
2240
|
+
else if (T_CHARGROUP === type)
|
|
2241
|
+
self.ast[self.level].node.push('['+flag+part.join('')+']');
|
|
2242
|
+
else
|
|
2243
|
+
self.ast[self.level].node.push(part.join(''));
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
return self;
|
|
2247
|
+
}
|
|
2248
|
+
};
|
|
2249
|
+
// aliases
|
|
2250
|
+
var CP = Composer[PROTO];
|
|
2251
|
+
CP.startOfLine = CP.SOL;
|
|
2252
|
+
CP.endOfLine = CP.EOL;
|
|
2253
|
+
CP.startOfInput = CP.SOF;
|
|
2254
|
+
CP.endOfInput = CP.EOF;
|
|
2255
|
+
CP.match = CP.token;
|
|
2256
|
+
CP.sub = CP.regexp;
|
|
2257
|
+
CP.lineFeed = CP.LF;
|
|
2258
|
+
CP.carriageReturn = CP.CR;
|
|
2259
|
+
CP.tabulate = CP.TAB;
|
|
2260
|
+
CP.wordBoundary = CP.boundary;
|
|
2261
|
+
CP.chars = CP.characters;
|
|
2262
|
+
CP.charGroup = CP.characterGroup;
|
|
2263
|
+
CP.namedSubGroup = CP.namedGroup;
|
|
2264
|
+
CP.nonCaptureSubGroup = CP.nonCaptureGroup;
|
|
2265
|
+
CP.lookAheadSubGroup = CP.lookAheadGroup;
|
|
2266
|
+
CP.lookBehindSubGroup = CP.lookBehindGroup;
|
|
2267
|
+
|
|
2268
|
+
var Regex = {
|
|
2269
|
+
VERSION : __version__,
|
|
2270
|
+
Node : Node,
|
|
2271
|
+
Analyzer : Analyzer,
|
|
2272
|
+
Composer : Composer
|
|
2273
|
+
};
|
|
2274
|
+
/* export the module */
|
|
2275
|
+
return Regex;
|
|
2276
|
+
})();
|