Commit 48a90015 authored by Pouya Kary's avatar Pouya Kary

First flag implementation: multiline

parent bffc54f6
......@@ -32,6 +32,7 @@
const openExternal = require( 'electron' ).shell.openExternal
const regulex = require('regulex')
const concerto = require('concerto-compiler')
//
// ─── NODE LOADS ─────────────────────────────────────────────────────────────────
//
......@@ -74,6 +75,14 @@
return x
})( )
//
// ─── COMPILER ───────────────────────────────────────────────────────────────────
//
const defaultActivatedFlagsValue = {
m: false, g: false, i: false, u: false, y: false
}
//
// ─── DEVELOPER TOOLS ────────────────────────────────────────────────────────────
//
......@@ -87,4 +96,16 @@
const detectAllBoundaryRegExp = /^(?:(?:\\b|\\B|\^|\$))+$/g
//
// ─── FLAGS CHECKER ──────────────────────────────────────────────────────────────
//
const detectOrchestraWithEOL =
// ../../orchestras/detect-orchestra-with-eol.orchestra
/(?:^|[^\\])(\\n|\\r|\\f|\\v|\\u0085|\\u2028|\\u2029|(?:\[(?:[^A-Z\[\]\^])*(?:\\s(?:[^A-Z\[\]])*\\S|\\w(?:[^A-Z\[\]])*\\W|\\W(?:[^A-Z\[\]])*\\w|\\S(?:[^A-Z\[\]])*\\s)(?:[^A-Z\[\]])*\]|\[\^(?:[^A-Z\[\]\^])*\]))/g
const checkIfEmptyExcludeSet =
// ../../orchestras/check-if-empty-exclude-set.orchestra
/^\[\^(?:[^A-Z\[\]\^])*\]$/
// ────────────────────────────────────────────────────────────────────────────────
......@@ -12,7 +12,8 @@
// ─── FILE SYSTEM ────────────────────────────────────────────────────────────────
//
var currentFile = Object.assign({ }, defaultFileObject )
var currentFile =
Object.assign({ }, defaultFileObject )
//
// ─── WINDOW STATUS ──────────────────────────────────────────────────────────────
......@@ -48,6 +49,13 @@
var workspace
var ComposeBlock
//
// ─── COMPILER ───────────────────────────────────────────────────────────────────
//
var activatedFlags =
Object.assign({ }, defaultActivatedFlagsValue )
//
// ─── PLAYGROUND ─────────────────────────────────────────────────────────────────
//
......
//
// Copyright © 2017-present Kary Foundation, Inc. All rights reserved.
// Author: Pouya Kary <k@karyfoundation.org>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
//
// ─── ACTIVATE FLAGS FOR BUILD ───────────────────────────────────────────────────
//
function updateFlagsForLatestBuild ( ) {
const latestCompiledRegex = fetchLatestCompiledRegExp( )
// resetting flags
activatedFlags = Object.assign({ }, defaultActivatedFlagsValue )
// checking for multiline flag (m)
if ( checkIfRegExpIsMultiLine( latestCompiledRegex ) )
activatedFlags.m = true
}
//
// ─── CHECK IF REGEXP IS MULTILINE ───────────────────────────────────────────────
//
function checkIfRegExpIsMultiLine ( regX ) {
while ( true ) {
const match = detectOrchestraWithEOL.exec( regX )
if ( match === null )
return false
const capture = match[ 1 ]
if ( checkIfEmptyExcludeSet.test( capture ) ) {
const regexpBasedOnSet = new RegExp( capture )
const testCase = "\n\r\v\f\u0085\u2028\u2029"
if ( regexpBasedOnSet.test( testCase ) ) {
return true
}
} else {
return true
}
}
}
// ────────────────────────────────────────────────────────────────────────────────
......@@ -13,7 +13,6 @@
//
function quartetOnUIChange ( event ) {
switch ( event.type ) {
case Blockly.Events.MOVE:
return
......@@ -27,9 +26,12 @@
if ( event.type === Blockly.Events.UI && event.element === 'selected' )
quartetActiveBlockId = event.newValue || event.blockId
let compiledRegex = QuartetGenerator.blockToCode( ComposeBlock )
const compiledRegex = QuartetGenerator.blockToCode( ComposeBlock )
setConsoleRegEx( `/${ compiledRegex }/` )
updateFlagsForLatestBuild( )
refreshActivatedFlagConsoleView( )
}
//
......@@ -37,7 +39,7 @@
//
function fetchLatestCompiledRegExp ( ) {
let latestCompiledRegEx = getCurrentRegExpFromConsole( )
const latestCompiledRegEx = getCurrentRegExpFromConsole( )
if ( latestCompiledRegEx.length < 3 ) return ''
return latestCompiledRegEx.substring( 1, latestCompiledRegEx.length - 1 )
}
......@@ -65,7 +67,7 @@
//
function onGetEscapedStringRegExp ( ) {
let source = getCurrentRegExpFromConsole( )
const source = getCurrentRegExpFromConsole( )
const regX = new RegExp( source.substring( 1, source.length - 1 ) )
.source
.replace( /\\/g, '\\\\' )
......
......@@ -66,4 +66,19 @@
}, 400 )
}
//
// ─── REFRESH ACTIVATED FLAGS VIEW ───────────────────────────────────────────────
//
function refreshActivatedFlagConsoleView ( ) {
const flagsViewHTML =
Object.keys( activatedFlags )
.map( key => `<div class="sidebar-flags${ ( activatedFlags[ key ]? ' active' : '' ) }">${ key }</div>` )
document.getElementById('orchestra-console-view-flags').innerHTML =
flagsViewHTML.join('')
}
// ────────────────────────────────────────────────────────────────────────────────
{"workspaceXML":"<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"compose\" id=\"~Ieu]{ErPnqqq2~xDzg?\" deletable=\"false\" x=\"130\" y=\"-107\"><statement name=\"blocks\"><block type=\"line_start\" id=\"y!iNeoP@pFn04H?X6RYL\"><next><block type=\"encode\" id=\"cA7WKyC0Ruu#VPw:{_xZ\"><field name=\"text\">[^</field><next><block type=\"any_number_of\" id=\"^7=Bm*F@|c9:izI-bnqv\"><statement name=\"blocks\"><block type=\"anything_but\" id=\"^E6J1%HVV{pGVlo]?:3D\"><field name=\"numbers\">FALSE</field><field name=\"lowercase\">FALSE</field><field name=\"uppercase\">TRUE</field><field name=\"other\">[]^</field></block></statement><next><block type=\"encode\" id=\"kMk.U(MY3OTgaq-OT~M5\"><field name=\"text\">]</field><next><block type=\"line_end\" id=\"*EyNJKpgto;#^ME#^40[\"></block></next></block></next></block></next></block></next></block></statement></block></xml>","playgroundText":""}
\ No newline at end of file
{"workspaceXML":"<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"compose\" id=\"~Ieu]{ErPnqqq2~xDzg?\" deletable=\"false\" x=\"125\" y=\"-167\"><statement name=\"blocks\"><block type=\"comment\" id=\"xT~EBh%9ti~9v~w~FNK6\"><field name=\"comment\">If this RegExp matches, \"m\" flag is needed</field><next><block type=\"comment\" id=\"+/lWPJD4U}+Rp^GqN4B{\"><field name=\"comment\">This makes sure escaped ones never get into count</field><next><block type=\"one_of\" id=\"]!S`gy0Bmb/vXV=tiaLv\"><statement name=\"blocks\"><block type=\"option\" id=\"KrxDRI,JXq!:[-sX:2~j\"><statement name=\"blocks\"><block type=\"line_start\" id=\"589uXE/5HAB?!F:KT-`!\"></block></statement><next><block type=\"option\" id=\";k:#2[c!)@ld|@gcs}nP\"><statement name=\"blocks\"><block type=\"anything_but\" id=\"+s0CbwmcC_7*zk9B[qh7\"><field name=\"numbers\">FALSE</field><field name=\"lowercase\">FALSE</field><field name=\"uppercase\">FALSE</field><field name=\"other\">\\</field></block></statement></block></next></block></statement><next><block type=\"match\" id=\".F!CGKtGf?r%}YV::@ve\"><statement name=\"blocks\"><block type=\"one_of\" id=\"%5h!qMd`;P}C0Q7RGx=H\"><statement name=\"blocks\"><block type=\"option\" id=\"W=4~)(,.u*Sw%-jMYiG9\"><statement name=\"blocks\"><block type=\"comment\" id=\"j/VkzQ3m,.y_{r5T}1[`\"><field name=\"comment\">Next Line</field><next><block type=\"encode\" id=\"?)zg_h-(0Jr^e)kwMMa;\"><field name=\"text\">\\n</field></block></next></block></statement><next><block type=\"option\" id=\"Yn|Al|gC/*oqk;RPTTp.\"><statement name=\"blocks\"><block type=\"comment\" id=\"J;V~Re/@0q.p|Ik5D1LO\"><field name=\"comment\">Carrige Return</field><next><block type=\"encode\" id=\"gPj[c9c:wFhNJ:86{da+\"><field name=\"text\">\\r</field></block></next></block></statement><next><block type=\"option\" id=\"1FI_U3Jl68tl5Q9eK4:h\"><statement name=\"blocks\"><block type=\"comment\" id=\"uaP-BH944};MZ(*^rhiu\"><field name=\"comment\">Line Feed</field><next><block type=\"encode\" id=\"%SQJC@{tO*YsKhOAaT4K\"><field name=\"text\">\\f</field></block></next></block></statement><next><block type=\"option\" id=\"8DJ_!L}W{n5AxdbNwI}+\"><statement name=\"blocks\"><block type=\"comment\" id=\"r`nxbrR}U`s^|]9]J{:r\"><field name=\"comment\">Vertical Tab</field><next><block type=\"encode\" id=\"KYxnbz5X=S#f[{=5xtad\"><field name=\"text\">\\v</field></block></next></block></statement><next><block type=\"option\" id=\"zQ,3|ZzBH5-(TVhj52ie\"><statement name=\"blocks\"><block type=\"encode\" id=\"JlzK+MRIO?7f?,C+HQ_J\"><field name=\"text\">\\u0085</field></block></statement><next><block type=\"option\" id=\"KQ=6!g%Q-3pYP;.2HzH7\"><statement name=\"blocks\"><block type=\"encode\" id=\"RZl?cnq/Mu.m03RK~86l\"><field name=\"text\">\\u2028</field></block></statement><next><block type=\"option\" id=\":r|!Oxxr,8Ai]BXG!K4R\"><statement name=\"blocks\"><block type=\"encode\" id=\"!JPTyJDEIir3,a?d|dzc\"><field name=\"text\">\\u2029</field></block></statement><next><block type=\"option\" id=\"@U6~0w-ER;Qi.aQ3[Fw)\"><statement name=\"blocks\"><block type=\"one_of\" id=\"ryJoG;X]WowzmLc)#`@G\"><statement name=\"blocks\"><block type=\"option\" id=\"3}),B7KpBkKs(4W!Ih?x\"><statement name=\"blocks\"><block type=\"comment\" id=\"v,u[|#=/cI|giaOm`x.H\"><field name=\"comment\">[\\s\\S] or [\\w\\W]</field><next><block type=\"encode\" id=\"q}Bu#AfAQMTZYQ+Hoanu\"><field name=\"text\">[</field><next><block type=\"any_number_of\" id=\"-RZ0kd1Z6Dt.lhc3dj_|\"><statement name=\"blocks\"><block type=\"anything_but\" id=\";jik`_[13?V+I%6Hb;/0\"><field name=\"numbers\">FALSE</field><field name=\"lowercase\">FALSE</field><field name=\"uppercase\">TRUE</field><field name=\"other\">[]^</field></block></statement><next><block type=\"one_of\" id=\"GS+HgM/6915*P^_R,ihl\"><statement name=\"blocks\"><block type=\"option\" id=\"wLW_(0rJ76Hfbu]nURLY\"><statement name=\"blocks\"><block type=\"encode\" id=\"B4LUo**QJdUldrMqV56P\"><field name=\"text\">\\s</field><next><block type=\"any_number_of\" id=\"g#!S-=HC.pC8NaNSy/2u\"><statement name=\"blocks\"><block type=\"anything_but\" id=\"|Hc!{;F|@B[Mf8L^Q+a=\"><field name=\"numbers\">FALSE</field><field name=\"lowercase\">FALSE</field><field name=\"uppercase\">TRUE</field><field name=\"other\">[]</field></block></statement><next><block type=\"encode\" id=\"xOR[/tiy[47,Ht%.xn97\"><field name=\"text\">\\S</field></block></next></block></next></block></statement><next><block type=\"option\" id=\"R;@8GL*8E=jlN4ZA59(u\"><statement name=\"blocks\"><block type=\"encode\" id=\"_CwNhQOxaEfp_i/Ot80w\"><field name=\"text\">\\w</field><next><block type=\"any_number_of\" id=\"jn)t_PL1[?x7l^gP!^iJ\"><statement name=\"blocks\"><block type=\"anything_but\" id=\"60BSAKe=`CB2A`4+_zKi\"><field name=\"numbers\">FALSE</field><field name=\"lowercase\">FALSE</field><field name=\"uppercase\">TRUE</field><field name=\"other\">[]</field></block></statement><next><block type=\"encode\" id=\"*:jE*|p{OSB2M~?axpBV\"><field name=\"text\">\\W</field></block></next></block></next></block></statement><next><block type=\"option\" id=\"Cb|6JY6V`3Vc)zH=14r/\"><statement name=\"blocks\"><block type=\"encode\" id=\"Mq#CXBd4A(Hl79p_)0,=\"><field name=\"text\">\\W</field><next><block type=\"any_number_of\" id=\"7?z79:Bb,Fu*W?f;{KEd\"><statement name=\"blocks\"><block type=\"anything_but\" id=\"v#2/xX.8`zu[h{B=hAE]\"><field name=\"numbers\">FALSE</field><field name=\"lowercase\">FALSE</field><field name=\"uppercase\">TRUE</field><field name=\"other\">[]</field></block></statement><next><block type=\"encode\" id=\"5Wlwl?FVhv9M*]#]Qb:(\"><field name=\"text\">\\w</field></block></next></block></next></block></statement><next><block type=\"option\" id=\",SqH5uG0-PF#iZRrb%Ze\"><statement name=\"blocks\"><block type=\"encode\" id=\"PjPr~1@#lQ[~;@Z-wm5+\"><field name=\"text\">\\S</field><next><block type=\"any_number_of\" id=\"?veB`Nc~`S^s-fBx=|;U\"><statement name=\"blocks\"><block type=\"anything_but\" id=\"e#2?6jJ71Y?:c1H^-yND\"><field name=\"numbers\">FALSE</field><field name=\"lowercase\">FALSE</field><field name=\"uppercase\">TRUE</field><field name=\"other\">[]</field></block></statement><next><block type=\"encode\" id=\"XCG4^T~{WIZou,-8?[@B\"><field name=\"text\">\\s</field></block></next></block></next></block></statement></block></next></block></next></block></next></block></statement><next><block type=\"any_number_of\" id=\"m#+;M?4/oj#V,PVW?HPd\"><statement name=\"blocks\"><block type=\"anything_but\" id=\"L-h7v-dMu]j7]_et0`M5\"><field name=\"numbers\">FALSE</field><field name=\"lowercase\">FALSE</field><field name=\"uppercase\">TRUE</field><field name=\"other\">[]</field></block></statement><next><block type=\"encode\" id=\"EoJFU]~KBWK!V`?nDeW;\"><field name=\"text\">]</field></block></next></block></next></block></next></block></next></block></next></block></statement><next><block type=\"option\" id=\"eZqN~Nd#+0Z_mBr.@ap(\"><statement name=\"blocks\"><block type=\"comment\" id=\"*#7D#F@oVQ4y%Xc[vZNt\"><field name=\"comment\">[^]</field><next><block type=\"encode\" id=\"cA7WKyC0Ruu#VPw:{_xZ\"><field name=\"text\">[^</field><next><block type=\"any_number_of\" id=\"^7=Bm*F@|c9:izI-bnqv\"><statement name=\"blocks\"><block type=\"anything_but\" id=\"^E6J1%HVV{pGVlo]?:3D\"><field name=\"numbers\">FALSE</field><field name=\"lowercase\">FALSE</field><field name=\"uppercase\">TRUE</field><field name=\"other\">[]^</field></block></statement><next><block type=\"encode\" id=\"kMk.U(MY3OTgaq-OT~M5\"><field name=\"text\">]</field></block></next></block></next></block></next></block></statement></block></next></block></statement></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></statement></block></next></block></next></block></next></block></statement></block></xml>","playgroundText":""}
\ No newline at end of file
......@@ -23,6 +23,7 @@
<script src="quartet/generator.js"></script>
<script src="quartet/blocks.js"></script>
<script src="quartet/blockly-styles.js"></script>
<script src="quartet/result-checker.js"></script>
<script src="quartet/base.js"></script>
<script src="quartet/ui.js"></script>
<script src="quartet/loader.js"></script>
......@@ -147,13 +148,7 @@
<div id="side-bar-container">
<div class="flex-fixed">
<div class="console-sidebar-title">activated flags</div>
<div id="orchestra-console-view-flags">
<div class="sidebar-flags">m</div>
<div class="sidebar-flags active">g</div>
<div class="sidebar-flags active">i</div>
<div class="sidebar-flags">u</div>
<div class="sidebar-flags">y</div>
</div>
<div id="orchestra-console-view-flags"></div>
</div>
<div class="console-sidebar-spacer"></div>
<div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment