// Note, aCompiledProcs MUST be an array.
PP_RunInit( aCompiledProcs )
// Note the return value from PP_ExecProcedure() and no Procedure declaration in this 1st sample...
Alert( PP_ExecProcedure( ;
PP_CompileLine( ;
PP_PreProLine( "Private cVar := 'Hi there'; ? cVar; Return 'Returned from embedded script!'" ), ;
0, aCompiledProcs, NIL, @nProcId )[1] ) )
This commit is contained in:
@@ -1,3 +1,22 @@
|
||||
2001-05-28 19:10 UTC-0800 Ron Pinkas <ron@profit-master.com>
|
||||
* contrib/dot/pp.prg
|
||||
* Modified PP_PreProLine() to handle multi-line lines (;) as primary line.
|
||||
* Improved PP_RunInit() accept aProcedure as paramater. Now it can auto handle setup of RP_Run_Err() and reset aProcedures to {}
|
||||
+ Added loading of std.ch
|
||||
|
||||
* contrib/dot/prgscrpt.prg
|
||||
* Simplified samples, and added a simpler inline form sample.
|
||||
|
||||
/*
|
||||
PP_RunInit( aCompiledProcs )
|
||||
|
||||
// Note the return value from PP_ExecProcedure() and no Procedure declaration in this 1st. sample...
|
||||
Alert( PP_ExecProcedure( ;
|
||||
PP_CompileLine( ;
|
||||
PP_PreProLine( "Private cVar := 'Hi there'; ? cVar; Return 'Returned from embedded script!'" ), ;
|
||||
0, aCompiledProcs, NIL, @nProcId )[1] ) )
|
||||
*/
|
||||
|
||||
2001-05-28 14:50 UTC-0800 Ron Pinkas <ron@profit-master.com>
|
||||
* contrib/dot/pp.prg
|
||||
* Renamed PP_ProcessLine() to PP_PreProLine() and PP_ProcessFile() to PP_PreProFile() to allow 10 chars uniqueness.
|
||||
|
||||
@@ -160,8 +160,6 @@ STATIC aDefRules := {}, aDefResults := {}
|
||||
STATIC aTransRules := {}, aTransResults := {}
|
||||
STATIC aCommRules := {}, aCommResults := {}
|
||||
|
||||
STATIC nPendingLines := 0, aPendingLines := {}
|
||||
|
||||
STATIC bDbgMatch := .F., bDbgExp := .F., bDbgPPO := .F., bLoadRules := .T., ;
|
||||
bCount := .T., bCCH := .F., bCompile := .F.
|
||||
|
||||
@@ -436,7 +434,7 @@ RETURN s_xRet
|
||||
|
||||
//--------------------------------------------------------------//
|
||||
|
||||
PROCEDURE PP_ExecProcedure( aProc, sProcName )
|
||||
FUNCTION PP_ExecProcedure( aProc, sProcName )
|
||||
|
||||
LOCAL nBlock, nBlocks := Len( aProc[2] ), xErr
|
||||
LOCAL nVar, nVars
|
||||
@@ -555,7 +553,7 @@ PROCEDURE PP_ExecProcedure( aProc, sProcName )
|
||||
aSize( s_aProcStack[s_nProcStack], 2 )
|
||||
ENDIF
|
||||
|
||||
RETURN
|
||||
RETURN s_xRet
|
||||
|
||||
//--------------------------------------------------------------//
|
||||
|
||||
@@ -738,7 +736,7 @@ RETURN
|
||||
|
||||
//--------------------------------------------------------------//
|
||||
|
||||
PROCEDURE PP_CompileLine( sPPed, nLine, aProcedures, aInitExit, nProcId )
|
||||
FUNCTION PP_CompileLine( sPPed, nLine, aProcedures, aInitExit, nProcId )
|
||||
|
||||
LOCAL nNext, sBlock, sTemp
|
||||
LOCAL sSymbol
|
||||
@@ -812,6 +810,13 @@ PROCEDURE PP_CompileLine( sPPed, nLine, aProcedures, aInitExit, nProcId )
|
||||
sStep := "1"
|
||||
ENDIF
|
||||
|
||||
// No procedure declaration.
|
||||
IF nProcId == 0
|
||||
sSymbol := "Implied_Main"
|
||||
aSize( aProcedures, ++nProcId )
|
||||
aProcedures[nProcId] := { sSymbol, {} }
|
||||
ENDIF
|
||||
|
||||
aAdd( aProcedures[ nProcId ][2], { 0, &( "{||" + sCounter + ":=" + sStart + "}" ), nLine } ) // Loop back
|
||||
|
||||
sBlock := sCounter + "<=" + sEnd
|
||||
@@ -1068,6 +1073,13 @@ PROCEDURE PP_CompileLine( sPPed, nLine, aProcedures, aInitExit, nProcId )
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
// No procedure declaration.
|
||||
IF nProcId == 0
|
||||
sSymbol := "Implied_Main"
|
||||
aSize( aProcedures, ++nProcId )
|
||||
aProcedures[nProcId] := { sSymbol, {} }
|
||||
ENDIF
|
||||
|
||||
IF sBlock == ""
|
||||
aAdd( aProcedures[ nProcId ][2], { 0, NIL, nLine } )
|
||||
ELSE
|
||||
@@ -1130,6 +1142,13 @@ PROCEDURE PP_CompileLine( sPPed, nLine, aProcedures, aInitExit, nProcId )
|
||||
sStep := "1"
|
||||
ENDIF
|
||||
|
||||
// No procedure declaration.
|
||||
IF nProcId == 0
|
||||
sSymbol := "Implied_Main"
|
||||
aSize( aProcedures, ++nProcId )
|
||||
aProcedures[nProcId] := { sSymbol, {} }
|
||||
ENDIF
|
||||
|
||||
aAdd( aProcedures[ nProcId ][2], { 0, &( "{||" + sCounter + ":=" + sStart + "}" ), nLine } ) // Loop back
|
||||
|
||||
sBlock := sCounter + "<=" + sEnd
|
||||
@@ -1386,6 +1405,13 @@ PROCEDURE PP_CompileLine( sPPed, nLine, aProcedures, aInitExit, nProcId )
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
// No procedure declaration.
|
||||
IF nProcId == 0
|
||||
sSymbol := "Implied_Main"
|
||||
aSize( aProcedures, ++nProcId )
|
||||
aProcedures[nProcId] := { sSymbol, {} }
|
||||
ENDIF
|
||||
|
||||
IF sBlock == ""
|
||||
aAdd( aProcedures[ nProcId ][2], { 0, NIL, nLine } )
|
||||
ELSE
|
||||
@@ -1399,7 +1425,7 @@ PROCEDURE PP_CompileLine( sPPed, nLine, aProcedures, aInitExit, nProcId )
|
||||
|
||||
END SEQUENCE
|
||||
|
||||
RETURN
|
||||
RETURN aProcedures
|
||||
|
||||
//--------------------------------------------------------------//
|
||||
|
||||
@@ -2524,6 +2550,8 @@ RETURN .T.
|
||||
|
||||
FUNCTION PP_PreProLine( sLine, nLine, sSource )
|
||||
|
||||
LOCAL nPendingLines := 0, aPendingLines := {}
|
||||
|
||||
LOCAL sDirective, bX, sToken, nRule
|
||||
LOCAL nNewLineAt, nLines, Counter
|
||||
LOCAL sLeft, sPassed, asOutLines := {}, sOut := '', cChar
|
||||
@@ -2534,6 +2562,35 @@ FUNCTION PP_PreProLine( sLine, nLine, sSource )
|
||||
LOCAL sBackupLine
|
||||
LOCAL sSkipped
|
||||
|
||||
nPosition := 0
|
||||
WHILE ( nNewLineAt := nAtSkipStr( ';', sLine ) ) > 0
|
||||
nPendingLines++
|
||||
aSize( aPendingLines, nPendingLines )
|
||||
|
||||
nPosition++
|
||||
aIns( aPendingLines, nPosition )
|
||||
aPendingLines[ nPosition ] := Left( sLine, nNewLineAt - 1 )
|
||||
|
||||
//? "Pending #", nPendingLines, Left( sLine, nNewLineAt - 1 ), aPendingLines[nPendingLines]
|
||||
sLine := LTrim( SubStr( sLine, nNewLineAt + 1 ) )
|
||||
ENDDO
|
||||
|
||||
IF nPosition > 0
|
||||
IF ! Empty( sLine )
|
||||
nPendingLines++
|
||||
aSize( aPendingLines, nPendingLines )
|
||||
|
||||
nPosition++
|
||||
aIns( aPendingLines, nPosition )
|
||||
aPendingLines[ nPosition ] := sLine
|
||||
ENDIF
|
||||
|
||||
//? "Pending #", nPendingLines, sLine, aPendingLines[nPendingLines]
|
||||
sLine := aPendingLines[1]
|
||||
aDel( aPendingLines, 1 )
|
||||
nPendingLines--
|
||||
ENDIF
|
||||
|
||||
WHILE .T.
|
||||
//? "Processing: '" + sLine + "'"
|
||||
//? nPendingLines, nIfDef, IIF( nIfDef > 0, abIfDef[nIfDef] , )
|
||||
@@ -7424,7 +7481,7 @@ RETURN sIdentifier
|
||||
|
||||
FUNCTION nAtSkipStr( sFind, sLine )
|
||||
|
||||
LOCAL nAt, nLen := Len( sLine ), cChar, cLastChar, sTmp, nLenFind := Len( sFind )
|
||||
LOCAL nAt, nLen := Len( sLine ), cChar, cLastChar := ' ', sTmp, nLenFind := Len( sFind )
|
||||
|
||||
FOR nAt := 1 TO nLen
|
||||
IF SubStr( sLine, nAt, nLenFind ) == sFind
|
||||
@@ -7572,12 +7629,23 @@ STATIC FUNCTION InitRunResults()
|
||||
RETURN .T.
|
||||
|
||||
//--------------------------------------------------------------//
|
||||
PROCEDURE PP_RunInit()
|
||||
PROCEDURE PP_RunInit( aProcedures )
|
||||
|
||||
STATIC s_anRulesLen[6]
|
||||
|
||||
IF ValType( aProcedures ) != 'A'
|
||||
Alert( "Invalid parameter to: " + ProcName() + " must be Array!" )
|
||||
ELSE
|
||||
aSize( aProcedures, 0 )
|
||||
ErrorBlock( {|oErr| RP_Run_Err( oErr, aProcedures ) } )
|
||||
ENDIF
|
||||
|
||||
IF ! s_lRunLoaded
|
||||
s_lRunLoaded := .T.
|
||||
|
||||
InitRules()
|
||||
InitResults()
|
||||
|
||||
InitRunRules()
|
||||
InitRunResults()
|
||||
|
||||
|
||||
@@ -2,12 +2,21 @@ Procedure Main()
|
||||
|
||||
LOCAL aCompiledProcs := {}, nProcId := 0, sPPed
|
||||
|
||||
ErrorBlock( {|oErr| RP_Run_Err( oErr, aCompiledProcs ) } )
|
||||
// Note, aCompiledProcs MUST be an array.
|
||||
PP_RunInit( aCompiledProcs )
|
||||
|
||||
PP_RunInit()
|
||||
// Note the return value from PP_ExecProcedure() and no Procedure declaration in this 1st sample...
|
||||
Alert( PP_ExecProcedure( ;
|
||||
PP_CompileLine( ;
|
||||
PP_PreProLine( "Private cVar := 'Hi there'; ? cVar; Return 'Returned from embedded script!'" ), ;
|
||||
0, aCompiledProcs, NIL, @nProcId )[1] ) )
|
||||
|
||||
// OR:
|
||||
nProcId := 0
|
||||
PP_RunInit( aCompiledProcs )
|
||||
|
||||
sPPed := PP_PreProLine( "Proc Test" )
|
||||
PP_CompileLine( sPPed, 1, aCompiledProcs, NIL, @nProcId )
|
||||
PP_CompileLine( sPPed, 2, aCompiledProcs, NIL, @nProcId )
|
||||
|
||||
sPPed := PP_PreProLine( "Alert( 'Hello from embedded PP' )" )
|
||||
PP_CompileLine( sPPed, 2, aCompiledProcs, NIL, @nProcId )
|
||||
@@ -19,8 +28,8 @@ Procedure Main()
|
||||
|
||||
// OR :
|
||||
|
||||
PP_RunInit()
|
||||
aCompiledProcs := {}; nProcId := 0
|
||||
nProcId := 0
|
||||
PP_RunInit( aCompiledProcs )
|
||||
|
||||
sPPed := PP_PreProLine( "Proc EmbeddedMain" )
|
||||
sPPed += ";" + PP_PreProLine( "Alert( EmbeddedTest() )" )
|
||||
|
||||
Reference in New Issue
Block a user