refactor(generators): Introduce PythonGenerator class, Order enum (#7163)

* refactor(generators): Introduce PhpGenerator class, Order enum

* refactor(generators): Use Order.* instead of .ORDER_*

* refactor(generators): Don't rename pythonGenerator
This commit is contained in:
Christopher Allen
2023-06-14 16:51:15 +01:00
committed by GitHub
parent 26901654ea
commit 2f89c0dd09
10 changed files with 725 additions and 671 deletions

View File

@@ -12,21 +12,23 @@ import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Python.variables');
import {NameType} from '../../core/names.js';
import {pythonGenerator as Python} from '../python.js';
import {pythonGenerator, Order} from '../python.js';
Python.forBlock['variables_get'] = function(block) {
pythonGenerator.forBlock['variables_get'] = function(block) {
// Variable getter.
const code =
Python.nameDB_.getName(block.getFieldValue('VAR'), NameType.VARIABLE);
return [code, Python.ORDER_ATOMIC];
pythonGenerator.nameDB_.getName(
block.getFieldValue('VAR'), NameType.VARIABLE);
return [code, Order.ATOMIC];
};
Python.forBlock['variables_set'] = function(block) {
pythonGenerator.forBlock['variables_set'] = function(block) {
// Variable setter.
const argument0 =
Python.valueToCode(block, 'VALUE', Python.ORDER_NONE) || '0';
pythonGenerator.valueToCode(block, 'VALUE', Order.NONE) || '0';
const varName =
Python.nameDB_.getName(block.getFieldValue('VAR'), NameType.VARIABLE);
pythonGenerator.nameDB_.getName(
block.getFieldValue('VAR'), NameType.VARIABLE);
return varName + ' = ' + argument0 + '\n';
};