Skip to content

Commit

Permalink
modifyEverythingToV2: added arg : is_AHK_H=true ; const whichBuffer =…
Browse files Browse the repository at this point in the history
… is_AHK_H ? 'BufferAlloc' : 'Buffer' ; #16
  • Loading branch information
FuPeiJiang committed Jun 25, 2021
1 parent 13bd696 commit a27f270
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
'key-spacing':['error',{'afterColon':false}],
'object-curly-spacing':'off',
'@typescript-eslint/object-curly-spacing':['error','never'],
'@typescript-eslint/naming-convention':'warn',
'@typescript-eslint/naming-convention':'off',
'@typescript-eslint/semi':['error','never'],
'semi':'off',
'curly':'warn',
Expand Down
13 changes: 7 additions & 6 deletions mocha/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('toV2(text)',function() {
describe('VarSetCapacity()',function() {
doIt('VarSetCapacity(a,b,c)','a:=BufferAlloc(b,c)')
doIt('VarSetCapacity(a,VarSetCapacity(a,b,c),c)','a:=BufferAlloc(a:=BufferAlloc(b,c),c)')
doIt('VarSetCapacity(a,b,c)','a:=Buffer(b,c)',false)
})
// describe('v1 removed #DIRECTIVES',function() {
// doIt('#NoEnv\n','')
Expand All @@ -35,21 +36,21 @@ describe('toV2(text)',function() {

})

function toV2(text) {
function toV2(text,is_AHK_H = true) {
const everything = ahkParser(text.replace(/\r/g,''))
const converted = modifyEverythingToV2(everything)
const converted = modifyEverythingToV2(everything,is_AHK_H)
return converted
}
function doIt(v1,v2) {
function doIt(v1,v2,is_AHK_H = true) {
it(`\`${v1}\`,\`${v2}\``,function() {
strictEqual(toV2(v1),v2)
strictEqual(toV2(v1,is_AHK_H),v2)
})
}
function readFileToString(path) {
return fs.readFileSync(`${__dirname}/${path}`).toString()
}
function doItFiles(path1,path2) {
function doItFiles(path1,path2,is_AHK_H = true) {
it(`FILE: '${path1}' vs '${path2}'`,function() {
strictEqual(toV2(readFileToString(path1)),readFileToString(path2))
strictEqual(toV2(readFileToString(path1),is_AHK_H),readFileToString(path2))
})
}
7 changes: 4 additions & 3 deletions src/modifyEverythingToV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ const startOfV1Expr: stringIndexBool = {'v1String findV1Expression':true,'%START

const typesThatAreVars: stringIndexBool = {'Param':true,'idkVariable':true,'assignment':true,'v1String findIdkVar':true,'var at v1Assignment':true}

export default (everything: ExtendedEverythingType): string => {
export default (everything: ExtendedEverythingType,is_AHK_H = true): string => {
const whichBuffer = is_AHK_H ? 'BufferAlloc' : 'Buffer'
// I'd never think I'd come to this day, but..
// preprocessing..
const varNames: {[key: string]: true} = {}
Expand Down Expand Up @@ -227,7 +228,7 @@ export default (everything: ExtendedEverythingType): string => {
} else {
// VarSetStrCapacity(TargetVar, RequestedCapacity, FillByte)
// TargetVar:=BufferAlloc(RequestedCapacity,FillByte)
a(1); p(':=BufferAlloc('); a(2); o(',',3); a(3); p(')'); s()
a(1); p(`:=${whichBuffer}(`); a(2); o(',',3); a(3); p(')'); s()
}
} else if (thisLowered === 'strreplace') {
// StrReplace(Haystack, Needle [, ReplaceText, OutputVarCount, Limit])
Expand Down Expand Up @@ -271,7 +272,7 @@ export default (everything: ExtendedEverythingType): string => {
// ObjSetCapacity( this, "allData", newSize )
// NOPE: this["allData"].Size := newSize
// this["allData"]:=BufferAlloc(newSize)
a(1); p('['); a(2); p(']:=BufferAlloc('); a(3); p(')'); s()
a(1); p('['); a(2); p(`]:=${whichBuffer}(`); a(3); p(')'); s()
} else {
p('ObjSetCapacity('); a(1); p(','); a(2); p(')'); s()
}
Expand Down

0 comments on commit a27f270

Please sign in to comment.