Skip to content

Commit

Permalink
Changes for awk blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
simosathan9 committed Oct 10, 2024
1 parent 3fd2f85 commit bb3fbf2
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 134 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<script src="blocks/NFBlock.js"></script>
<script src="blocks/xargsBlock.js"></script>
<script src="blocks/conditionActionBlock.js"></script>
<script src="blocks/conditionBlock.js"></script>
<!-- END OF BLOCK DEFINITION -->
<script>
document.addEventListener('DOMContentLoaded', () => {
Expand Down Expand Up @@ -456,6 +457,7 @@
{ kind: 'block', type: 'NR' },
{ kind: 'block', type: 'NF' },
{ kind: 'block', type: 'xargs' },
{ kind: 'block', type: 'condition' },
{
kind: 'category',
name: [MSG.TEXT_OUTPUT],
Expand Down
6 changes: 5 additions & 1 deletion public/blocks/NFBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ var NFBlock = {
style: 'Field Processing',
output: null,
tooltip: '%{BKY_FIELD_NUMBER_TOOLTIP}',
helpUrl: '%{BKY_FIELD_NUMBER_HELPURL}' // URL to further information or documentation.
helpUrl: '%{BKY_FIELD_NUMBER_HELPURL}', // URL to further information or documentation.
generateCommand: function (block) {
var awkCommand = 'NF';
return awkCommand;
}
};

Blockly.defineBlocksWithJsonArray([NFBlock]);
5 changes: 4 additions & 1 deletion public/blocks/NRBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ var NRBlock = {
style: 'Field Processing',
output: null,
tooltip: '%{BKY_RECORD_NUMBER_TOOLTIP}',
helpUrl: '%{BKY_RECORD_NUMBER_HELPURL}' // URL to further information or documentation.
helpUrl: '%{BKY_RECORD_NUMBER_HELPURL}', // URL to further information or documentation.
generateCommand: function (block) {
return 'NR';
}
};

Blockly.defineBlocksWithJsonArray([NRBlock]);
5 changes: 4 additions & 1 deletion public/blocks/awkBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ var awkBlock = {
previousStatement: 'Action',
nextStatement: 'Action',
tooltip: '%{BKY_AWK_TOOLTIP}',
helpUrl: '%{BKY_AWK_HELPURL}' // URL to further information or documentation.
helpUrl: '%{BKY_AWK_HELPURL}', // URL to further information or documentation.
generateCommand: function (block) {
var awkInput_delimiter = block.getFieldValue('awkInput_delimiter');
}
};

Blockly.defineBlocksWithJsonArray([awkBlock]);
6 changes: 5 additions & 1 deletion public/blocks/columnBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ var columnBlock = {
output: null,
style: 'Field Processing',
tooltip: '%{BKY_COLUMN_TOOLTIP}',
helpUrl: '%{BKY_COLUMN_HELPURL}'
helpUrl: '%{BKY_COLUMN_HELPURL}',
generateCommand: function (block) {
var text = block.getFieldValue('TEXT');
return '$' + text;
}
};

Blockly.defineBlocksWithJsonArray([columnBlock]);
15 changes: 14 additions & 1 deletion public/blocks/conditionActionBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@ var conditionActionBlock = {
nextStatement: null,
style: 'Field Processing',
tooltip: '%{BKY_CONDITION_ACTION_TOOLTIP}',
helpUrl: '%{BKY_CONDITION_ACTION_HELPURL}' // URL to further information or documentation.
helpUrl: '%{BKY_CONDITION_ACTION_HELPURL}', // URL to further information or documentation.
generateCommand: function (block) {
var cond = block.getInputTargetBlock('COND');
var condCommand = '';
if (cond !== null) {
condCommand = handleBlockByType(cond);
}
var action = block.getInputTargetBlock('DO');
actionCommand = '';
if (action !== null) {
actionCommand = handleBlockByType(action);
}
return condCommand + ' {' + actionCommand + '}';
}
};

Blockly.defineBlocksWithJsonArray([conditionActionBlock]);
71 changes: 71 additions & 0 deletions public/blocks/conditionBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
var conditionBlock = {
type: 'condition',
category: 'Field Processing',
message0: '%1', // First message line for left_part
args0: [
{
type: 'input_value',
name: 'left_part',
check: ['String', 'Number', 'Boolean'] // Allow both String and Number types
}
],
message1: '%1', // Second message line for operator
args1: [
{
type: 'field_dropdown',
name: 'operator',
options: [
['==', '=='],
['!=', '!='],
['<', '<'],
['<=', '<='],
['>', '>'],
['>=', '>=']
]
}
],
message2: '%1', // Third message line for right_part
args2: [
{
type: 'input_value',
name: 'right_part',
check: ['String', 'Number', 'Boolean'] // Allow both String and Number types
}
],
style: 'Field Processing',
previousStatement: null,
generateCommand: function (block) {
var awkCondition = '';
const leftPartBlock = block.getInputTargetBlock('left_part');
const rightPartBlock = block.getInputTargetBlock('right_part');

const operator = block.getFieldValue('operator');
var leftPart = '';
var rightPart = '';

// Retrieve the command for the left part block, if it exists
if (leftPartBlock !== null) {
leftPart = handleBlockByType(leftPartBlock);
}
if (leftPart === '') {
leftPart = leftPartBlock.getFieldValue('TEXT');
}
console.log('leftPartBlock:', leftPart);

// Retrieve the command for the right part block, if it exists
if (rightPartBlock !== null) {
rightPart = handleBlockByType(rightPartBlock);
}

console.log('leftPart:', leftPart);
console.log('operator:', operator);
console.log('rightPart:', rightPart);

// Combine the parts to form the AWK condition
awkCondition = leftPart + ' ' + operator + ' ' + rightPart;

return awkCondition;
}
};

Blockly.defineBlocksWithJsonArray([conditionBlock]);
2 changes: 1 addition & 1 deletion public/blocks/sedBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var sedBlock = {
tooltip: '%{BKY_SED_TOOLTIP}',
helpUrl: '%{BKY_SED_HELPURL}', // URL to further information or documentation.
generateCommand: function (block) {
let sedCommand = handleBlock(block); // Basic sed command
let sedCommand = handleBlockByType(block); // Basic sed command

// Handle pattern and replacement
let patternBlock = block.getInputTargetBlock('regPattern');
Expand Down
Loading

0 comments on commit bb3fbf2

Please sign in to comment.