Skip to content

Commit

Permalink
Improve Regex Category
Browse files Browse the repository at this point in the history
  • Loading branch information
foivospro committed Oct 1, 2024
1 parent db1f13d commit 39c2d0f
Show file tree
Hide file tree
Showing 24 changed files with 182 additions and 199 deletions.
Binary file modified db/blockly_unix_database.db
Binary file not shown.
24 changes: 14 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

<!-- BLOCKS DEFINITION -->
<script src="blocks/psBlock.js"></script>
<script src="blocks/argumentsCreateBlock.js"></script>
<script src="blocks/argumentBlock.js"></script>
<script src="blocks/regBackreferenceBlock.js"></script>
<script src="blocks/dfBlock.js"></script>
<script src="blocks/killBlock.js"></script>
<script src="blocks/chmodBlock.js"></script>
Expand Down Expand Up @@ -58,9 +61,7 @@
<script src="blocks/catBlock.js"></script>
<script src="blocks/saveBlock.js"></script>
<script src="blocks/appendBlock.js"></script>
<script src="blocks/regOutputBlock.js"></script>
<script src="blocks/regPatternBlock.js"></script>
<script src="blocks/regOrBlock.js"></script>
<script src="blocks/regCapturingGroupBlock.js"></script>
<script src="blocks/regStartBlock.js"></script>
<script src="blocks/regEndBlock.js"></script>
Expand All @@ -77,7 +78,6 @@
<script src="blocks/fileEndStartBlock.js"></script>
<script src="blocks/echoBlock.js"></script>
<script src="blocks/findBlock.js"></script>
<script src="blocks/regLookaheadBlock.js"></script>
<script src="blocks/regCommonBlock.js"></script>
<script src="blocks/touchBlock.js"></script>
<script src="blocks/NRBlock.js"></script>
Expand Down Expand Up @@ -239,7 +239,7 @@
colourSecondary: '#FFCDD2',
colourTertiary: '#CDB6E9'
},
'File inputs': {
'Function inputs': {
colourPrimary: '#5C81A6',
colourSecondary: '#ff0000',
colourTertiary: '#C5EAFF'
Expand Down Expand Up @@ -352,12 +352,14 @@
},
{
kind: 'category',
name: [MSG.FILE_INPUTS],
name: [MSG.FUCTION_INPUTS],
colour: '#5C81A6',
contents: [
{ kind: 'block', type: 'filename' },
{ kind: 'block', type: 'filenamesCreate' },
{ kind: 'block', type: 'fileEndStart' }
{ kind: 'block', type: 'fileEndStart' },
{ kind: 'block', type: 'argument' },
{ kind: 'block', type: 'argumentsCreate' }
]
},
{
Expand All @@ -373,6 +375,7 @@
{ kind: 'block', type: 'mv' },
{ kind: 'block', type: 'rm' },
{ kind: 'block', type: 'ls' },
{ kind: 'block', type: 'cd' },
{ kind: 'block', type: 'find' },
{ kind: 'block', type: 'mkdir' }
]
Expand All @@ -399,13 +402,14 @@
colour: '#FF5733',
contents: [
{ kind: 'block', type: 'regPattern' },
{ kind: 'block', type: 'regOr' },
{ kind: 'block', type: 'regCapturingGroup' },
{ kind: 'block', type: 'regStart' },
{ kind: 'block', type: 'regEnd' },
{ kind: 'block', type: 'regFor' },
{ kind: 'block', type: 'regRange' },
{ kind: 'block', type: 'regStart' },
{ kind: 'block', type: 'regEnd' },
{ kind: 'block', type: 'regAnyOne' },
{ kind: 'block', type: 'regCapturingGroup' },
{ kind: 'block', type: 'regAlternation' },
{ kind: 'block', type: 'regBackreference' },
{ kind: 'block', type: 'regCommon' }
]
},
Expand Down
19 changes: 19 additions & 0 deletions public/blocks/argumentBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var argumentBlock = {
type: 'argument',
category: 'Function inputs',
message0: '%{BKY_ARGUMENT} %1',
args0: [
{
type: 'field_input',
name: 'argument',
text: 'argument' // default text for the input
}
],

output: 'String',
style: 'Function inputs',
tooltip: '%{BKY_ARGUMENT_TOOLTIP}',
helpUrl: '%{BKY_ARGUMENT_HELPURL}' // URL για περαιτέρω πληροφορίες ή τεκμηρίωση.
};

Blockly.defineBlocksWithJsonArray([argumentBlock]);
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
var regOrBlock = {
type: 'regOr',
category: 'Regular Expressions',
message0: '%{BKY_REGOR_CREATE_WITH} %1',
var argumentsCreateBlock = {
type: 'argumentsCreate',
category: 'Function inputs',
message0: '%{BKY_ARGUMENTS_CREATE_WITH} %1',
args0: [
{
type: 'input_dummy',
name: 'EMPTY'
}
],
output: 'String',
style: 'Regular Expressions',
helpUrl: '%{BKY_REGOR_CREATE_WITH_HELPURL}',
tooltip: '%{BKY_REGOR_CREATE_WITH_TOOLTIP}',
mutator: 'new_list_create_with_mutator_OrRegex'
style: 'Function inputs',
helpUrl: '%{BKY_ARGUMENTS_CREATE_WITH_HELPURL}',
tooltip: '%{BKY_ARGUMENTS_CREATE_WITH_TOOLTIP}',
mutator: 'new_list_create_with_mutator_Arguments'
};

Blockly.defineBlocksWithJsonArray([regOrBlock]);
Blockly.defineBlocksWithJsonArray([argumentsCreateBlock]);

const listCreateMutator_OrRegex = {
const listCreateMutator_Arguments = {
/**
* Number of item inputs the block has.
* @type {number}
*/
itemCount_: 0,

/**
* Creates XML to represent number of text inputs.
* Creates XML to represent number of argument inputs.
* @returns {!Element} XML storage element.
* @this {Blockly.Block}
*/
Expand All @@ -35,7 +35,7 @@ const listCreateMutator_OrRegex = {
return container;
},
/**
* Parses XML to restore the text inputs.
* Parses XML to restore the argument inputs.
* @param {!Element} xmlElement XML storage element.
* @this {Blockly.Block}
*/
Expand Down Expand Up @@ -99,10 +99,6 @@ const listCreateMutator_OrRegex = {
this.updateMinus_();
},

// To properly keep track of indices we have to increment before/after adding
// the inputs, and decrement the opposite.
// Because we want our first input to be ADD0 (not ADD1) we increment after.

/**
* Adds an input to the end of the block. If the block currently has no
* inputs it updates the top 'EMPTY' input to receive a block.
Expand All @@ -114,7 +110,7 @@ const listCreateMutator_OrRegex = {
this.removeInput('EMPTY');
this.topInput_ = this.appendValueInput('ADD' + this.itemCount_)
.appendField(createPlusField(), 'PLUS')
.appendField(Blockly.Msg['REGOR_CREATE_WITH']);
.appendField(Blockly.Msg['ARGUMENTS_CREATE_WITH']);
} else {
this.appendValueInput('ADD' + this.itemCount_);
}
Expand All @@ -133,7 +129,7 @@ const listCreateMutator_OrRegex = {
if (this.itemCount_ == 0) {
this.topInput_ = this.appendDummyInput('EMPTY')
.appendField(createPlusField(), 'PLUS')
.appendField(Blockly.Msg['REGOR_CREATE_EMPTY_TITLE']);
.appendField(Blockly.Msg['ARGUMENTS_CREATE_EMPTY_TITLE']);
}
},

Expand All @@ -155,13 +151,13 @@ const listCreateMutator_OrRegex = {
* Updates the shape of the block to have 3 inputs if no mutation is provided.
* @this {Blockly.Block}
*/
const listCreateHelper_OrRegex = function () {
const listCreateHelper_Arguments = function () {
this.getInput('EMPTY').insertFieldAt(0, createPlusField(), 'PLUS');
this.updateShape_(2);
};

Blockly.Extensions.registerMutator(
'new_list_create_with_mutator_OrRegex',
listCreateMutator_OrRegex,
listCreateHelper_OrRegex
'new_list_create_with_mutator_Arguments',
listCreateMutator_Arguments,
listCreateHelper_Arguments
);
13 changes: 4 additions & 9 deletions public/blocks/cdBlock.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
var cdBlock = {
type: 'cd',
category: 'Filesystem Operations',
unix_description: [
{
directory: './str'
}
],
unix_description: [{}],
message0: '%{BKY_CD} %1',
args0: [
{
type: 'field_input',
name: 'directory',
text: '' // αρχικό κενό text για να ορίσει ο χρήστης το path
text: '............' // empty text for user to define path
}
],
style: 'File and Directory Operations',
style: 'Filesystem Operations',
tooltip: '%{BKY_CD_TOOLTIP}',
helpUrl: '%{BKY_CD_HELPURL}' // Σύνδεσμος για περισσότερες πληροφορίες ή τεκμηρίωση.
helpUrl: '%{BKY_CD_HELPURL}' // URL to further information or documentation.
};

// Εισάγουμε το block στο Blockly
Blockly.defineBlocksWithJsonArray([cdBlock]);
4 changes: 2 additions & 2 deletions public/blocks/fileEndStartBlock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var fileEndStartBlock = {
type: 'fileEndStart',
category: 'File inputs',
category: 'Function inputs',
unix_description: [
{
starts: 'str*',
Expand All @@ -26,7 +26,7 @@ var fileEndStartBlock = {
],

output: 'fileWildcard',
style: 'File inputs',
style: 'Function inputs',
tooltip: '%{BKY_FILE_END_START_WILDCHARS_TOOLTIP}',
helpUrl: '%{BKY_FILE_END_START_WILDCHARS_HELPURL} ' // URL to further information or documentation.
};
Expand Down
4 changes: 2 additions & 2 deletions public/blocks/filenameBlock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var filenameBlock = {
type: 'filename',
category: 'File inputs',
category: 'Function inputs',
message0: '%{BKY_FILENAME} %1',
args0: [
{
Expand All @@ -10,7 +10,7 @@ var filenameBlock = {
}
],
output: 'filename',
style: 'File inputs',
style: 'Function inputs',
tooltip: '%{BKY_FILENAME_TOOLTIP}',
helpUrl: '%{BKY_FILENAME_HELPURL}' // URL to further information or documentation.
};
Expand Down
4 changes: 2 additions & 2 deletions public/blocks/filenamesCreateBlock.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var filenamesCreateBlock = {
type: 'filenamesCreate',
category: 'File inputs',
category: 'Function inputs',
message0: '%{BKY_FILES_CREATE_WITH} %1',
args0: [
{
type: 'input_dummy',
name: 'EMPTY'
}
],
style: 'File inputs',
style: 'Function inputs',
nextStatement: 'Action',
helpUrl: '%{BKY_FILES_CREATE_WITH_HELPURL}',
tooltip: '%{BKY_FILES_CREATE_WITH_TOOLTIP}',
Expand Down
13 changes: 8 additions & 5 deletions public/blocks/lnBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ var lnBlock = {
force: '-f',
interactive: '-i',
follow_symlink: '-L',
no_symlink_follow: '-P'
no_symlink_follow: '-P',
SOURCE: 'str'
}
],
message1: '%{BKY_LN_SYMBOLIC_LINK}',
Expand Down Expand Up @@ -39,14 +40,16 @@ var lnBlock = {
message4: '%{BKY_LN_SOURCE}: %1 %{BKY_LN_TARGET}: %2',
args4: [
{
type: 'field_input',
type: 'input_value',
name: 'SOURCE',
text: 'source' // default source
text: 'source', // default source
check: 'String'
},
{
type: 'field_input',
type: 'input_value',
name: 'TARGET',
text: 'target' // default target
text: 'target', // default target
check: 'String'
}
],
style: 'Filesystem Operations',
Expand Down
1 change: 1 addition & 0 deletions public/blocks/regAlternationBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var regAlternationBlock = {
}
],
style: 'Regular Expressions',
output: 'String',
previousStatement: null,
nextStatement: null,
tooltip:
Expand Down
21 changes: 11 additions & 10 deletions public/blocks/regAnyOneBlock.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
var regAnyOneBlock = {
type: 'regAnyOne',
category: 'Regular Expressions',
unix_description: [
{
regPattern: '[patt]',
notMatch: 'patt^'
notMatch: '[^patt^]'
}
],
category: 'Regular Expressions',
message0: '%{BKY_REGANYONE}',

message0: '%{BKY_REGANYONE} \n Not %2',
args0: [
{
type: 'input_value',
type: 'input_statement',
name: 'regPattern',
check: 'String'
}
],
message1: '%{BKY_REGANYONE_NOT}',
args1: [
},

{
type: 'field_checkbox',
name: 'notMatch',
checked: false
}
],

tooltip: '%{BKY_REGANYONE_TOOLTIP}',
previousStatement: 'Action',
nextStatement: 'Action',
output: 'String',
previousStatement: null,
nextStatement: null,
style: 'Regular Expressions',
helpUrl: '%{BKY_REGANYONE_HELPURL}' // URL to further information or documentation.
};
Expand Down
Loading

0 comments on commit 39c2d0f

Please sign in to comment.