From 73402411b2d5610d0b396c65b52ecb884b61d0ce Mon Sep 17 00:00:00 2001 From: Kirill Shumilov Date: Thu, 17 Sep 2020 15:38:03 +0300 Subject: [PATCH 1/2] chore(xod-project): extract char literal regexp and export it --- packages/xod-project/src/utils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/xod-project/src/utils.js b/packages/xod-project/src/utils.js index f03ce04a7..fe9f3f9fa 100644 --- a/packages/xod-project/src/utils.js +++ b/packages/xod-project/src/utils.js @@ -187,9 +187,11 @@ export const isValidNumberDataValue = R.test(numberDataTypeRegExp); export const isValidPortLiteral = R.test(/^(P[A-F]|A|D)\d{0,3}$/g); +export const charLiteralRegExp = /^'\\?(.)'$/; + export const isLikeCharLiteral = def( 'isLikeCharLiteral :: String -> Boolean', - R.test(/^'\\?.'$/) + R.test(charLiteralRegExp) ); const unescapedCharLiterals = ["'''", "'\\'"]; From 864269ae0c056e06384373c0c3eddf12571f7cfd Mon Sep 17 00:00:00 2001 From: Kirill Shumilov Date: Thu, 17 Sep 2020 16:34:03 +0300 Subject: [PATCH 2/2] fix(xo-arduino): make possible to send char literals in tweak-byte nodes --- .../xod-arduino/src/formatTweakMessage.js | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/xod-arduino/src/formatTweakMessage.js b/packages/xod-arduino/src/formatTweakMessage.js index bbb6fdc61..186e0b981 100644 --- a/packages/xod-arduino/src/formatTweakMessage.js +++ b/packages/xod-arduino/src/formatTweakMessage.js @@ -7,6 +7,24 @@ import { def } from './types'; import { byteLiteralToDecimal } from './templates'; +// Convert char literals to decimal byte literals +// E.G. `'a'` -> `97d` +const charLiteralToByteLiteral = R.when( + XP.isLikeCharLiteral, + R.compose( + R.concat(R.__, 'd'), + R.toString, + a => a.charCodeAt(0), + R.nth(1), + R.match(XP.charLiteralRegExp) + ) +); + +const formatByteLiteral = R.compose( + byteLiteralToDecimal, + charLiteralToByteLiteral +); + export default def( 'formatTweakMessage :: PatchPath -> NodeId -> DataValue -> String', (nodeType, nodeId, value) => { @@ -17,7 +35,7 @@ export default def( case XP.PIN_TYPE.BOOLEAN: return `${prefix}:${value === 'True' ? '1' : '0'}\r\n`; case XP.PIN_TYPE.BYTE: - return `${prefix}:${byteLiteralToDecimal(value)}\r\n`; + return `${prefix}:${formatByteLiteral(value)}\r\n`; case XP.PIN_TYPE.PULSE: return `${prefix}\r\n`; case XP.PIN_TYPE.STRING: