Skip to content

SmaCC: Re-parsing strings as expressions #4100

Answered by j-brant
joelreymont asked this question in Q&A
Discussion options

You must be logged in to vote

You could do something like this:

<define>
	: \@define
	;
<misc>
	: \{ | \} | [a-zA-Z]+
	;
<whitespace>
	: \s+
	;
<semicolon>
	: a
	;
Start 
	: "Foo"
	;

And define a define method on your scanner:

define
	| token |
	[ token := self next.
	token ids first = self emptySymbolTokenId or: [ token value = ';' ] ]
		whileFalse.
	^ self next

With this you can parse @define asdf {{}}{{}{{} ; Foo. It will skip over the @define stuff and only see the Foo token. For your use, you would need to store the tokens so you could replay them when you see the reference.

Replies: 7 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@joelreymont
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by joelreymont
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants