@@ -40,6 +40,14 @@ $ import path.to.mycoms
4040/*«
4141»*/
4242
43+ /*12/7/25«
44+ @XLMJHU : This barfed when there were BQuote's/ComSub's tokens inside of functions, because the 'raw'
45+ properties never got copied over in the respective dup() methods (@WKLMUJK/@JDPLUI) of the given tokens.
46+ I guess we should add this same thing for all the other dup methods.
47+
48+ @SLKMDUY , I just added the 'parentCommand' arg to the term.funcs functions, so that, e.g. functions
49+ defined inside of shell scripts will inherit the correct stdin/stdin methods.
50+ »*/
4351/*12/3/25: MAJOR OVERHAUL TIME!«
4452
4553We are going to rename, refactor, and simplify everything as much as possible.
@@ -1467,7 +1475,8 @@ class BaseCommand {//«
14671475 #subOutBuffer;
14681476 #haveEOF;
14691477 #awaitPipeInCb;
1470- constructor ( ) {
1478+ constructor ( parentCom ) {
1479+ this . parentCom = parentCom ;
14711480 }
14721481 initPipeInBuffer ( ) {
14731482 this . #haveEOF = false ;
@@ -1476,6 +1485,9 @@ class BaseCommand {//«
14761485 get haveStdin ( ) {
14771486 return this . pipeFrom || this . haveRedirIn ;
14781487 }
1488+ get isTermOut ( ) {
1489+ return ! ( this . haveRedirOut || this . nextCom || this . parentCom || this . subLines ) ;
1490+ }
14791491 initRedirInBuffer ( buf ) {
14801492if ( ! isArr ( buf ) ) {
14811493log ( buf ) ;
@@ -1530,8 +1542,8 @@ return;
15301542 }
15311543 else if ( isEOF ( val ) ) { }
15321544 else {
1533- log ( val ) ;
1534- DIE ( `Unknown value in the com sub output stream (above)` ) ;
1545+ log ( val ) ;
1546+ DIE ( `Unknown value in the com sub output stream (above)` ) ;
15351547 }
15361548 }
15371549 else {
@@ -1627,7 +1639,7 @@ async #pipeBytesDone(){//«
16271639class SimpleCommand extends BaseCommand { //«
16281640// #lines;
16291641 constructor ( name , args , opts , env , parentCom ) { //«
1630- super ( ) ;
1642+ super ( parentCom ) ;
16311643 if ( ! env ) env = { } ;
16321644// this.#lines = [];
16331645// this.#haveEOF = false;
@@ -1639,7 +1651,7 @@ class SimpleCommand extends BaseCommand{//«
16391651 this . opts = opts ;
16401652 this . numErrors = 0 ;
16411653 this . noPipe = false ;
1642- this . parentCom = parentCom ;
1654+ // this.parentCom = parentCom;
16431655//log(this.name, this.parentCommand);
16441656 for ( let k in env ) {
16451657 this [ k ] = env [ k ] ;
@@ -1732,7 +1744,10 @@ class SimpleCommand extends BaseCommand{//«
17321744 get noStdin ( ) { return ( ! ( this . pipeFrom || this . stdin ) ) ; }
17331745 get useStdin ( ) { return this . argsLen === 0 && ( this . pipeFrom || this . haveRedirIn ) ; }
17341746 get noArgs ( ) { return ( this . args . length === 0 ) ; }
1735- isTermOut ( ) { return ! ( this . nextCom || this . scriptOut || this . subLines ) ; }
1747+ // isTermOut(){
1748+ //cwarn("isTermOut: Update this OLD logic!!!");
1749+ // return !(this.nextCom || this.scriptOut || this.subLines);
1750+ // }
17361751 expectArgs ( num ) { //«
17371752 if ( ! isNum ( num ) ) {
17381753 this . err ( `invalid argument given to expectArgs (see console)` ) ;
@@ -1886,8 +1901,8 @@ class ErrCom extends SimpleCommand{//«
18861901
18871902class CompoundCom extends BaseCommand { //«
18881903
1889- constructor ( shell , opts ) { //«
1890- super ( ) ;
1904+ constructor ( shell , opts , parentCommand ) { //«
1905+ super ( parentCommand ) ;
18911906 this . isCompound = true ;
18921907 this . shell = shell ;
18931908 this . term = shell . term ;
@@ -1923,11 +1938,11 @@ log(val);
19231938
19241939class BraceGroupCom extends CompoundCom { //«
19251940
1926- constructor ( shell , opts , list , parentCommand ) { //«
1927- super ( shell , opts ) ;
1941+ constructor ( shell , opts , list , parentCom ) { //«
1942+ super ( shell , opts , parentCom ) ;
19281943 this . list = list ;
19291944 this . name = "brace_group" ;
1930- this . parentCommand = parentCommand ;
1945+ // this.parentCom = parentCommand;
19311946} //»
19321947async run ( ) { //«
19331948 if ( this . isFunc ) {
@@ -1941,11 +1956,11 @@ async run(){//«
19411956
19421957} //»
19431958class SubshellCom extends CompoundCom { //«
1944- constructor ( shell , opts , list , parentCommand ) {
1945- super ( shell , opts ) ;
1959+ constructor ( shell , opts , list , parentCom ) {
1960+ super ( shell , opts , parentCom ) ;
19461961 this . list = list ;
19471962 this . name = "subshell" ;
1948- this . parentCommand = parentCommand ;
1963+ // this.parentCom = parentCommand;
19491964}
19501965async run ( ) {
19511966 if ( this . isFunc ) {
@@ -1965,14 +1980,14 @@ async run(){
19651980
19661981class WhileCom extends CompoundCom { //«
19671982
1968- constructor ( shell , opts , cond , do_group , parentCommand ) { //«
1969- super ( shell , opts ) ;
1983+ constructor ( shell , opts , cond , do_group , parentCom ) { //«
1984+ super ( shell , opts , parentCom ) ;
19701985 if ( this . opts . loopNum ) this . opts . loopNum ++ ;
19711986 else this . opts . loopNum = 1 ;
19721987 this . cond = cond ;
19731988 this . do_group = do_group ;
19741989 this . name = "while" ;
1975- this . parentCommand = parentCommand ;
1990+ // this.parentCom = parentCommand;
19761991} //»
19771992async run ( ) { //«
19781993 let rv ;
@@ -2021,14 +2036,14 @@ log(rv);
20212036} //»
20222037class UntilCom extends CompoundCom { //«
20232038
2024- constructor ( shell , opts , cond , do_group , parentCommand ) { //«
2025- super ( shell , opts ) ;
2039+ constructor ( shell , opts , cond , do_group , parentCom ) { //«
2040+ super ( shell , opts , parentCom ) ;
20262041 if ( this . opts . loopNum ) this . opts . loopNum ++ ;
20272042 else this . opts . loopNum = 1 ;
20282043 this . cond = cond ;
20292044 this . do_group = do_group ;
20302045 this . name = "until" ;
2031- this . parentCommand = parentCommand ;
2046+ // this.parentCom = parentCommand;
20322047} //»
20332048async run ( ) { //«
20342049 let rv ;
@@ -2092,13 +2107,13 @@ async run(){//«
20922107} //»
20932108
20942109class IfCom extends CompoundCom { //«
2095- constructor ( shell , opts , conds , conseqs , fallback , parentCommand ) { //«
2096- super ( shell , opts ) ;
2110+ constructor ( shell , opts , conds , conseqs , fallback , parentCom ) { //«
2111+ super ( shell , opts , parentCom ) ;
20972112 this . conds = conds ;
20982113 this . conseqs = conseqs
20992114 this . fallback = fallback ;
21002115 this . name = "if" ;
2101- this . parentCommand = parentCommand ;
2116+ // this.parentCom = parentCommand;
21022117} //»
21032118async run ( ) { //«
21042119 const { conds, conseqs, opts} = this ;
@@ -2127,15 +2142,15 @@ this.shell.fatal("Non-numerical return value");
21272142} //»
21282143class ForCom extends CompoundCom { //«
21292144
2130- constructor ( shell , opts , name , in_list , do_group , parentCommand ) { //«
2131- super ( shell , opts ) ;
2145+ constructor ( shell , opts , name , in_list , do_group , parentCom ) { //«
2146+ super ( shell , opts , parentCom ) ;
21322147 if ( this . opts . loopNum ) this . opts . loopNum ++ ;
21332148 else this . opts . loopNum = 1 ;
21342149 this . var_name = name ;
21352150 this . in_list = in_list ;
21362151 this . do_group = do_group ;
21372152 this . name = "for" ;
2138- this . parentCommand = parentCommand ;
2153+ // this.parentCom = parentCommand;
21392154} //»
21402155async init ( ) { //«
21412156 this . _init ( ) ;
@@ -2182,13 +2197,13 @@ async run(){//«
21822197} //»
21832198class FunctionCom extends CompoundCom { //«
21842199
2185- constructor ( shell , opts , name , com , parentCommand ) { //«
2186- super ( shell , opts ) ;
2200+ constructor ( shell , opts , name , com , parentCom ) { //«
2201+ super ( shell , opts , parentCom ) ;
21872202 this . name = name ;
21882203 this . com = com . compound_command . compound_list . term ;
21892204 this . type = com . type ;
21902205 this . redirs = com . redirs ;
2191- this . parentCommand = parentCommand ;
2206+ // this.parentCom = parentCommand;
21922207} //»
21932208async init ( ) { //«
21942209 this . _init ( ) ;
@@ -2197,15 +2212,15 @@ async init(){//«
21972212 const funcs = this . shell . term . funcs ;
21982213 let func ;
21992214 if ( typ === "brace_group" ) {
2200- func = ( shell , args , opts , com_env ) => {
2201- let com = new BraceGroupCom ( shell , opts , dup ( this . com ) ) ;
2215+ func = ( shell , args , opts , com_env , parentCommand ) => {
2216+ let com = new BraceGroupCom ( shell , opts , dup ( this . com ) , parentCommand ) ;
22022217 com . args = args ;
22032218 return com ;
22042219 }
22052220 }
22062221 else if ( typ === "subshell" ) {
2207- func = ( shell , args , opts , com_env ) => {
2208- let com = new SubshellCom ( shell , opts , dup ( this . com ) ) ;
2222+ func = ( shell , args , opts , com_env , parentCommand ) => {
2223+ let com = new SubshellCom ( shell , opts , dup ( this . com ) , parentCommand ) ;
22092224 com . args = args ;
22102225 return com ;
22112226 }
@@ -2223,12 +2238,12 @@ run(){//«
22232238
22242239} //»
22252240class CaseCom extends CompoundCom { //«
2226- constructor ( shell , opts , word , list , parentCommand ) { //«
2227- super ( shell , opts ) ;
2241+ constructor ( shell , opts , word , list , parentCom ) { //«
2242+ super ( shell , opts , parentCom ) ;
22282243this . word = word ;
22292244this . list = list ;
22302245this . name = "case" ;
2231- this . parentCommand = parentCommand ;
2246+ // this.parentCom = parentCommand;
22322247} //»
22332248async init ( ) { //«
22342249 this . _init ( ) ;
@@ -2773,7 +2788,7 @@ async run(){//«
27732788 const err = ( ...args ) => {
27742789 this . err ( ...args ) ;
27752790 } ;
2776- let is_term = this . isTermOut ( ) ;
2791+ let is_term = this . isTermOut ;
27772792 let nargs = args . length ;
27782793 let dir_was_last = false ;
27792794 let all = this . optAll ;
@@ -4068,12 +4083,14 @@ expand(shell, term, opts){
40684083 return shell . expandComsub ( this , opts ) ;
40694084}
40704085dup ( ) { //«
4086+ //log(this);
40714087 let bq = new BQuote ( this . start , this . par , this . env ) ;
40724088 let arr = bq . val ;
40734089 for ( let ent of this . val ) {
40744090 if ( isStr ( ent ) ) arr . push ( ent ) ;
40754091 else arr . push ( ent . dup ( ) ) ;
40764092 }
4093+ bq . raw = this . raw ; //WKLMUJK
40774094 return bq ;
40784095} //»
40794096toString ( ) {
@@ -4125,6 +4142,7 @@ async expand(shell, term, com_opts, opts={}){//«
41254142*/
41264143 let s ;
41274144//if (this.isPlain||this.isSubstitute||this.isStrRep) s = this.toString();
4145+
41284146if ( this . isSym ) { //«
41294147 s = this . val [ 0 ] ;
41304148 if ( s === "0" ) {
@@ -4337,6 +4355,7 @@ dup(){//«
43374355 if ( isStr ( ent ) ) arr . push ( ent ) ;
43384356 else arr . push ( ent . dup ( ) ) ;
43394357 }
4358+ com . raw = this . raw ; //JDPLUI
43404359 return com ;
43414360} //»
43424361toString ( ) {
@@ -5279,6 +5298,7 @@ this.throwUnexpectedToken("unexpected EOF reached");
52795298 else if ( ch === "$" && next1 && ( next1 . match ( / [ 1 - 9 ] / ) || SPECIAL_SYMBOLS . includes ( next1 ) ) ) { //«
52805299 let sub = new ParamSub ( this . index ) ;
52815300 sub . val = [ next1 ] ;
5301+ next1 . match ( / [ 1 - 9 ] / ) ? ( sub . isNum = true ) : ( sub . isSym = true ) ;
52825302 wordarr . push ( sub ) ;
52835303 this . index ++ ;
52845304 } //»
@@ -6676,6 +6696,7 @@ async expandComsub(tok, opts){//«
66766696 const err = ( mess ) => {
66776697 term . response ( mess , { isErr : true } ) ;
66786698 } ;
6699+ //XLMJHU [Fixed] NO tok.raw when the BQuote/ComSub is inside of a function
66796700 let arr = tok . raw . split ( "" ) ; //Should use the raw here!!!
66806701// let arr = tok.val;
66816702 let s = '' ;
@@ -7256,7 +7277,8 @@ makeCompoundCommand(com, opts, parentCommand){//«
72567277
72577278async makeCommand ( { assigns= [ ] , name, args= [ ] } , opts , parentCommand ) { //«
72587279 const { term} = this ;
7259- const { loopNum, scriptOut, stdin, stdinLns, outRedir, scriptArgs, scriptName, subLines, heredocScanner, env, isInteractive} = opts ;
7280+ // const {loopNum, scriptOut, stdin, stdinLns, outRedir, scriptArgs, scriptName, subLines, heredocScanner, env, isInteractive}=opts;
7281+ const { loopNum, scriptArgs, scriptName, heredocScanner, env, isInteractive} = opts ;
72607282 let comobj , usecomword ;
72617283 let rv
72627284 let use_env ;
@@ -7270,15 +7292,15 @@ async makeCommand({assigns=[], name, args=[]}, opts, parentCommand){//«
72707292 else use_env = env ;
72717293 const com_env = { //«
72727294 loopNum,
7273- stdin,
7274- stdinLns,
7275- outRedir,
7276- isSub : ! ! subLines ,
7277- scriptOut,
7295+ // stdin,
7296+ // stdinLns,
7297+ // outRedir,
7298+ // isSub: !!subLines,
72787299 term,
72797300 env : use_env ,
72807301 command_str : this . commandStr ,
72817302 shell : this ,
7303+ // scriptOut,
72827304 scriptArgs,
72837305 scriptName,
72847306 } //»
@@ -7355,7 +7377,7 @@ async makeCommand({assigns=[], name, args=[]}, opts, parentCommand){//«
73557377 let newopts = sdup ( opts ) ;
73567378 delete newopts . isInteractive ;
73577379 newopts . isFunc = true ;
7358- let func = term . funcs [ usecomword ] ( this , arr , newopts , com_env ) ;
7380+ let func = term . funcs [ usecomword ] ( this , arr , newopts , com_env , parentCommand ) ; //<--- SLKMDUY
73597381 func . isFunc = true ;
73607382 return func ;
73617383 } //»
@@ -7382,8 +7404,8 @@ async makeCommand({assigns=[], name, args=[]}, opts, parentCommand){//«
73827404 }
73837405 try { //«new Com
73847406 comobj = new com ( usecomword , arr , com_opts , com_env , parentCommand ) ;
7385- comobj . scriptOut = scriptOut ;
7386- comobj . subLines = subLines ;
7407+ // comobj.scriptOut = scriptOut;
7408+ // comobj.subLines = subLines;
73877409 return comobj ;
73887410 }
73897411 catch ( e ) {
@@ -7834,3 +7856,4 @@ if (!globals.shell_command_options) {
78347856
78357857}
78367858//»
7859+
0 commit comments