Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various issue with recursive tokens #257

Closed
fdedinec opened this issue Dec 10, 2022 · 3 comments
Closed

Various issue with recursive tokens #257

fdedinec opened this issue Dec 10, 2022 · 3 comments

Comments

@fdedinec
Copy link

Hello,

I suspect that issue 44 is a consequence of this one.

Below is my grammar (sorry for the mess, work in progress).
I have two issues with the various typeName->name
One is #44 : I have to remove the whitespaces in a c++ post-prrocessing pass.
The second is that the following code doesn't work:

	DAGparser["entityName"] = [](const peg::SemanticValues &vs) {
		cerr << this << endl; // if this doesn't work, none of my class methods will
		return  removeSpaces(vs.token_to_string());
	};

(...) error: ‘this’ was not captured for this lambda function
(which prevents these functions to do the housekeeping they were intended for)

while DAGparser["nameValuePair"] = [&](const peg::SemanticValues &vs) {
cerr << this << endl;
(...) }
compiles OK.

I am not sure I understand why some rules are special.
If it is a feature of PEG (I come from yacc then antlr) please close this bug stating so.
I'll be avoiding this situation in between, it makes the grammar less verbose but also less explicit.

Thanks for cpp-peglib.
Florent

-- Bug reports are love letters.

dag <- command*
command <- parameterDeclaration / fileName / operatorDeclaration / InputDeclaration / OutputDeclaration / Assignment / LineComment/ EndOfLine
fileName <- 'Name' entityName ';'
parameterDeclaration <- 'Param' paramName '=' number ';'
operatorDeclaration <- 'Operator' instanceName ':' entityName nameValuePair* ';'
nameValuePair <- name '=' value
InputDeclaration <- 'Input' signalName ':' typeName '(' value ',' value ')' ';'
OutputDeclaration <- 'Output' signalName ':' typeName '(' value ',' value ')' ';'

Assignment <- signalName '=' instance ';'
instance <- instanceName '(' arg (',' arg)* ')'
arg <- instance / signalName

typeName <- name
instanceName <- name
entityName <- name
paramName <- name
signalName <- name
value <- string / number / paramValue
string <- < '"' (!'"' .)* '"' >
number <- < '-'? [0-9]+ >
name <- < [a-zA-Z] [a-zA-Z0-9-_]* >
paramValue <- '$' name

%whitespace <- [ \t\n]*
Endl <- EndOfLine / EndOfFile
EndOfLine <- '\r\n' / '\n' / '\r'
EndOfFile <- !.
LineComment <- ('#' / '//') (!Endl .)* &Endl

@yhirose
Copy link
Owner

yhirose commented Dec 10, 2022

@fdedinec, thank you for the feedback. I read your comment, but I still don't understand this issue, yet... Could you please show me the smallest possible PEG grammar and the shortest source text for the grammar to reveal the problem that you experienced? That will help me to understand this issue fully and I can give you a more meaningful comment. Thanks a lot!

@fdedinec
Copy link
Author

fdedinec commented Dec 11, 2022 via email

@yhirose
Copy link
Owner

yhirose commented Dec 21, 2022

@fdedinec sorry that I still don't understand what the problem is... Anyway, it seems like it's not an issue anymore. Hope your project will go smoothly!

@yhirose yhirose closed this as completed Dec 21, 2022
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

No branches or pull requests

2 participants