Skip to content

Commit

Permalink
feat: make quoting methods public
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Aug 14, 2023
1 parent 18ee0ec commit dfac8a9
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 15 deletions.
10 changes: 5 additions & 5 deletions core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type BlockGenerator = (
/**
* Class for a code generator that translates the blocks into a language.
*/
export class CodeGenerator {
export abstract class CodeGenerator {
name_: string;

/** A dictionary of block generator functions keyed by block type. */
Expand Down Expand Up @@ -170,10 +170,6 @@ export class CodeGenerator {
return codeString;
}

// The following are some helpful functions which can be used by multiple

// languages.

/**
* Prepend a common prefix onto each line of code.
* Intended for indenting code or adding comment markers.
Expand Down Expand Up @@ -441,6 +437,10 @@ export class CodeGenerator {
return msg.replace(/%1/g, "'" + id + "'");
}

abstract quote_(toQuote: string): string;

abstract multiline_quote_(toQuote: string): string;

/**
* Add one or more words to the list of reserved words for this language.
*
Expand Down
2 changes: 0 additions & 2 deletions generators/dart/dart_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ export class DartGenerator extends CodeGenerator {
* Encode a string as a properly escaped Dart string, complete with quotes.
* @param {string} string Text to encode.
* @return {string} Dart string.
* @protected
*/
quote_(string) {
// Can't use goog.string.quote since $ must also be escaped.
Expand All @@ -192,7 +191,6 @@ export class DartGenerator extends CodeGenerator {
* quotes.
* @param {string} string Text to encode.
* @return {string} Dart string.
* @protected
*/
multiline_quote_(string) {
const lines = string.split(/\n/g).map(this.quote_);
Expand Down
2 changes: 0 additions & 2 deletions generators/javascript/javascript_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ export class JavascriptGenerator extends CodeGenerator {
* quotes.
* @param {string} string Text to encode.
* @return {string} JavaScript string.
* @protected
*/
quote_(string) {
// Can't use goog.string.quote since Google's style guide recommends
Expand All @@ -222,7 +221,6 @@ export class JavascriptGenerator extends CodeGenerator {
* with quotes.
* @param {string} string Text to encode.
* @return {string} JavaScript string.
* @protected
*/
multiline_quote_(string) {
// Can't use goog.string.quote since Google's style guide recommends
Expand Down
2 changes: 0 additions & 2 deletions generators/lua/lua_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export class LuaGenerator extends CodeGenerator {
* quotes.
* @param {string} string Text to encode.
* @return {string} Lua string.
* @protected
*/
quote_(string) {
string = string.replace(/\\/g, '\\\\')
Expand All @@ -163,7 +162,6 @@ export class LuaGenerator extends CodeGenerator {
* quotes.
* @param {string} string Text to encode.
* @return {string} Lua string.
* @protected
*/
multiline_quote_(string) {
const lines = string.split(/\n/g).map(this.quote_);
Expand Down
2 changes: 0 additions & 2 deletions generators/php/php_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ export class PhpGenerator extends CodeGenerator {
* quotes.
* @param {string} string Text to encode.
* @return {string} PHP string.
* @protected
*/
quote_(string) {
string = string.replace(/\\/g, '\\\\')
Expand All @@ -198,7 +197,6 @@ export class PhpGenerator extends CodeGenerator {
* quotes.
* @param {string} string Text to encode.
* @return {string} PHP string.
* @protected
*/
multiline_quote_(string) {
const lines = string.split(/\n/g).map(this.quote_);
Expand Down
2 changes: 0 additions & 2 deletions generators/python/python_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ export class PythonGenerator extends CodeGenerator {
* Encode a string as a properly escaped Python string, complete with quotes.
* @param {string} string Text to encode.
* @return {string} Python string.
* @protected
*/
quote_(string) {
string = string.replace(/\\/g, '\\\\').replace(/\n/g, '\\\n');
Expand All @@ -250,7 +249,6 @@ export class PythonGenerator extends CodeGenerator {
* with quotes.
* @param {string} string Text to encode.
* @return {string} Python string.
* @protected
*/
multiline_quote_(string) {
const lines = string.split(/\n/g).map(this.quote_);
Expand Down

0 comments on commit dfac8a9

Please sign in to comment.