interscript 0.1.7 → 2.1.0b1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/Gemfile +29 -0
- data/LICENSE.adoc +31 -0
- data/README.md +3 -0
- data/Rakefile +116 -0
- data/bin/console +14 -0
- data/bin/interscript +5 -0
- data/bin/maps_analyze_staging +168 -0
- data/bin/maps_debug_compilers +58 -0
- data/bin/maps_debug_ordering +88 -0
- data/bin/maps_debug_ruby_compile +24 -0
- data/bin/maps_debug_step_by_step +44 -0
- data/bin/maps_optimize_order +112 -0
- data/bin/maps_v1_analyze_regexps +45 -0
- data/bin/maps_v1_to_v2 +426 -0
- data/bin/setup +8 -0
- data/exe/interscript +6 -0
- data/interscript.gemspec +31 -0
- data/lib/interscript.rb +83 -133
- data/lib/interscript/command.rb +5 -5
- data/lib/interscript/compiler.rb +22 -0
- data/lib/interscript/compiler/javascript.rb +292 -0
- data/lib/interscript/compiler/ruby.rb +262 -0
- data/lib/interscript/dsl.rb +68 -0
- data/lib/interscript/dsl/aliases.rb +23 -0
- data/lib/interscript/dsl/document.rb +46 -0
- data/lib/interscript/dsl/group.rb +45 -0
- data/lib/interscript/dsl/group/parallel.rb +6 -0
- data/lib/interscript/dsl/items.rb +89 -0
- data/lib/interscript/dsl/metadata.rb +68 -0
- data/lib/interscript/dsl/stage.rb +6 -0
- data/lib/interscript/dsl/symbol_mm.rb +11 -0
- data/lib/interscript/dsl/tests.rb +12 -0
- data/lib/interscript/interpreter.rb +251 -0
- data/lib/interscript/node.rb +25 -0
- data/lib/interscript/node/alias_def.rb +15 -0
- data/lib/interscript/node/dependency.rb +13 -0
- data/lib/interscript/node/document.rb +45 -0
- data/lib/interscript/node/group.rb +34 -0
- data/lib/interscript/node/group/parallel.rb +9 -0
- data/lib/interscript/node/group/sequential.rb +2 -0
- data/lib/interscript/node/item.rb +52 -0
- data/lib/interscript/node/item/alias.rb +42 -0
- data/lib/interscript/node/item/any.rb +76 -0
- data/lib/interscript/node/item/capture.rb +50 -0
- data/lib/interscript/node/item/group.rb +51 -0
- data/lib/interscript/node/item/repeat.rb +40 -0
- data/lib/interscript/node/item/stage.rb +23 -0
- data/lib/interscript/node/item/string.rb +51 -0
- data/lib/interscript/node/metadata.rb +18 -0
- data/lib/interscript/node/rule.rb +6 -0
- data/lib/interscript/node/rule/funcall.rb +18 -0
- data/lib/interscript/node/rule/run.rb +15 -0
- data/lib/interscript/node/rule/sub.rb +68 -0
- data/lib/interscript/node/stage.rb +19 -0
- data/lib/interscript/node/tests.rb +15 -0
- data/lib/interscript/stdlib.rb +211 -0
- data/lib/interscript/utils/regexp_converter.rb +283 -0
- data/lib/interscript/version.rb +1 -1
- data/lib/interscript/visualize.rb +61 -0
- data/lib/interscript/visualize/group.html.erb +59 -0
- data/lib/interscript/visualize/json.rb +57 -0
- data/lib/interscript/visualize/map.html.erb +46 -0
- data/lib/interscript/visualize/nodes.rb +89 -0
- data/requirements.txt +1 -0
- metadata +78 -416
- data/README.adoc +0 -298
- data/lib/g2pwrapper.py +0 -34
- data/lib/interscript/fs.rb +0 -69
- data/lib/interscript/mapping.rb +0 -142
- data/lib/interscript/opal.rb +0 -57
- data/lib/interscript/opal/entrypoint.rb +0 -12
- data/lib/interscript/opal/map_translate.rb +0 -7
- data/lib/interscript/opal/maps.js.erb +0 -10
- data/lib/model-7 +0 -0
- data/lib/tha-pt-b-7 +0 -0
- data/maps/acadsin-zho-Hani-Latn-2002.yaml +0 -38916
- data/maps/alalc-amh-Ethi-Latn-1997.yaml +0 -513
- data/maps/alalc-amh-Ethi-Latn-2011.yaml +0 -138
- data/maps/alalc-ara-Arab-Latn-1997.yaml +0 -1287
- data/maps/alalc-asm-Deva-Latn-1997.yaml +0 -165
- data/maps/alalc-asm-Deva-Latn-2012.yaml +0 -40
- data/maps/alalc-aze-Cyrl-Latn-1997.yaml +0 -145
- data/maps/alalc-bel-Cyrl-Latn-1997.yaml +0 -129
- data/maps/alalc-ben-Beng-Latn-2017.yaml +0 -130
- data/maps/alalc-bul-Cyrl-Latn-1997.yaml +0 -98
- data/maps/alalc-ell-Grek-Latn-1997.yaml +0 -628
- data/maps/alalc-ell-Grek-Latn-2010.yaml +0 -626
- data/maps/alalc-guj-Gujr-Latn-1997.yaml +0 -266
- data/maps/alalc-guj-Gujr-Latn-2011.yaml +0 -64
- data/maps/alalc-hin-Deva-Latn-1997.yaml +0 -211
- data/maps/alalc-hin-Deva-Latn-2011.yaml +0 -47
- data/maps/alalc-kat-Geok-Latn-1997.yaml +0 -111
- data/maps/alalc-kat-Geor-Latn-1997.yaml +0 -150
- data/maps/alalc-kor-Hang-Latn-1997.yaml +0 -98
- data/maps/alalc-mal-Mlym-Latn-1997.yaml +0 -303
- data/maps/alalc-mal-Mlym-Latn-2012.yaml +0 -73
- data/maps/alalc-mar-Deva-Latn-1997.yaml +0 -189
- data/maps/alalc-mar-Deva-Latn-2011.yaml +0 -45
- data/maps/alalc-mkd-Cyrl-Latn-1997.yaml +0 -114
- data/maps/alalc-mkd-Cyrl-Latn-2013.yaml +0 -103
- data/maps/alalc-mon-Cyrl-Latn-1997.yaml +0 -220
- data/maps/alalc-pan-Guru-Latn-1997.yaml +0 -256
- data/maps/alalc-pan-Guru-Latn-2011.yaml +0 -78
- data/maps/alalc-per-Arab-Latn-1997.yaml +0 -375
- data/maps/alalc-pli-Deva-Latn-2012.yaml +0 -144
- data/maps/alalc-pra-Deva-Latn-2012.yaml +0 -47
- data/maps/alalc-rus-Cyrl-Latn-1997.yaml +0 -225
- data/maps/alalc-rus-Cyrl-Latn-2012.yaml +0 -162
- data/maps/alalc-san-Deva-Latn-2012.yaml +0 -172
- data/maps/alalc-sin-Sinh-Latn-1997.yaml +0 -292
- data/maps/alalc-sin-Sinh-Latn-2011.yaml +0 -71
- data/maps/alalc-srp-Cyrl-Latn-1997.yaml +0 -118
- data/maps/alalc-srp-Cyrl-Latn-2013.yaml +0 -135
- data/maps/alalc-tam-Taml-Latn-1997.yaml +0 -62
- data/maps/alalc-tam-Taml-Latn-2011.yaml +0 -58
- data/maps/alalc-ukr-Cyrl-Latn-1997.yaml +0 -145
- data/maps/alalc-ukr-Cyrl-Latn-2011.yaml +0 -16
- data/maps/apcbg-bul-Cyrl-Latn-1995.yaml +0 -283
- data/maps/bas-rus-Cyrl-Latn-2017-bss.yaml +0 -174
- data/maps/bas-rus-Cyrl-Latn-2017-oss.yaml +0 -169
- data/maps/bgn-jpn-Hrkt-Latn-1962.yaml +0 -292
- data/maps/bgn-kor-Hang-Latn-1943.yaml +0 -35
- data/maps/bgn-kor-Kore-Latn-1943.yaml +0 -31
- data/maps/bgna-bul-Cyrl-Latn-2006.yaml +0 -208
- data/maps/bgna-bul-Cyrl-Latn-2009.yaml +0 -208
- data/maps/bgnpcgn-amh-Ethi-Latn-1967.yaml +0 -532
- data/maps/bgnpcgn-ara-Arab-Latn-1956.yaml +0 -596
- data/maps/bgnpcgn-arm-Armn-Latn-1981.yaml +0 -108
- data/maps/bgnpcgn-aze-Cyrl-Latn-1993.yaml +0 -104
- data/maps/bgnpcgn-bak-Cyrl-Latn-2007.yaml +0 -188
- data/maps/bgnpcgn-bel-Cyrl-Latn-1979.yaml +0 -289
- data/maps/bgnpcgn-bul-Cyrl-Latn-1952.yaml +0 -119
- data/maps/bgnpcgn-bul-Cyrl-Latn-2013.yaml +0 -42
- data/maps/bgnpcgn-che-Cyrl-Latn-2008.yaml +0 -184
- data/maps/bgnpcgn-ell-Grek-Latn-1962.yaml +0 -705
- data/maps/bgnpcgn-ell-Grek-Latn-1996.yaml +0 -23
- data/maps/bgnpcgn-fas-Arab-Latn-1956.yaml +0 -96
- data/maps/bgnpcgn-jpn-Hrkt-Latn-1976.yaml +0 -257
- data/maps/bgnpcgn-kat-Geor-Latn-1981.yaml +0 -131
- data/maps/bgnpcgn-kat-Geor-Latn-2009.yaml +0 -42
- data/maps/bgnpcgn-kor-Hang-Latn-kn-1945.yaml +0 -253
- data/maps/bgnpcgn-kor-Hang-Latn-rok-2011.yaml +0 -48
- data/maps/bgnpcgn-kor-Kore-Latn-rok-2011.yaml +0 -48
- data/maps/bgnpcgn-mkd-Cyrl-Latn-1981.yaml +0 -163
- data/maps/bgnpcgn-mkd-Cyrl-Latn-2013.yaml +0 -190
- data/maps/bgnpcgn-mon-Cyrl-Latn-1964.yaml +0 -223
- data/maps/bgnpcgn-nep-Deva-Latn-2011.yaml +0 -230
- data/maps/bgnpcgn-per-Arab-Latn-1958.yaml +0 -336
- data/maps/bgnpcgn-prs-Arab-Latn-2007.yaml +0 -639
- data/maps/bgnpcgn-prs-Arab-Latn-yaghoubi.yaml +0 -459
- data/maps/bgnpcgn-rue-Cyrl-Latn-2016.yaml +0 -168
- data/maps/bgnpcgn-rus-Cyrl-Latn-1947.yaml +0 -318
- data/maps/bgnpcgn-srp-Cyrl-Latn-2005.yaml +0 -170
- data/maps/bgnpcgn-tat-Cyrl-Latn-2007.yaml +0 -220
- data/maps/bgnpcgn-tgk-Cyrl-Latn-1994.yaml +0 -240
- data/maps/bgnpcgn-ukr-Cyrl-Latn-1965.yaml +0 -166
- data/maps/bgnpcgn-ukr-Cyrl-Latn-2019.yaml +0 -119
- data/maps/bgnpcgn-uzb-Cyrl-Latn-1979.yaml +0 -127
- data/maps/bgnpcgn-uzb-Cyrl-Latn-2000.yaml +0 -82
- data/maps/bgnpcgn-zho-Hans-Latn-1979.yaml +0 -7456
- data/maps/bis-asm-Beng-Latn-13194-1991.yaml +0 -159
- data/maps/bis-ben-Beng-Latn-13194-1991.yaml +0 -156
- data/maps/bis-dev-Deva-Latn-13194-1991.yaml +0 -184
- data/maps/bis-guj-Gujr-Latn-13194-1991.yaml +0 -181
- data/maps/bis-knd-Knda-Latn-13194-1991.yaml +0 -173
- data/maps/bis-mlm-Mlym-Latn-13194-1991.yaml +0 -176
- data/maps/bis-ori-Orya-Latn-13194-1991.yaml +0 -160
- data/maps/bis-pnj-Guru-Latn-13194-1991.yaml +0 -175
- data/maps/bis-tel-Telu-Latn-13194-1991.yaml +0 -170
- data/maps/bis-tml-Taml-Latn-13194-1991.yaml +0 -155
- data/maps/by-bel-Cyrl-Latn-1998.yaml +0 -172
- data/maps/by-bel-Cyrl-Latn-2007.yaml +0 -115
- data/maps/din-grc-Grek-Latn-31634-2011-t1.yaml +0 -899
- data/maps/din-hin-Deva-Latn-33904-2018.yaml +0 -100
- data/maps/din-kat-Geor-Latn-32707-2010.yaml +0 -145
- data/maps/din-mar-Deva-Latn-33904-2018.yaml +0 -84
- data/maps/din-nep-Deva-Latn-33904-2018.yaml +0 -119
- data/maps/din-pli-Deva-Latn-33904-2018.yaml +0 -75
- data/maps/din-pra-Deva-Latn-33904-2018.yaml +0 -63
- data/maps/din-san-Deva-Latn-33904-2018.yaml +0 -338
- data/maps/din-tam-Taml-Latn-33903-2016.yaml +0 -213
- data/maps/dos-nep-Deva-Latn-1997.yaml +0 -47
- data/maps/elot-ell-Grek-Latn-743-1982-tl.yaml +0 -684
- data/maps/elot-ell-Grek-Latn-743-1982-ts.yaml +0 -680
- data/maps/elot-ell-Grek-Latn-743-2001-tl.yaml +0 -19
- data/maps/elot-ell-Grek-Latn-743-2001-ts.yaml +0 -31
- data/maps/ggg-kat-Geor-Latn-2002.yaml +0 -92
- data/maps/gki-bel-Cyrl-Latn-1992.yaml +0 -33
- data/maps/gki-bel-Cyrl-Latn-2000.yaml +0 -201
- data/maps/gost-rus-Cyrl-Latn-16876-71-1983.yaml +0 -190
- data/maps/gost-rus-Cyrl-Latn-7.79-2000-2002.yaml +0 -157
- data/maps/hk-yue-Hani-Latn-1888.yaml +0 -38497
- data/maps/icao-bel-Cyrl-Latn-9303.yaml +0 -136
- data/maps/icao-bul-Cyrl-Latn-9303.yaml +0 -118
- data/maps/icao-fas-Arab-Latn-9303.yaml +0 -103
- data/maps/icao-heb-Hebr-Latn-9303.yaml +0 -151
- data/maps/icao-mkd-Cyrl-Latn-9303.yaml +0 -117
- data/maps/icao-rus-Cyrl-Latn-9303.yaml +0 -117
- data/maps/icao-srp-Cyrl-Latn-9303.yaml +0 -117
- data/maps/icao-ukr-Cyrl-Latn-9303.yaml +0 -119
- data/maps/iso-ara-Arab-Latn-233-1984.yaml +0 -323
- data/maps/iso-asm-Beng-Latn-15919-2001.yaml +0 -75
- data/maps/iso-ben-Beng-Latn-15919-2001.yaml +0 -175
- data/maps/iso-ell-Grek-Latn-843-1997-t1.yaml +0 -613
- data/maps/iso-ell-Grek-Latn-843-1997-t2.yaml +0 -44
- data/maps/iso-guj-Gujr-Latn-15919-2001.yaml +0 -220
- data/maps/iso-hin-Deva-Latn-15919-2001.yaml +0 -87
- data/maps/iso-inc-Deva-Latn-15919-2001.yaml +0 -61
- data/maps/iso-jpn-Hrkt-Latn-3602-1989.yaml +0 -66
- data/maps/iso-kan-Knda-Latn-15919-2001.yaml +0 -220
- data/maps/iso-kat-Geor-Latn-9984-1996.yaml +0 -145
- data/maps/iso-kor-Hang-Latn-1996-method1.yaml +0 -240
- data/maps/iso-kor-Hang-Latn-1996-method2.yaml +0 -226
- data/maps/iso-mal-Mlym-Latn-15919-2001.yaml +0 -281
- data/maps/iso-mar-Deva-Latn-15919-2001.yaml +0 -75
- data/maps/iso-nep-Deva-Latn-15919-2001.yaml +0 -87
- data/maps/iso-ori-Orya-Latn-15919-2001.yaml +0 -193
- data/maps/iso-pan-Guru-Latn-15919-2001.yaml +0 -222
- data/maps/iso-pli-Beng-Latn-15919-2001.yaml +0 -73
- data/maps/iso-pli-Deva-Latn-15919-2001.yaml +0 -74
- data/maps/iso-pli-Sinh-Latn-15919-2001.yaml +0 -219
- data/maps/iso-pli-Thai-Latn-15919-2001.yaml +0 -55
- data/maps/iso-pra-Deva-Latn-15919-2001.yaml +0 -59
- data/maps/iso-prs-Arab-Latn-233-3-1999.yaml +0 -366
- data/maps/iso-rus-Cyrl-Latn-9-1995.yaml +0 -271
- data/maps/iso-san-Deva-Latn-15919-2001.yaml +0 -220
- data/maps/iso-tam-Taml-Latn-15919-2001.yaml +0 -159
- data/maps/iso-tel-Telu-Latn-15919-2001.yaml +0 -220
- data/maps/iso-tha-Thai-Latn-11940-1998.yaml +0 -109
- data/maps/kp-kor-Hang-Latn-2002.yaml +0 -909
- data/maps/lshk-yue-Hani-Latn-jyutping-1993.yaml +0 -44820
- data/maps/mext-jpn-Hrkt-Latn-1954.yaml +0 -411
- data/maps/mns-mon-Cyrl-Latn-5217-2012.yaml +0 -163
- data/maps/mns-mon-Latn-Cyrl-5217-2012.yaml +0 -200
- data/maps/moct-kor-Hang-Latn-2000.yaml +0 -807
- data/maps/mofa-jpn-Hrkt-Latn-1989.yaml +0 -541
- data/maps/mvd-bel-Cyrl-Latn-2008.yaml +0 -225
- data/maps/mvd-bel-Cyrl-Latn-2010.yaml +0 -63
- data/maps/mvd-rus-Cyrl-Latn-2008.yaml +0 -109
- data/maps/mvd-rus-Cyrl-Latn-2010.yaml +0 -37
- data/maps/odni-ara-Arab-Latn-2015.yaml +0 -425
- data/maps/odni-aze-Cyrl-Latn-2015.yaml +0 -144
- data/maps/odni-bel-Cyrl-Latn-2015.yaml +0 -148
- data/maps/odni-bul-Cyrl-Latn-2015.yaml +0 -96
- data/maps/odni-che-Cyrl-Latn-2015.yaml +0 -169
- data/maps/odni-fas-Arab-Latn-2015.yaml +0 -406
- data/maps/odni-hin-Deva-Latn-2015.yaml +0 -258
- data/maps/odni-kat-Geor-Latn-2015.yaml +0 -87
- data/maps/odni-kaz-Cyrl-Latn-2015.yaml +0 -148
- data/maps/odni-kir-Cyrl-Latn-2015.yaml +0 -136
- data/maps/odni-kor-Hang-Latn-2015.yaml +0 -375
- data/maps/odni-mkd-Cyrl-Latn-2015.yaml +0 -122
- data/maps/odni-per-Arab-Latn-2015.yaml +0 -228
- data/maps/odni-rus-Cyrl-Latn-2015.yaml +0 -77
- data/maps/odni-srp-Cyrl-Latn-2015.yaml +0 -129
- data/maps/odni-tat-Cyrl-Latn-2015.yaml +0 -142
- data/maps/odni-tgk-Cyrl-Latn-2015.yaml +0 -148
- data/maps/odni-uig-Cyrl-Latn-2015.yaml +0 -138
- data/maps/odni-ukr-Cyrl-Latn-2015.yaml +0 -157
- data/maps/odni-urd-Arab-Latn-2015.yaml +0 -221
- data/maps/odni-uzb-Cyrl-Latn-2015.yaml +0 -166
- data/maps/royin-tha-Thai-Latn-1939-generic.yaml +0 -90
- data/maps/royin-tha-Thai-Latn-1968.yaml +0 -183
- data/maps/royin-tha-Thai-Latn-1999-chained.yaml +0 -180
- data/maps/royin-tha-Thai-Latn-1999.yaml +0 -80
- data/maps/sac-zho-Hans-Latn-1979.yaml +0 -24763
- data/maps/sasm-mon-Mong-Latn-general-1978.yaml +0 -389
- data/maps/sasm-mon-Mong-Latn-phonetic-1978.yaml +0 -354
- data/maps/ses-ara-Arab-Latn-1930.yaml +0 -283
- data/maps/stategeocadastre-ukr-Cyrl-Latn-1993.yaml +0 -222
- data/maps/ua-ukr-Cyrl-Latn-1996.yaml +0 -197
- data/maps/ua-ukr-Cyrl-Latn-2007.yaml +0 -75
- data/maps/ua-ukr-Cyrl-Latn-2010.yaml +0 -192
- data/maps/un-amh-Ethi-Latn-2016.yaml +0 -602
- data/maps/un-ara-Arab-Latn-1971.yaml +0 -139
- data/maps/un-ara-Arab-Latn-1972.yaml +0 -159
- data/maps/un-ara-Arab-Latn-2017.yaml +0 -420
- data/maps/un-bel-Cyrl-Latn-2007.yaml +0 -114
- data/maps/un-ben-Beng-Latn-2016.yaml +0 -534
- data/maps/un-ell-Grek-Latn-1987-phonetic.yaml +0 -780
- data/maps/un-ell-Grek-Latn-1987-tl.yaml +0 -31
- data/maps/un-ell-Grek-Latn-1987-ts.yaml +0 -19
- data/maps/un-hin-Deva-Latn-2016.yaml +0 -222
- data/maps/un-mar-Deva-Latn-2016.yaml +0 -91
- data/maps/un-mon-Mong-Latn-general-2013.yaml +0 -264
- data/maps/un-mon-Mong-Latn-phonetic-2013.yaml +0 -264
- data/maps/un-nep-Deva-Latn-1972.yaml +0 -350
- data/maps/un-nep-Deva-Latn-2013.yaml +0 -74
- data/maps/un-rus-Cyrl-Latn-1987.yaml +0 -166
- data/maps/un-ukr-Cyrl-Latn-1998.yaml +0 -53
- data/maps/un-ukr-Cyrl-Latn-2012.yaml +0 -162
- data/maps/var-hin-Deva-Latn-hunterian-1872.yaml +0 -221
- data/maps/var-jpn-Hrkt-Latn-hepburn-1886.yaml +0 -406
- data/maps/var-jpn-Hrkt-Latn-hepburn-1954.yaml +0 -386
- data/maps/var-kor-Hang-Hang-jamo.yaml +0 -11193
- data/maps/var-kor-Hang-Latn-mr-1939.yaml +0 -1054
- data/maps/var-kor-Kore-Hang-2013.yaml +0 -59754
- data/maps/var-kor-Kore-Latn-mr-1939.yaml +0 -36
- data/maps/var-mar-Deva-Latn-hunterian-1872.yaml +0 -43
- data/maps/var-mon-Mong-Latn-1930.yaml +0 -102
- data/maps/var-mon-Mong-Latn-lessing.yaml +0 -272
- data/maps/var-mon-Mong-Latn-vpmc.yaml +0 -274
- data/maps/var-pra-Deva-Latn-iast-1912.yaml +0 -30
- data/maps/var-san-Deva-Latn-iast-1912.yaml +0 -149
- data/maps/var-tha-Thai-Thai-phonemic.yaml +0 -59
- data/maps/var-tha-Thai-Zsym-ipa.yaml +0 -301
- data/maps/var-zho-Hani-Latn-wd-1979.yaml +0 -38912
- data/spec/interscript/filenames_spec.rb +0 -384
- data/spec/interscript/mapping_spec.rb +0 -42
- data/spec/interscript_spec.rb +0 -29
- data/spec/spec_helper.rb +0 -3
@@ -0,0 +1,283 @@
|
|
1
|
+
require 'regexp_parser'
|
2
|
+
|
3
|
+
|
4
|
+
def process(node)
|
5
|
+
children = if node.respond_to?(:expressions) && node.expressions
|
6
|
+
children = node.expressions.map.each { |expr| process(expr) }
|
7
|
+
end
|
8
|
+
# puts node.inspect
|
9
|
+
out = case node
|
10
|
+
when Regexp::Expression::Root
|
11
|
+
children
|
12
|
+
when Regexp::Expression::Assertion::Lookbehind
|
13
|
+
[:lookbehind_start, children, :lookbehind_stop]
|
14
|
+
when Regexp::Expression::Assertion::NegativeLookbehind
|
15
|
+
[:negative_lookbehind_start, children, :negative_lookbehind_stop]
|
16
|
+
when Regexp::Expression::Assertion::Lookahead
|
17
|
+
[:lookahead_start, children, :lookahead_stop]
|
18
|
+
when Regexp::Expression::Assertion::NegativeLookahead
|
19
|
+
[:negative_lookahead_start, children, :negative_lookahead_stop]
|
20
|
+
when Regexp::Expression::Group::Capture
|
21
|
+
[:capture_start, children, :capture_stop]
|
22
|
+
when Regexp::Expression::CharacterSet
|
23
|
+
# puts children.inspect
|
24
|
+
if children.flatten.include? (:range_start) #or children.size > 1
|
25
|
+
[:characterset_start, :array_start, children, :array_stop, :characterset_stop]
|
26
|
+
else
|
27
|
+
[:characterset_start, children, :characterset_stop]
|
28
|
+
end
|
29
|
+
when Regexp::Expression::Alternation
|
30
|
+
[:alternation_start, children, :alternation_stop]
|
31
|
+
when Regexp::Expression::Alternative
|
32
|
+
[:alternative_start, children, :alternative_stop]
|
33
|
+
when Regexp::Expression::CharacterSet::Range
|
34
|
+
lit1 = node.expressions[0].text
|
35
|
+
lit2 = node.expressions[1].text
|
36
|
+
[:range_start, lit1, :range_mid, lit2, :range_stop]
|
37
|
+
when Regexp::Expression::Anchor::WordBoundary
|
38
|
+
:boundary
|
39
|
+
when Regexp::Expression::Anchor::NonWordBoundary
|
40
|
+
:non_word_boundary
|
41
|
+
when Regexp::Expression::EscapeSequence::Backspace
|
42
|
+
:boundary # most probably boundary
|
43
|
+
when Regexp::Expression::CharacterType::Space
|
44
|
+
:space
|
45
|
+
when Regexp::Expression::Anchor::BeginningOfLine
|
46
|
+
:line_start
|
47
|
+
when Regexp::Expression::Anchor::EndOfLine
|
48
|
+
:line_end
|
49
|
+
when Regexp::Expression::CharacterType::Any
|
50
|
+
:any_character
|
51
|
+
when Regexp::Expression::Literal
|
52
|
+
node.text
|
53
|
+
when Regexp::Expression::EscapeSequence::Literal
|
54
|
+
node.text
|
55
|
+
when Regexp::Expression::EscapeSequence::Codepoint
|
56
|
+
node.text
|
57
|
+
when Regexp::Expression::PosixClass
|
58
|
+
'[' + node.text + ']'
|
59
|
+
when Regexp::Expression::UnicodeProperty::Script
|
60
|
+
node.text
|
61
|
+
when Regexp::Expression::Backreference::Number # why is there a space before after node.number?
|
62
|
+
[:backref_num_start, node.number, :backref_num_stop]
|
63
|
+
else
|
64
|
+
out = [:missing, node.class]
|
65
|
+
|
66
|
+
out << children if node.respond_to? :expressions
|
67
|
+
if node.respond_to? :quantifier and node.quantifier
|
68
|
+
# TODO add quantifier support
|
69
|
+
pp node
|
70
|
+
# out << process(node.quantifier)
|
71
|
+
end
|
72
|
+
out
|
73
|
+
end
|
74
|
+
if node.respond_to?(:quantifier) && node.quantifier&.token.to_s == "interval" && node.quantifier.max == node.quantifier.min
|
75
|
+
out = [out] * node.quantifier.max
|
76
|
+
elsif node.respond_to?(:quantifier) && node.quantifier
|
77
|
+
qname = node.quantifier.token.to_s
|
78
|
+
out = ["#{qname}_start".to_sym, [out], "#{qname}_stop".to_sym]
|
79
|
+
end
|
80
|
+
out
|
81
|
+
end
|
82
|
+
|
83
|
+
def process_root(node)
|
84
|
+
node2 = node.dup
|
85
|
+
root = {}
|
86
|
+
if before = node.select { |x| x[0] == :lookbehind_start }
|
87
|
+
# root[:before] = before[1]
|
88
|
+
# node2.delete(before)
|
89
|
+
if before.size == 1
|
90
|
+
root[:before] = before[0][1]
|
91
|
+
node2.delete(before[0])
|
92
|
+
elsif before.size >1
|
93
|
+
# pp not_before
|
94
|
+
|
95
|
+
a = [:alternation_start]
|
96
|
+
a << before.map{|x| [:alternative_start, x[1], :alternative_stop] }
|
97
|
+
a << [:alternation_stop]
|
98
|
+
root[:before] = a
|
99
|
+
# pp root[:not_before]
|
100
|
+
before.each{|n| node2.delete(n)}
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
if not_before = node.select { |x| x[0] == :negative_lookbehind_start }
|
105
|
+
# root[:not_before] = not_before[1]
|
106
|
+
# node2.delete(not_before)
|
107
|
+
|
108
|
+
if not_before.size == 1
|
109
|
+
root[:not_before] = not_before[0][1]
|
110
|
+
node2.delete(not_before[0])
|
111
|
+
elsif not_before.size >1
|
112
|
+
# pp not_before
|
113
|
+
|
114
|
+
a = [:alternation_start]
|
115
|
+
a << not_before.map{|x| [:alternative_start, x[1], :alternative_stop] }
|
116
|
+
a << [:alternation_stop]
|
117
|
+
root[:not_before] = a
|
118
|
+
# pp root[:not_before]
|
119
|
+
not_before.each{|n| node2.delete(n)}
|
120
|
+
end
|
121
|
+
end
|
122
|
+
if after = node.select { |x| x[0] == :lookahead_start }
|
123
|
+
# root[:after] = after[1]
|
124
|
+
# node2.delete(after)
|
125
|
+
|
126
|
+
if after.size == 1
|
127
|
+
root[:after] = after[0][1]
|
128
|
+
node2.delete(after[0])
|
129
|
+
elsif after.size >1
|
130
|
+
# pp not_before
|
131
|
+
|
132
|
+
a = [:alternation_start]
|
133
|
+
a << after.map{|x| [:alternative_start, x[1], :alternative_stop] }
|
134
|
+
a << [:alternation_stop]
|
135
|
+
root[:after] = a
|
136
|
+
# pp root[:not_before]
|
137
|
+
after.each{|n| node2.delete(n)}
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
if not_after = node.select { |x| x[0] == :negative_lookahead_start }
|
142
|
+
# root[:not_after] = not_after[1]
|
143
|
+
# node2.delete(not_after)
|
144
|
+
if not_after.size == 1
|
145
|
+
root[:not_after] = not_after[0][1]
|
146
|
+
node2.delete(not_after[0])
|
147
|
+
elsif not_after.size >1
|
148
|
+
# pp not_after
|
149
|
+
|
150
|
+
a = [:alternation_start]
|
151
|
+
a << not_after.map{|x| [:alternative_start, x[1], :alternative_stop] }
|
152
|
+
a << [:alternation_stop]
|
153
|
+
root[:not_after] = a
|
154
|
+
# pp root[:not_after]
|
155
|
+
not_after.each{|n| node2.delete(n)}
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
root[:from] = node2
|
160
|
+
root
|
161
|
+
end
|
162
|
+
|
163
|
+
def stringify(node)
|
164
|
+
tokens = node.flatten
|
165
|
+
subs = {
|
166
|
+
characterset_start: 'any(',
|
167
|
+
characterset_stop: ')',
|
168
|
+
array_start: '[',
|
169
|
+
array_stop: ']',
|
170
|
+
capture_start: 'capture(',
|
171
|
+
capture_stop: ')',
|
172
|
+
zero_or_one_start: 'maybe(',
|
173
|
+
zero_or_one_stop: ')',
|
174
|
+
zero_or_more_start: 'maybe_some(',
|
175
|
+
zero_or_more_stop: ')',
|
176
|
+
one_or_more_start: 'some(',
|
177
|
+
one_or_more_stop: ')',
|
178
|
+
alternation_start: 'any([',
|
179
|
+
alternation_stop: '])',
|
180
|
+
alternative_start: '',
|
181
|
+
alternative_stop: '',
|
182
|
+
boundary: 'boundary',
|
183
|
+
non_word_boundary: 'non_word_boundary',
|
184
|
+
space: 'space',
|
185
|
+
line_start: 'line_start',
|
186
|
+
line_end: 'line_end',
|
187
|
+
any_character: 'any_character',
|
188
|
+
range_start: 'any(',
|
189
|
+
range_mid: '..',
|
190
|
+
range_stop: ')',
|
191
|
+
backref_num_start: 'ref(',
|
192
|
+
backref_num_stop: ')'
|
193
|
+
}
|
194
|
+
|
195
|
+
str = []
|
196
|
+
tokens.each_with_index do |token, idx|
|
197
|
+
prev = tokens[idx - 1] if idx > 0
|
198
|
+
left_side = %i[characterset_stop capture_stop
|
199
|
+
zero_or_one_stop zero_or_more_stop one_or_more_stop
|
200
|
+
boundary non_word_boundary
|
201
|
+
line_start any_character range_stop space
|
202
|
+
backref_num_stop]
|
203
|
+
right_side = %i[characterset_start capture_start
|
204
|
+
zero_or_one_start zero_or_more_start one_or_more_start
|
205
|
+
boundary non_word_boundary
|
206
|
+
line_end any_character range_start space
|
207
|
+
backref_num_start]
|
208
|
+
#if prev==:range_stop and token==:range_start
|
209
|
+
# str << ' :adding_ranges '
|
210
|
+
#end
|
211
|
+
if (prev.instance_of?(String) && right_side.include?(token)) or
|
212
|
+
(left_side.include?(prev) && token.instance_of?(String)) or
|
213
|
+
(left_side.include?(prev) && right_side.include?(token))
|
214
|
+
str << ' + '
|
215
|
+
end
|
216
|
+
str << ', ' if prev == :alternative_stop and token == :alternative_start
|
217
|
+
# str << '[' if prev == :characterset_start and token == :range_start
|
218
|
+
# str << ']' if prev == :range_stop and token ==:characterset_stop
|
219
|
+
if subs.include? token
|
220
|
+
str << subs[token]
|
221
|
+
elsif token.instance_of?(String)
|
222
|
+
if prev.instance_of?(String)
|
223
|
+
str[-1] = "#{str[-1][0..-2]}#{token}\""
|
224
|
+
else
|
225
|
+
str << "\"#{token}\""
|
226
|
+
end
|
227
|
+
else
|
228
|
+
str << " #{token.inspect} "
|
229
|
+
end
|
230
|
+
# puts [idx, token].inspect
|
231
|
+
# puts str.inspect
|
232
|
+
end
|
233
|
+
str.join.gsub('\\\\u', '\\u')
|
234
|
+
end
|
235
|
+
|
236
|
+
def stringify_root(root, indent: 0)
|
237
|
+
warning = ''
|
238
|
+
root[:from] = [""] if root[:from] == []
|
239
|
+
str = " "*indent+"sub #{stringify(root[:from])}, #{root[:to]}"
|
240
|
+
[:before, :not_before, :after, :not_after].each do |look|
|
241
|
+
# puts "#{look.inspect} = #{root[look]}"
|
242
|
+
next unless root[look]
|
243
|
+
str_look = stringify(root[look])
|
244
|
+
str_look = "\"\"" if root[look] == [] || root[look] == nil
|
245
|
+
#if str_look.empty? #apparently it is empty sometimes. iso-mal-Mlym-Latn for example
|
246
|
+
# warning << "warning: #{look} is empty string;"
|
247
|
+
#else
|
248
|
+
str << ", #{look}: #{str_look}"
|
249
|
+
#end
|
250
|
+
end
|
251
|
+
str = " "*indent+"# #{str} # warning: :" if str =~ /[^\[]:[^ \]]/
|
252
|
+
str = " "*indent+"# #{str} # #{warning}" if !warning.empty?
|
253
|
+
|
254
|
+
str = " "*indent+"# #{str} # warning: :missing unimplemented" if str.include?(':missing')
|
255
|
+
str = " "*indent+"# #{str} # warning: :interval unimplemented" if str.include?(':interval')
|
256
|
+
str = " "*indent+"# #{str} # warning: :adding_ranges unimplemented" if str.include?(':adding_ranges')
|
257
|
+
if str.include?('zero_or_one')
|
258
|
+
str = " "*indent+"# #{str} # warning: zero_or_one"
|
259
|
+
puts "str.includes 'zero_or_one'"
|
260
|
+
pp root
|
261
|
+
end
|
262
|
+
# str = " "*indent+"# #{str} # warning: one_or_more" if str.include?('one_or_more')
|
263
|
+
str = " "*indent+"# #{str} # warning: :lookahead_start" if str.include?(':lookahead_start')
|
264
|
+
# str += " # original: #{root[:from]}"
|
265
|
+
str
|
266
|
+
end
|
267
|
+
|
268
|
+
if __FILE__ == $0
|
269
|
+
rs = File.open(__dir__+"/../../docs/utils/regexp_examples.txt").read.gsub(/([^\\^])\\u/, '\\1\\\\u').gsub(/\\\\b/, '\b')
|
270
|
+
rs = rs.split("\n")
|
271
|
+
rs.each do |r|
|
272
|
+
puts r
|
273
|
+
tree = Regexp::Parser.parse(r, 'ruby/2.1')
|
274
|
+
conv = process(tree)
|
275
|
+
pp conv
|
276
|
+
root = process_root(conv)
|
277
|
+
pp root
|
278
|
+
root[:to] = ['X']
|
279
|
+
str = stringify_root(root)
|
280
|
+
puts str
|
281
|
+
puts "\n\n"
|
282
|
+
end
|
283
|
+
end
|
data/lib/interscript/version.rb
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'interscript/visualize/nodes'
|
3
|
+
require 'interscript/visualize/json'
|
4
|
+
|
5
|
+
def h(str)
|
6
|
+
str.to_s.gsub("&", "&").gsub("<", "<").gsub(">", ">").gsub('"', """)
|
7
|
+
end
|
8
|
+
|
9
|
+
class Interscript::Visualize
|
10
|
+
def self.def_template(template)
|
11
|
+
@template = ERB.new(File.read(__dir__+"/visualize/#{template}.html.erb"))
|
12
|
+
end
|
13
|
+
def get_binding; binding; end
|
14
|
+
|
15
|
+
def self.call(*args)
|
16
|
+
return Map.(*args) if self == Interscript::Visualize
|
17
|
+
|
18
|
+
tplctx = self.new(*args)
|
19
|
+
@template.result(tplctx.get_binding)
|
20
|
+
end
|
21
|
+
|
22
|
+
class Map < self
|
23
|
+
def_template :map
|
24
|
+
|
25
|
+
def initialize(map_name)
|
26
|
+
@map = Interscript.parse(map_name)
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_reader :map
|
30
|
+
|
31
|
+
def render_stage(map_name, stage)
|
32
|
+
Stage.(map_name, stage)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Group < self
|
37
|
+
def_template :group
|
38
|
+
|
39
|
+
def initialize(map, group, style=nil)
|
40
|
+
@map = map
|
41
|
+
@group = group
|
42
|
+
@style = style
|
43
|
+
end
|
44
|
+
|
45
|
+
attr_reader :map, :group
|
46
|
+
|
47
|
+
def render_group(map, group, style=nil)
|
48
|
+
Group.(map, group, style)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Stage < Group
|
53
|
+
def_template :group
|
54
|
+
|
55
|
+
def initialize(map_name, stage_name, style=nil)
|
56
|
+
@map = Interscript.parse(map_name)
|
57
|
+
@group = map.stages[stage_name]
|
58
|
+
@style = style
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
<table style='<%= @style %>'>
|
2
|
+
<% group.children.each do |rule| %>
|
3
|
+
<tr>
|
4
|
+
<% case rule
|
5
|
+
when Interscript::Node::Rule::Sub %>
|
6
|
+
<td>
|
7
|
+
Replace
|
8
|
+
<td>
|
9
|
+
<%= rule.from.to_html(map) %>
|
10
|
+
<td>
|
11
|
+
<%= Symbol === rule.to ? rule.to : rule.to.to_html(map) %>
|
12
|
+
<td>
|
13
|
+
<%=
|
14
|
+
out = []
|
15
|
+
out << "before: #{rule.before.to_html(map)}" if rule.before
|
16
|
+
out << "after: #{rule.after.to_html(map)}" if rule.after
|
17
|
+
out << "<nobr>not before:</nobr> #{rule.not_before.to_html(map)}" if rule.not_before
|
18
|
+
out << "<nobr>not after:</nobr> #{rule.not_after.to_html(map)}" if rule.not_after
|
19
|
+
out.join(", ")
|
20
|
+
%>
|
21
|
+
<% when Interscript::Node::Group::Parallel %>
|
22
|
+
<td>
|
23
|
+
Parallel
|
24
|
+
<td colspan='3'>
|
25
|
+
<%= render_group map, rule %>
|
26
|
+
</td>
|
27
|
+
<% when Interscript::Node::Rule::Funcall %>
|
28
|
+
<td>
|
29
|
+
<%= h rule.name.to_s.gsub("_", " ").gsub(/^(.)/, &:upcase) %>
|
30
|
+
<td>
|
31
|
+
<%=
|
32
|
+
rule.kwargs.map do |k,v|
|
33
|
+
"#{k.to_s.gsub("_", " ")}: #{v}"
|
34
|
+
end.join(", ")
|
35
|
+
%>
|
36
|
+
<% when Interscript::Node::Rule::Run %>
|
37
|
+
<td>
|
38
|
+
<nobr>Run</nobr>
|
39
|
+
<td>
|
40
|
+
<a href='#' onclick='this.parentNode.lastElementChild.style.display=this.parentNode.lastElementChild.style.display=="none"?"table":"none";return!1'>
|
41
|
+
<%= rule.stage.to_html(map) %>
|
42
|
+
</a>
|
43
|
+
|
44
|
+
<%=
|
45
|
+
if rule.stage.map
|
46
|
+
doc = map.dep_aliases[rule.stage.map].document
|
47
|
+
stage = doc.imported_stages[rule.stage.name]
|
48
|
+
else
|
49
|
+
doc = map
|
50
|
+
stage = map.imported_stages[rule.stage.name]
|
51
|
+
end
|
52
|
+
|
53
|
+
render_group doc, stage, "display: none"
|
54
|
+
%>
|
55
|
+
<% else %>
|
56
|
+
<td colspan='4'><pre><%= h rule.inspect %></pre>
|
57
|
+
<% end %>
|
58
|
+
<% end %>
|
59
|
+
</table>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class Interscript::Node::Group
|
2
|
+
def to_visualization_array(map=self)
|
3
|
+
out = []
|
4
|
+
|
5
|
+
self.children.each do |rule|
|
6
|
+
case rule
|
7
|
+
when Interscript::Node::Rule::Sub
|
8
|
+
more = []
|
9
|
+
more << "before: #{rule.before.to_html(map)}" if rule.before
|
10
|
+
more << "after: #{rule.after.to_html(map)}" if rule.after
|
11
|
+
more << "<nobr>not before:</nobr> #{rule.not_before.to_html(map)}" if rule.not_before
|
12
|
+
more << "<nobr>not after:</nobr> #{rule.not_after.to_html(map)}" if rule.not_after
|
13
|
+
more = more.join(", ")
|
14
|
+
|
15
|
+
out << {
|
16
|
+
type: "Replace",
|
17
|
+
from: rule.from.to_html(map),
|
18
|
+
to: Symbol === rule.to ? rule.to : rule.to.to_html(map),
|
19
|
+
more: more
|
20
|
+
}
|
21
|
+
when Interscript::Node::Group::Parallel
|
22
|
+
out << {
|
23
|
+
type: "Parallel",
|
24
|
+
children: rule.to_visualization_array(map)
|
25
|
+
}
|
26
|
+
when Interscript::Node::Rule::Funcall
|
27
|
+
out << {
|
28
|
+
type: rule.name.to_s.gsub("_", " ").gsub(/^(.)/, &:upcase),
|
29
|
+
more: rule.kwargs.map do |k,v|
|
30
|
+
"#{k.to_s.gsub("_", " ")}: #{v}"
|
31
|
+
end.join(", ")
|
32
|
+
}
|
33
|
+
when Interscript::Node::Rule::Run
|
34
|
+
if rule.stage.map
|
35
|
+
doc = map.dep_aliases[rule.stage.map].document
|
36
|
+
stage = rule.stage.name
|
37
|
+
else
|
38
|
+
doc = map
|
39
|
+
stage = rule.stage.name
|
40
|
+
end
|
41
|
+
|
42
|
+
out << {
|
43
|
+
type: "Run",
|
44
|
+
doc: doc.name,
|
45
|
+
stage: stage
|
46
|
+
}
|
47
|
+
else
|
48
|
+
out << {
|
49
|
+
type: "Unknown",
|
50
|
+
more: "<pre>#{h rule.inspect}</pre>"
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
out
|
56
|
+
end
|
57
|
+
end
|