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

Field name in a syntax definition wrongly associated as redefinition of Rascal grammar field? #1190

Closed
msteindorfer opened this issue May 17, 2018 · 4 comments

Comments

@msteindorfer
Copy link
Member

When importing my own syntax definition of a language in a compiled Rascal console, then I'm getting the following error:

Error: Field chars already defined as type [34-34]+ on non-terminal type StringConstant, cannot redefine to type MyStringChars? AT |std:///lang/rascal/syntax/Rascal.rsc|(14583,14,<374,8>,<374,22>)

Both my own syntax definition and also the Rascal grammar contain a lexical named StringConstant with a field chars, however it remains unclear to me why the compiler associated my syntax definition's lexical, with the Rascal'l lexical (neither Rascal grammar nor any other module is imported):

// MyLanguage.rsc
lexical StringConstant
  = @category="Constant" "\"": MyStringChars? chars "\"" ;
// Rascal.rsc
lexical StringConstant
  = @category="Constant" "\"" StringCharacter* chars "\"" ;
@DavyLandman
Copy link
Member

DavyLandman commented May 17, 2018

which modules have you imported? if one of them also (transitively) imports the rascal grammar, that's the cause.

@msteindorfer
Copy link
Member Author

@DavyLandman, no module import, just the syntax definition standalone, thus I don't understand where the Rascal grammar comes from.

@msteindorfer
Copy link
Member Author

What if I indeed would like to include two grammars that have the same names for productions or lexicals (e.g., if I'd like to transform from one language to another)?

I'd assume that names like StringConstant or IntegerLiteral are common in grammars.

@DavyLandman
Copy link
Member

That is possible, but mixing them in the same file is a bit painful, as grammars are merged differently than the import works for other stuff. I think @tvdstorm has most experience with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants