Skip to content

Conversation

@jayrm
Copy link
Member

@jayrm jayrm commented May 16, 2021

This change builds on PR #309 to also allow single '_' character token pasting.

  • previously fbc unable to handle single '_' token pasting since in such cases the '_' is always seen as line continuation.
    Example:
#define join1(a,b) a##_ b
#define join2(a,b) a _##b
#define join3(a,b) a##_##b

skyfish4tb and others added 4 commits May 16, 2021 00:18
…he dynamic addition of a line continuation character ("_"), Causes the compiler to delay parsing the line continuation.This allows multiple lines of code in the input file to be combined into a single statement. For example:

Type _MAP_ENTRY
	id As integer
	pA As integer
End Type
#macro BEGIN_ENTRIESMAP()
	Function _GetMapEntries() As _MAP_ENTRY Ptr
		Static As _MAP_ENTRY _entries(0 To ...) = { ##_
#endmacro
#macro END_ENTRIESMAP()
		(0, 0)}
		Return @_entries(0)
	End Function
#endmacro
#define _INTERFACE_ENTRY(x, y) (x, y), ##_

BEGIN_ENTRIESMAP()
	_INTERFACE_ENTRY(1, 2)
	_INTERFACE_ENTRY(3, 4)
	_INTERFACE_ENTRY(5, 6)
END_ENTRIESMAP()

/' Compiler parsing results:
	Function _GetMapEntries() As _MAP_ENTRY Ptr
		Static As _MAP_ENTRY _entries(0 To ...) = { _
		(1, 2), _
		(3, 4), _
		(5, 6), _
		(0, 0)}
		Return @_entries(0)
	End Function
'/
…r '_'

- allow multiple lines of macro expanded code to be combined into a single statement.(Skyfish)
- lex.bas
- pp.bas
- previously fbc unable to handle single '_' token pasting single since in such cases the '_' is always seen as line continutation.
Example:
#define join1(a,b) a##_ b
#define join2(a,b) a _##b
#define join3(a,b) a##_##b

- because '_' line continuation and '##' token pasting are handled nearly entirely in the lexer, no token checks can be made
- adds lexGetLookAheadChar2( ) so that the sequence '_##' can be checked before tokenizing
- plus previous commits (Skyfish) allow handling the sequence '##_' to escape the '_' character and paste it in on expansion
@jayrm jayrm merged commit 417e334 into freebasic:master May 16, 2021
@jayrm jayrm deleted the token-pasting branch May 17, 2021 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants