diff --git a/src/ce_d2syn.pas b/src/ce_d2syn.pas index 870a70e2..a8190996 100644 --- a/src/ce_d2syn.pas +++ b/src/ce_d2syn.pas @@ -827,7 +827,7 @@ begin exit; end; - // symbols 1 + // symbols if isSymbol(reader^) then begin fTokKind := tkSymbl; @@ -856,31 +856,60 @@ begin if isOperator1(reader^) then begin fTokKind := tkSymbl; - while isOperator1(readerNext^) do (*!*); - case fTokStop - fTokStart of - 4:begin - if (not isOperator1(reader^)) and - isOperator4(fLineBuf[fTokStart..fTokStop-1]) - then exit; - end; - 3:begin - if (not isOperator1(reader^)) and - (isOperator3(fLineBuf[fTokStart..fTokStop-1]) or - (isOperator2(fLineBuf[fTokStart..fTokStop-2]) and - isPostOpSymbol(fLineBuf[fTokStop-1]))) - then exit; - end; - 2:begin - if (not isOperator1(reader^)) and - isOperator2(fLineBuf[fTokStart..fTokStop-1]) - then exit; - end; - 1:begin - if not isOperator1(reader^) then exit; - end; + while isOperator1(readerNext^) do + if fTokStop - fTokStart = 4 then break; + if (fTokStop - fTokStart = 4) then + begin + if isOperator4(fLineBuf[fTokStart..fTokStart+3]) then + exit; + if isOperator3(fLineBuf[fTokStart..fTokStart+2]) then + begin + readerPrev; + exit; + end; + if isOperator2(fLineBuf[fTokStart..fTokStart+1]) then + begin + readerPrev; + readerPrev; + exit; + end; + if isOperator1(fLineBuf[fTokStart]) then + begin + readerPrev; + readerPrev; + readerPrev; + exit; + end; end; + if (fTokStop - fTokStart = 3) then + begin + if isOperator3(fLineBuf[fTokStart..fTokStart+2]) then + exit; + if isOperator2(fLineBuf[fTokStart..fTokStart+1]) then + begin + readerPrev; + exit; + end; + if isOperator1(fLineBuf[fTokStart]) then + begin + readerPrev; + readerPrev; + exit; + end; + end; + if (fTokStop - fTokStart = 2) then + begin + if isOperator2(fLineBuf[fTokStart..fTokStart+1]) then + exit; + if isOperator1(fLineBuf[fTokStart]) then + begin + readerPrev; + exit; + end; + end; + if (fTokStop - fTokStart = 1) and isOperator1(fLineBuf[fTokStart]) then + exit; fTokKind := tkError; - //if isWhite(reader^) then exit; end; diff --git a/src/ce_dlang.pas b/src/ce_dlang.pas index afb69175..16255bbf 100644 --- a/src/ce_dlang.pas +++ b/src/ce_dlang.pas @@ -739,52 +739,98 @@ begin if isOutOfBound then exit; identifier += reader.head^; + if length(identifier) = 4 then + break; end; - case length(identifier) of - 4: + if length(identifier) = 4 then + begin + if isOperator4(identifier) then begin - if (not isOperator1(reader.head^)) and - isOperator4(identifier) then - begin - addToken(ltkOperator); - if callBackDoStop then - exit; - continue; - end; + addToken(ltkOperator); + if callBackDoStop then + exit; + continue; end; - 3: + if isOperator3(identifier[1..length(identifier)-1]) then begin - if (not isOperator1(reader.head^)) and - isOperator3(identifier) then - begin - addToken(ltkOperator); - if callBackDoStop then - exit; - continue; - end; + reader.previous; + addToken(ltkOperator); + if callBackDoStop then + exit; + continue; end; - 2: + if isOperator2(identifier[1..length(identifier)-2]) then begin - if (not isOperator1(reader.head^)) and - isOperator2(identifier) then - begin - addToken(ltkOperator); - if callBackDoStop then - exit; - continue; - end; + reader.previous; + reader.previous; + addToken(ltkOperator); + if callBackDoStop then + exit; + continue; end; - 1: + if isOperator1(identifier[1]) then begin - if not isOperator1(reader.head^) then - begin - addToken(ltkOperator); - if callBackDoStop then - exit; - continue; - end; + reader.previous; + reader.previous; + reader.previous; + addToken(ltkOperator); + if callBackDoStop then + exit; + continue; end; end; + if length(identifier) = 3 then + begin + if isOperator3(identifier) then + begin + addToken(ltkOperator); + if callBackDoStop then + exit; + continue; + end; + if isOperator2(identifier[1..length(identifier)-1]) then + begin + reader.previous; + addToken(ltkOperator); + if callBackDoStop then + exit; + continue; + end; + if isOperator1(identifier[1]) then + begin + reader.previous; + reader.previous; + addToken(ltkOperator); + if callBackDoStop then + exit; + continue; + end; + end; + if length(identifier) = 2 then + begin + if isOperator2(identifier) then + begin + addToken(ltkOperator); + if callBackDoStop then + exit; + continue; + end; + if isOperator1(identifier[1]) then + begin + reader.previous; + addToken(ltkOperator); + if callBackDoStop then + exit; + continue; + end; + end; + if (length(identifier) = 1) and isOperator1(identifier[1]) then + begin + addToken(ltkOperator); + if callBackDoStop then + exit; + continue; + end; end; // identifier accum @@ -807,7 +853,9 @@ begin end; // error + {$IFDEF DEBUG} identifier += ' (unrecognized lexer input)'; + {$ENDIF} addToken(ltkIllegal); end; diff --git a/src/ce_dlangutils.pas b/src/ce_dlangutils.pas index a79fbcb4..9c191e87 100644 --- a/src/ce_dlangutils.pas +++ b/src/ce_dlangutils.pas @@ -26,8 +26,6 @@ function isBit(const c: Char): boolean; {$IFNDEF DEBUG}inline;{$ENDIF} function isAlNum(const c: Char): boolean; {$IFNDEF DEBUG}inline;{$ENDIF} function isHex(const c: Char): boolean; {$IFNDEF DEBUG}inline;{$ENDIF} function isSymbol(const c: char): boolean; {$IFNDEF DEBUG}inline;{$ENDIF} -function isPtrOperator(const c: char): boolean; {$IFNDEF DEBUG}inline;{$ENDIF} -function isPostOpSymbol(const c: char): boolean; {$IFNDEF DEBUG} inline; {$ENDIF} function isOperator1(const c: char): boolean; {$IFNDEF DEBUG}inline;{$ENDIF} function isOperator2(const s: string): boolean; {$IFNDEF DEBUG}inline;{$ENDIF} function isOperator3(const s: string): boolean; {$IFNDEF DEBUG} inline; {$ENDIF} @@ -97,16 +95,6 @@ begin exit(c in [';', '{', '}', '(', ')', '[', ']', ',', '.', ':' , '"', #39, '?', '$', #35]); end; -function isPtrOperator(const c: char): boolean; {$IFNDEF DEBUG}inline;{$ENDIF} -begin - exit(c in ['&', '*']); -end; - -function isPostOpSymbol (const c: char): boolean; {$IFNDEF DEBUG}inline;{$ENDIF} -begin - exit(c in ['+', '-', '*', '&']); -end; - function isOperator1(const c: char): boolean; {$IFNDEF DEBUG}inline;{$ENDIF} begin exit(c in ['/', '*', '-', '+', '%', '>', '<', '=', '!', '&', '|', '^', '~']);