Skip to content

Commit

Permalink
#295 Fix asm style extending past end.
Browse files Browse the repository at this point in the history
 Add test files for Pascal from HoTschir.
  • Loading branch information
zufuliu authored and nyamatongwe committed Dec 20, 2024
1 parent 8846098 commit 870a8ca
Show file tree
Hide file tree
Showing 12 changed files with 650 additions and 6 deletions.
13 changes: 13 additions & 0 deletions doc/LexillaHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,22 @@ <h2>Contributors</h2>
</tr><tr>
<td>Henrik S. Johansen</td>
<td>Ekopalypse</td>
<td>HoTschir</td>
</tr>
</table>
<h2>Releases</h2>
<h3>
<a href="https://www.scintilla.org/lexilla543.zip">Release 5.4.3</a>
</h3>
<ul>
<li>
Released 18 December 2024.
</li>
<li>
Pascal: Fix asm style extending past end.
<a href="https://github.com/ScintillaOrg/lexilla/issues/295">Issue #295</a>.
</li>
</ul>
<h3>
<a href="https://www.scintilla.org/lexilla542.zip">Release 5.4.2</a>
</h3>
Expand Down
11 changes: 5 additions & 6 deletions lexers/LexPascal.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,6 @@ static void ColourisePascalDoc(Sci_PositionU startPos, Sci_Position length, int
StyleContext sc(startPos, length, initStyle, styler);

for (; sc.More(); sc.Forward()) {
if (sc.atLineEnd) {
// Update the line state, so it can be seen by next line
curLine = styler.GetLine(sc.currentPos);
styler.SetLineState(curLine, curLineState);
}

// Determine if the current state should terminate.
switch (sc.state) {
case SCE_PAS_NUMBER:
Expand Down Expand Up @@ -335,6 +329,11 @@ static void ColourisePascalDoc(Sci_PositionU startPos, Sci_Position length, int
sc.SetState(SCE_PAS_ASM);
}
}

if (sc.atLineEnd) {
// Update the line state, so it can be seen by next line
styler.SetLineState(sc.currentLine, curLineState);
}
}

if (sc.state == SCE_PAS_IDENTIFIER && setWord.Contains(sc.chPrev)) {
Expand Down
82 changes: 82 additions & 0 deletions test/examples/pascal/AllStyles.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Enumerate all primary styles: 0 to 14

{
SCE_PAS_DEFAULT=0
SCE_PAS_IDENTIFIER=1
SCE_PAS_COMMENT=2
SCE_PAS_COMMENT2=3
SCE_PAS_COMMENTLINE=4
SCE_PAS_PREPROCESSOR=5
SCE_PAS_PREPROCESSOR2=6
SCE_PAS_NUMBER=7
SCE_PAS_HEXNUMBER=8
SCE_PAS_WORD=9
SCE_PAS_STRING=10
SCE_PAS_STRINGEOL=11
SCE_PAS_CHARACTER=12
SCE_PAS_OPERATOR=13
SCE_PAS_ASM=14
}

// default=0

// identifier=1
function functionname(var paramerter1: type1):result1;
procedure procedurename(const parameter2: type2);

// comment=2
{comment text}

// comment2=3
(* comment text *)

// commentline=4
// example line

// preprocessor=5
{$DEFINE xyz}

{$IFDEF xyz}
codeblock 1
{$else}
codeblock 2
{$endif}

// preprocessor2=6
(*$DEFINE xyz*)

// number=7
123
1.23
-123
-12.3
+123
123
1.23e2
-1.23E2

// hexnumber=8
$123
$123ABCDEF
$ABCDEF123

// word=9
absolute abstract and array as

// string=10
'string'

// stringeol=11
'string
// character=12
#65
// operator=13
$ & * + / < = > ^
// asm
asm
this is
inside assembler
end
83 changes: 83 additions & 0 deletions test/examples/pascal/AllStyles.pas.folded
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
0 400 0 // Enumerate all primary styles: 0 to 14
1 400 0
2 400 0 + {
0 401 0 | SCE_PAS_DEFAULT=0
0 401 0 | SCE_PAS_IDENTIFIER=1
0 401 0 | SCE_PAS_COMMENT=2
0 401 0 | SCE_PAS_COMMENT2=3
0 401 0 | SCE_PAS_COMMENTLINE=4
0 401 0 | SCE_PAS_PREPROCESSOR=5
0 401 0 | SCE_PAS_PREPROCESSOR2=6
0 401 0 | SCE_PAS_NUMBER=7
0 401 0 | SCE_PAS_HEXNUMBER=8
0 401 0 | SCE_PAS_WORD=9
0 401 0 | SCE_PAS_STRING=10
0 401 0 | SCE_PAS_STRINGEOL=11
0 401 0 | SCE_PAS_CHARACTER=12
0 401 0 | SCE_PAS_OPERATOR=13
0 401 0 | SCE_PAS_ASM=14
0 401 0 | }
1 400 0
0 400 0 // default=0
1 400 0
0 400 0 // identifier=1
0 400 0 function functionname(var paramerter1: type1):result1;
0 400 0 procedure procedurename(const parameter2: type2);
1 400 0
0 400 0 // comment=2
0 400 0 {comment text}
1 400 0
0 400 0 // comment2=3
0 400 0 (* comment text *)
1 400 0
2 400 0 + // commentline=4
0 401 0 | // example line
1 400 0
0 400 0 // preprocessor=5
0 400 0 {$DEFINE xyz}
1 400 0
2 400 0 + {$IFDEF xyz}
0 401 0 | codeblock 1
0 401 0 | {$else}
0 401 0 | codeblock 2
0 401 0 | {$endif}
1 400 0
0 400 0 // preprocessor2=6
0 400 0 (*$DEFINE xyz*)
1 400 0
0 400 0 // number=7
0 400 0 123
0 400 0 1.23
0 400 0 -123
0 400 0 -12.3
0 400 0 +123
0 400 0 123
0 400 0 1.23e2
0 400 0 -1.23E2
1 400 0
0 400 0 // hexnumber=8
0 400 0 $123
0 400 0 $123ABCDEF
0 400 0 $ABCDEF123
1 400 0
0 400 0 // word=9
0 400 0 absolute abstract and array as
1 400 0
0 400 0 // string=10
0 400 0 'string'
1 400 0
0 400 0 // stringeol=11
0 400 0 'string
1 400 0
0 400 0 // character=12
0 400 0 #65
1 400 0
0 400 0 // operator=13
0 400 0 $ & * + / < = > ^
1 400 0
0 400 0 // asm
2 400 0 + asm
0 401 0 | this is
0 401 0 | inside assembler
0 401 0 | end
1 400 0
82 changes: 82 additions & 0 deletions test/examples/pascal/AllStyles.pas.styled
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{4}// Enumerate all primary styles: 0 to 14
{0}
{2}{
SCE_PAS_DEFAULT=0
SCE_PAS_IDENTIFIER=1
SCE_PAS_COMMENT=2
SCE_PAS_COMMENT2=3
SCE_PAS_COMMENTLINE=4
SCE_PAS_PREPROCESSOR=5
SCE_PAS_PREPROCESSOR2=6
SCE_PAS_NUMBER=7
SCE_PAS_HEXNUMBER=8
SCE_PAS_WORD=9
SCE_PAS_STRING=10
SCE_PAS_STRINGEOL=11
SCE_PAS_CHARACTER=12
SCE_PAS_OPERATOR=13
SCE_PAS_ASM=14
}{0}

{4}// default=0
{0}
{4}// identifier=1
{9}function{0} {1}functionname{13}({9}var{0} {1}paramerter1{13}:{0} {1}type1{13}):{1}result1{13};{0}
{9}procedure{0} {1}procedurename{13}({9}const{0} {1}parameter2{13}:{0} {1}type2{13});{0}

{4}// comment=2
{2}{comment text}{0}

{4}// comment2=3
{3}(* comment text *){0}

{4}// commentline=4
// example line
{0}
{4}// preprocessor=5
{5}{$DEFINE xyz}{0}

{5}{$IFDEF xyz}{0}
{1}codeblock{0} {7}1{0}
{5}{$else}{0}
{1}codeblock{0} {7}2{0}
{5}{$endif}{0}

{4}// preprocessor2=6
{6}(*$DEFINE xyz*){0}

{4}// number=7
{7}123{0}
{7}1.23{0}
{13}-{7}123{0}
{13}-{7}12.3{0}
{13}+{7}123{0}
{7}123{0}
{7}1.23e2{0}
{13}-{7}1.23E2{0}

{4}// hexnumber=8
{8}$123{0}
{8}$123ABCDEF{0}
{8}$ABCDEF123{0}

{4}// word=9
{9}absolute{0} {9}abstract{0} {9}and{0} {9}array{0} {9}as{0}

{4}// string=10
{10}'string'{0}

{4}// stringeol=11
{11}'string
{0}
{4}// character=12
{12}#65{0}

{4}// operator=13
{8}${0} {13}&{0} {13}*{0} {13}+{0} {13}/{0} {13}<{0} {13}={0} {13}>{0} {13}^{0}

{4}// asm
{9}asm{14}
this is
inside assembler
{9}end{0}
80 changes: 80 additions & 0 deletions test/examples/pascal/CodeFolding.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// tests for code folding

// multi line comments
{
line1
line2
}

// begin .. end
begin
some commands
end;

record test
var1: type1;
var2: type2;
end; //record

//asm
asm
some statement
end; //asm

//try (from https://wiki.freepascal.org/Try)
try
// code that might generate an exception
except
// will only be executed in case of an exception
on E: EDatabaseError do
ShowMessage( 'Database error: '+ E.ClassName + #13#10 + E.Message );
on E: Exception do
ShowMessage( 'Error: '+ E.ClassName + #13#10 + E.Message );
end;

//try nested (from https://wiki.freepascal.org/Try)
try
try
// code dealing with database that might generate an exception
except
// will only be executed in case of an exception
on E: EDatabaseError do
ShowMessage( 'Database error: '+ E.ClassName + #13#10 + E.Message );
on E: Exception do
ShowMessage( 'Error: '+ E.ClassName + #13#10 + E.Message );
end;
finally
// clean up database-related resources
end;

//case
case x of
1: do something;
2: do some other thing;
else
do default;
end; //case

//if then else
if x=y then
do something;
else
do some other thing;

//for loop
for i:=1 to 10 do
writeln(i)

//do until
repeat
write(a);
i:=i+1;
until i>10;

//preprocessor if, else, endif
{$DEFINE label}
{$IFDEF label}
command 1
{$ELSE}
command 2
{$ENDIF}
Loading

0 comments on commit 870a8ca

Please sign in to comment.