From e632c8dbaad5d4405c7fb46bbd9c80c91a6c5ac2 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Tue, 19 Sep 2017 07:24:27 +0300 Subject: [PATCH] pascal `{}` comment support in parser --- src/shared/xparser.pas | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/shared/xparser.pas b/src/shared/xparser.pas index b704c4b..6ecf7f0 100644 --- a/src/shared/xparser.pas +++ b/src/shared/xparser.pas @@ -14,6 +14,7 @@ * along with this program. If not, see . *) {$INCLUDE a_modes.inc} +{.$DEFINE XPARSER_DEBUG} unit xparser; interface @@ -51,7 +52,8 @@ type TOption = ( SignedNumbers, // allow signed numbers; otherwise sign will be TTDelim DollarIsId, // allow dollar in identifiers; otherwise dollar will be TTDelim - DotIsId // allow dot in identifiers; otherwise dot will be TTDelim + DotIsId, // allow dot in identifiers; otherwise dot will be TTDelim + PascalComments // allow `{}` pascal comments ); TOptions = set of TOption; @@ -86,7 +88,9 @@ type function skipBlanks (): Boolean; // ...and comments; returns `false` on eof function skipToken (): Boolean; // returns `false` on eof - //function skipToken1 (): Boolean; + {$IFDEF XPARSER_DEBUG} + function skipToken1 (): Boolean; + {$ENDIF} function expectId (): AnsiString; procedure expectId (const aid: AnsiString); @@ -368,6 +372,22 @@ begin skipChar(); end; continue; + end + else if (curChar = '{') and (TOption.PascalComments in mOptions) then + begin + // pascal comment; skip comment start + skipChar(); + while not isEOF do + begin + if (curChar = '}') then + begin + // skip comment end + skipChar(); + break; + end; + skipChar(); + end; + continue; end; if (curChar > ' ') then break; skipChar(); // skip blank @@ -376,18 +396,18 @@ begin end; -{ +{$IFDEF XPARSER_DEBUG} function TTextParser.skipToken (): Boolean; begin writeln('getting token...'); result := skipToken1(); writeln(' got token: ', mTokType, ' <', mTokStr, '> : <', mTokChar, '>'); end; -} - +function TTextParser.skipToken1 (): Boolean; +{$ELSE} function TTextParser.skipToken (): Boolean; - +{$ENDIF} procedure parseInt (); var neg: Boolean = false; -- 2.29.2