mirror of https://gitlab.com/basile.b/dexed.git
fix, valid operator combinations could be detected as invalid
This commit is contained in:
parent
c74f6af73f
commit
487241064c
|
|
@ -827,7 +827,7 @@ begin
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// symbols 1
|
// symbols
|
||||||
if isSymbol(reader^) then
|
if isSymbol(reader^) then
|
||||||
begin
|
begin
|
||||||
fTokKind := tkSymbl;
|
fTokKind := tkSymbl;
|
||||||
|
|
@ -856,31 +856,60 @@ begin
|
||||||
if isOperator1(reader^) then
|
if isOperator1(reader^) then
|
||||||
begin
|
begin
|
||||||
fTokKind := tkSymbl;
|
fTokKind := tkSymbl;
|
||||||
while isOperator1(readerNext^) do (*!*);
|
while isOperator1(readerNext^) do
|
||||||
case fTokStop - fTokStart of
|
if fTokStop - fTokStart = 4 then break;
|
||||||
4:begin
|
if (fTokStop - fTokStart = 4) then
|
||||||
if (not isOperator1(reader^)) and
|
begin
|
||||||
isOperator4(fLineBuf[fTokStart..fTokStop-1])
|
if isOperator4(fLineBuf[fTokStart..fTokStart+3]) then
|
||||||
then exit;
|
exit;
|
||||||
end;
|
if isOperator3(fLineBuf[fTokStart..fTokStart+2]) then
|
||||||
3:begin
|
begin
|
||||||
if (not isOperator1(reader^)) and
|
readerPrev;
|
||||||
(isOperator3(fLineBuf[fTokStart..fTokStop-1]) or
|
exit;
|
||||||
(isOperator2(fLineBuf[fTokStart..fTokStop-2]) and
|
end;
|
||||||
isPostOpSymbol(fLineBuf[fTokStop-1])))
|
if isOperator2(fLineBuf[fTokStart..fTokStart+1]) then
|
||||||
then exit;
|
begin
|
||||||
end;
|
readerPrev;
|
||||||
2:begin
|
readerPrev;
|
||||||
if (not isOperator1(reader^)) and
|
exit;
|
||||||
isOperator2(fLineBuf[fTokStart..fTokStop-1])
|
end;
|
||||||
then exit;
|
if isOperator1(fLineBuf[fTokStart]) then
|
||||||
end;
|
begin
|
||||||
1:begin
|
readerPrev;
|
||||||
if not isOperator1(reader^) then exit;
|
readerPrev;
|
||||||
end;
|
readerPrev;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
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;
|
fTokKind := tkError;
|
||||||
//if isWhite(reader^) then
|
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
|
||||||
120
src/ce_dlang.pas
120
src/ce_dlang.pas
|
|
@ -739,52 +739,98 @@ begin
|
||||||
if isOutOfBound then
|
if isOutOfBound then
|
||||||
exit;
|
exit;
|
||||||
identifier += reader.head^;
|
identifier += reader.head^;
|
||||||
|
if length(identifier) = 4 then
|
||||||
|
break;
|
||||||
end;
|
end;
|
||||||
case length(identifier) of
|
if length(identifier) = 4 then
|
||||||
4:
|
begin
|
||||||
|
if isOperator4(identifier) then
|
||||||
begin
|
begin
|
||||||
if (not isOperator1(reader.head^)) and
|
addToken(ltkOperator);
|
||||||
isOperator4(identifier) then
|
if callBackDoStop then
|
||||||
begin
|
exit;
|
||||||
addToken(ltkOperator);
|
continue;
|
||||||
if callBackDoStop then
|
|
||||||
exit;
|
|
||||||
continue;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
3:
|
if isOperator3(identifier[1..length(identifier)-1]) then
|
||||||
begin
|
begin
|
||||||
if (not isOperator1(reader.head^)) and
|
reader.previous;
|
||||||
isOperator3(identifier) then
|
addToken(ltkOperator);
|
||||||
begin
|
if callBackDoStop then
|
||||||
addToken(ltkOperator);
|
exit;
|
||||||
if callBackDoStop then
|
continue;
|
||||||
exit;
|
|
||||||
continue;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
2:
|
if isOperator2(identifier[1..length(identifier)-2]) then
|
||||||
begin
|
begin
|
||||||
if (not isOperator1(reader.head^)) and
|
reader.previous;
|
||||||
isOperator2(identifier) then
|
reader.previous;
|
||||||
begin
|
addToken(ltkOperator);
|
||||||
addToken(ltkOperator);
|
if callBackDoStop then
|
||||||
if callBackDoStop then
|
exit;
|
||||||
exit;
|
continue;
|
||||||
continue;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
1:
|
if isOperator1(identifier[1]) then
|
||||||
begin
|
begin
|
||||||
if not isOperator1(reader.head^) then
|
reader.previous;
|
||||||
begin
|
reader.previous;
|
||||||
addToken(ltkOperator);
|
reader.previous;
|
||||||
if callBackDoStop then
|
addToken(ltkOperator);
|
||||||
exit;
|
if callBackDoStop then
|
||||||
continue;
|
exit;
|
||||||
end;
|
continue;
|
||||||
end;
|
end;
|
||||||
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;
|
end;
|
||||||
|
|
||||||
// identifier accum
|
// identifier accum
|
||||||
|
|
@ -807,7 +853,9 @@ begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// error
|
// error
|
||||||
|
{$IFDEF DEBUG}
|
||||||
identifier += ' (unrecognized lexer input)';
|
identifier += ' (unrecognized lexer input)';
|
||||||
|
{$ENDIF}
|
||||||
addToken(ltkIllegal);
|
addToken(ltkIllegal);
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
|
||||||
|
|
@ -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 isAlNum(const c: Char): boolean; {$IFNDEF DEBUG}inline;{$ENDIF}
|
||||||
function isHex(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 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 isOperator1(const c: char): boolean; {$IFNDEF DEBUG}inline;{$ENDIF}
|
||||||
function isOperator2(const s: string): 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}
|
function isOperator3(const s: string): boolean; {$IFNDEF DEBUG} inline; {$ENDIF}
|
||||||
|
|
@ -97,16 +95,6 @@ begin
|
||||||
exit(c in [';', '{', '}', '(', ')', '[', ']', ',', '.', ':' , '"', #39, '?', '$', #35]);
|
exit(c in [';', '{', '}', '(', ')', '[', ']', ',', '.', ':' , '"', #39, '?', '$', #35]);
|
||||||
end;
|
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}
|
function isOperator1(const c: char): boolean; {$IFNDEF DEBUG}inline;{$ENDIF}
|
||||||
begin
|
begin
|
||||||
exit(c in ['/', '*', '-', '+', '%', '>', '<', '=', '!', '&', '|', '^', '~']);
|
exit(c in ['/', '*', '-', '+', '%', '>', '<', '=', '!', '&', '|', '^', '~']);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue