Skip to content

Commit 945df0e

Browse files
authored
Merge pull request #107 from jayrm/comments
Allow suffixes in comments
2 parents df595db + c2f54a9 commit 945df0e

File tree

6 files changed

+47
-24
lines changed

6 files changed

+47
-24
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Version 1.06.0
7878
- Fix for debugging lines in include files but not in procedures. Filename debugging information added for module level statements in included files.
7979
- #699: fix new[0] causing infinite loop when calling constructor/destructor list
8080
- #883: when mapping 32 & 64 bit functions for PALETTE [GET] USING, check the data type pointed to and choose one of LONG PTR, LONGINT PTR, INTEGER PTR
81+
- #866: fbc was throwing lexer errors in comments stating with $. Comments are lexed for directives; allow suffixes in comments
8182

8283

8384
Version 1.05.0

src/compiler/lex.bas

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,12 @@ private sub hReadIdentifier _
386386
byval flags as LEXCHECK _
387387
)
388388

389+
#macro hCheckIdentifierSuffix()
390+
if( (fbLangOptIsSet( FB_LANG_OPT_SUFFIX ) = FALSE) and ((flags and LEXCHECK_ALLOWSUFFIX) = 0) ) then
391+
errReportNotAllowed(FB_LANG_QB, FB_ERRMSG_SUFFIXONLYVALIDINLANG, "")
392+
end if
393+
#endmacro
394+
389395
dim as integer skipchar = any
390396

391397
'' (ALPHA | '_' )
@@ -442,39 +448,38 @@ private sub hReadIdentifier _
442448

443449
'' [SUFFIX]
444450
dtype = FB_DATATYPE_INVALID
445-
446451
if( (flags and LEXCHECK_NOSUFFIX) = 0 ) then
447452
select case as const lexCurrentChar( )
448453
'' '%'?
449454
case FB_TK_INTTYPECHAR
450-
if( fbLangOptIsSet( FB_LANG_OPT_SUFFIX ) = FALSE ) then errReportNotAllowed(FB_LANG_QB, FB_ERRMSG_SUFFIXONLYVALIDINLANG, "")
455+
hCheckIdentifierSuffix()
451456
dtype = env.lang.integerkeyworddtype
452457
lexEatChar( )
453458

454459
'' '&'?
455460
case FB_TK_LNGTYPECHAR
456-
if( fbLangOptIsSet( FB_LANG_OPT_SUFFIX ) = FALSE ) then errReportNotAllowed(FB_LANG_QB, FB_ERRMSG_SUFFIXONLYVALIDINLANG, "")
461+
hCheckIdentifierSuffix()
457462
dtype = FB_DATATYPE_LONG
458463
lexEatChar( )
459464

460465
'' '!'?
461466
case FB_TK_SGNTYPECHAR
462-
if( fbLangOptIsSet( FB_LANG_OPT_SUFFIX ) = FALSE ) then errReportNotAllowed(FB_LANG_QB, FB_ERRMSG_SUFFIXONLYVALIDINLANG, "")
467+
hCheckIdentifierSuffix()
463468
dtype = FB_DATATYPE_SINGLE
464469
lexEatChar( )
465470

466471
'' '#'?
467472
case FB_TK_DBLTYPECHAR
468473
'' isn't it a '##'?
469474
if( lexGetLookAheadChar( ) <> FB_TK_DBLTYPECHAR ) then
470-
if( fbLangOptIsSet( FB_LANG_OPT_SUFFIX ) = FALSE ) then errReportNotAllowed(FB_LANG_QB, FB_ERRMSG_SUFFIXONLYVALIDINLANG, "")
475+
hCheckIdentifierSuffix()
471476
dtype = FB_DATATYPE_DOUBLE
472477
lexEatChar( )
473478
end if
474479

475480
'' '$'?
476481
case FB_TK_STRTYPECHAR
477-
if( fbLangOptIsSet( FB_LANG_OPT_SUFFIX ) = FALSE ) then errReportNotAllowed(FB_LANG_QB, FB_ERRMSG_SUFFIXONLYVALIDINLANG, "")
482+
hCheckIdentifierSuffix()
478483
dtype = FB_DATATYPE_STRING
479484
lexEatChar( )
480485
end select
@@ -1843,10 +1848,9 @@ read_char:
18431848
'' '/'?
18441849
case CHAR_SLASH
18451850
t->class = FB_TKCLASS_OPERATOR
1846-
'' in lang fb, only check for multiline comment if not inside
1851+
'' only check for multiline comment if not inside
18471852
'' a single line comment already (thanks to VonGodric for help)
1848-
if( (flags and LEXCHECK_NOMULTILINECOMMENT) = 0 or _
1849-
fbLangIsSet( FB_LANG_FB ) = FALSE ) then
1853+
if( (flags and LEXCHECK_NOMULTILINECOMMENT) = 0 ) then
18501854
'' "/'"?
18511855
if( lexCurrentChar( ) = CHAR_APOST ) then
18521856
'' multi-line comment..

src/compiler/lex.bi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ enum LEXCHECK
4040

4141
'' don't interpret f, u, l as type-specifier suffixes on numeric literals (used in asm blocks)
4242
LEXCHECK_NOLETTERSUFFIX = &h0400
43+
44+
'' allow suffix, like when reading potential directives from comments, even though the dialect prohibits suffixes
45+
LEXCHECK_ALLOWSUFFIX = &h0800
4346

4447
end enum
4548

src/compiler/parser-comment.bas

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ function cComment _
2727
'' to the lexSkipToken() calls for '$' and from cDirective(),
2828
'' when parsing a $ meta command)
2929
lex.ctx->reclevel += 1
30-
lexSkipToken( LEX_FLAGS )
31-
30+
lexSkipToken( LEX_FLAGS or LEXCHECK_ALLOWSUFFIX )
3231
if( lexGetToken( LEX_FLAGS ) = FB_TK_DIRECTIVECHAR ) then
33-
lexSkipToken( LEX_FLAGS )
32+
lexSkipToken( LEX_FLAGS or LEXCHECK_ALLOWSUFFIX )
3433
cDirective( )
3534
else
3635
lexSkipLine( )
@@ -171,7 +170,6 @@ private sub cDirective( ) static
171170
case FB_TK_EOL, FB_TK_EOF
172171
exit do
173172
end select
174-
175-
lexSkipToken( )
173+
lexSkipToken( LEX_FLAGS or LEXCHECK_ALLOWSUFFIX )
176174
loop
177175
end sub

tests/comments/multiline.bas

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,24 @@ end sub
4949

5050
proc
5151

52+
/'
53+
54+
multiline comments never check for '$' directives,
55+
so suffixes should never matter
56+
57+
${f!
58+
$=f#
59+
$^f$
60+
$-f%
61+
$@f&
62+
63+
'${f!
64+
'$=f#
65+
'$^f$
66+
'$-f%
67+
'$@f&
68+
69+
$include 'does_not_matter'
70+
$include "does_not_matter"
71+
72+
'/

tests/comments/singleline.bas

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,20 @@ rem comment _
2727
#error X1 should be defined
2828
#endif
2929

30-
#if ENABLE_CHECK_BUGS
31-
32-
#print enable check for #866 fbc throws lexer errors in comments stating with $
33-
#print see bug #866 at https://sourceforge.net/p/fbc/bugs/866/
34-
#print introduced by #832 QB type suffixes allowed on any keywords
35-
#print see bug #832 at https://sourceforge.net/p/fbc/bugs/832/
36-
37-
3830
'$=f#
3931
'$=f#
4032
'$=f#
4133
'$=f#
4234
'$=f#
4335

36+
''$=f#
37+
''$=f#
38+
''$=f#
39+
''$=f#
40+
''$=f#
41+
4442
rem ${f!
4543
rem $=f#
4644
rem $^f$
4745
rem $-f%
4846
rem $@f&
49-
50-
#endif

0 commit comments

Comments
 (0)