Compiler/Simple file inclusion pre processor: Difference between revisions

Content added Content deleted
(→‎{{header|Phix}}: marked incorrect, the penny has just dropped...)
Line 233: Line 233:
result
result
END # get string # ;
END # get string # ;
# gets a string denotation from the source without the quotes #
# returns s unquoted #
PROC get unquoted string = STRING:
PROC unquote string = ( STRING s )STRING:
BEGIN
BEGIN
STRING result := "";
STRING result := "";
# within a string denotation, "" denotes the " character #
# within a string denotation, "" denotes the " character #
WHILE have string delimiter DO
INT c pos := LWB s + 1;
WHILE next char;
WHILE cpos < UPB s DO
NOT at eof AND NOT have string delimiter
CHAR ch = s[ c pos ];
DO
IF ch = """" THEN
result +:= c
# have an embedded quote - it will be doubled #
OD;
c pos +:= 1
IF NOT have string delimiter THEN
# unterminated string #
unterminated( "string" )
FI;
FI;
next char;
result +:= ch;
IF have string delimiter THEN
c pos +:= 1
# embedded string delimiter #
result +:= c
FI
OD;
OD;
result
result
END # get unquoted string # ;
END # unquote string # ;
# gets a bold word from then source #
# gets a bold word from then source #
PROC get bold word = STRING:
PROC get bold word = STRING:
Line 297: Line 291:
IF at eof THEN
IF at eof THEN
# unterminated commant #
# unterminated commant #
unterminated( """" + delimiter + """ comment" )
unterminated( "'" + delimiter + "' comment" )
FI;
FI;
put string( delimiter )
put string( delimiter )
Line 318: Line 312:
IF have string delimiter THEN
IF have string delimiter THEN
# have a file name #
# have a file name #
file name := get unquoted string;
file name := get string;
pragment +:= file name + get whitespace
pragment +:= file name + get whitespace;
file name := unquote string( file name )
FI;
FI;
# should now have the closing delimiter #
# should now have the closing delimiter #
IF have bold THEN
IF NOT have bold THEN
# no bold word in/at-the-nd-of the pragment #
bold word := ""
ELSE
# have a bold word - could be the delimiter #
# have a bold word - could be the delimiter #
pragment +:= ( bold word := get bold word )
pragment +:= ( bold word := get bold word )
Line 332: Line 330:
# not a read/include pragmatic comment #
# not a read/include pragmatic comment #
put string( pragment );
put string( pragment );
WHILE bold word := skip to bold;
IF bold word /= delimiter THEN
NOT at eof
# haven't got the closing delimiter yet #
AND bold word /= delimiter
WHILE bold word := skip to bold;
DO SKIP OD;
NOT at eof
IF at eof THEN
AND bold word /= delimiter
# unterminated commant #
DO SKIP OD;
unterminated( """" + delimiter + """ pragmatic comment" )
IF at eof THEN
FI;
# unterminated commant #
put string( delimiter )
unterminated( """" + delimiter )
FI;
put string( delimiter )
FI
ELIF
ELIF
# attempt to include the file #
# attempt to include the file #