Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Format for specifying a list of source files for a DSL
Format for specifying a list of source files for a DSL [message #1708740] Sat, 19 September 2015 18:44 Go to next message
Elvis Dowson is currently offline Elvis DowsonFriend
Messages: 65
Registered: December 2011
Member
Hi,

I need to generate the following list of source files to exclude from a build, by inserting the following text snippet into a CMakeLists.txt file:

# Exclude specific files from the build.
set (CTR_SOURCES_EXCLUDE dir1/file1.cpp
                      dir1/file2.cpp
                      dir2/file3.cpp
                      dir2/file4.cpp)


What would be the best option to represent this list in my DSL?

project test_project  {

	// Project information.
	name = "test_project";
	description = "Test project";
	version = "1.0";

	// Exclude files.
	exclude_files = "dir1/file1.cpp,
                         dir1/file2.cpp,
                         dir2/file3.cpp,
                         dir2/file4.cpp"; // Is there a better way to specify the list of files to exclude here?

}


Is there a better or more natural way to specify the list of exclude files, other than the one described above?

Regards,

Elvsi Dowson

[Updated on: Sat, 19 September 2015 18:57]

Report message to a moderator

Re: Format for specifying a list of source files for a DSL [message #1709045 is a reply to message #1708740] Wed, 23 September 2015 14:19 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Quote:
Is there a better or more natural way to specify the list of exclude files, other than the one described above?


Firstly, why hide the list inside the string, rather than saying:
	exclude_files = "dir1/file1.cpp",
                         "dir1/file2.cpp",
                         "dir2/file3.cpp",
                         "dir2/file4.cpp";


Secondly, IMHO, using a quoted string for anything that is supposed to refer some existing thing is a bad smell. Question: is it necessary to cope with white space inside file names? If not I'd suggest:
	exclude_files = dir1/file1.cpp,
                         dir1/file2.cpp,
                         dir2/file3.cpp,
                         dir2/file4.cpp;


Next you could challenge the necessity of semicolons and commas etc.

Or, if you want to reflect the directory structure, why not:
	exclude_files = dir1 { file1.cpp, file2.cpp },
                         dir2 { file3.cpp, file4.cpp };


etc.

Quote:
Is there a better or more natural way ...


What is "better" or "more natural" in your context?
Stephan
Re: Format for specifying a list of source files for a DSL [message #1709079 is a reply to message #1708740] Wed, 23 September 2015 19:23 Go to previous messageGo to next message
Elvis Dowson is currently offline Elvis DowsonFriend
Messages: 65
Registered: December 2011
Member
Hi Stephane,

I like the following option for specifying the file list:

exclude_files = dir1 { file1.cpp, file2.cpp },
                dir2 { file3.cpp, file4.cpp };


How can I go about refactoring my existing DSL, to incorporate this change? At the moment, all the ProjectTypes in the DSL simply take string value inputs. What should I do to be able to change each project type expression in a modular manner, e.g. change exclude_files to accept the above expression, but leave the rest the same?

// Project.
Project:
	('abstract')? 'project' name=ID ('extends' superclass = [Project])? '{'
		projectAttributes += ProjectAttribute*
		('maintainer' maintainers = [Maintainer] ';')?
	'}';

ProjectAttribute:
	type=ProjectAttributeType (name=ID)? '=' expression=TerminalExpression ';';

ProjectAttributeType:
	projectElementType=ProjectElementType (array ?= '[' (length=INT)? ']')?;

ProjectElementType:
	ProjectType;

ProjectType:
	typeName=('name' |
              'description' |
              'version' |
              'license' |
              'library' |
              'executable' |
              'tool' |
              'include_directories' |
              'header_files' |
              'source_directories' |
              'source_files' |
              'exclude_files' |
              'model_directories' |
              'model_files'  |
              'build_dependency' |
              'run_dependency' |
              'test_dependency');

// Maintainer information.
Maintainer:
	'maintainer' name=ID 'full_name' fullname=STRING 'email' email=STRING;

NameWithSpaces:
	ID (WS)* (ID)*;

// Expressions.
TerminalExpression returns Expression:
        {StringConstant} value=STRING |
        {IntConstant}    value=INT |
        {BoolConstant}   value = ('true' | 'false') |
        {ProjectRef}     (project += [Project] ("," project += [Project])*);


Regards,

Elvis Dowson

[Updated on: Wed, 23 September 2015 19:26]

Report message to a moderator

Re: Format for specifying a list of source files for a DSL [message #1709194 is a reply to message #1709079] Thu, 24 September 2015 18:34 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
It looks unfortunate, how deeply nested the keyword 'exclude_files' is hidden behind indirections. In particular, can you tell us what's the use of the rule ProjectElementType? Smile

This way you already lost the connection between the different keywords and the alternatives in TerminalExpression.
But assuming that you may already have validations to check that the expression format matches the type, why not simply add another alternative to TerminalExpression?

Otherwise, you'd probably start by making "ProjectAttribute" a set of alternatives along the following lines (simplified):
ProjectAttribute : StringAttribute | FileSetAttribute;
FileSetAttribute:
    type=('source_files' |'exclude_files') '=' expression=FileSetExpression;

This will require to repeatedly specify things like "name", "array", "length" but if the grammar isn't huge that shouldn't hurt, IMHO.

HTH,
Stephan
Re: Format for specifying a list of source files for a DSL [message #1709196 is a reply to message #1709194] Thu, 24 September 2015 19:21 Go to previous messageGo to next message
Elvis Dowson is currently offline Elvis DowsonFriend
Messages: 65
Registered: December 2011
Member
Hi Stephan,

You're correct that at the moment ProjectElementType is pretty much useless. It was just left there because an example that I started with, used such a construct for handling multiple element types, but in my DSL's case, it probably isn't necessary.

In your example, how would you define FileSetExpression?

Regards,

Elvis Dowson
Re: Format for specifying a list of source files for a DSL [message #1709357 is a reply to message #1709196] Sun, 27 September 2015 17:26 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Quote:
In your example, how would you define FileSetExpression?


What about (untested):
FileSetExpression: filesInDir+=FilesInDir (',' filesInDir+=FilesInDir)* ;
FilesInDir:
    dirPath=DirPath
   (
     (files+=File)
   |
     ('{' files+=File (',' files+=File)* '}')
   );
DirPath: ID  ('/' ID)*;
File: ID '.' ID;


Lot's of little variants are possible, I guess.

Depending on context in your grammar, the initial ID in DirPath may create an ambiguity with other rules. If so, it might force you to make at least on '/' mandatory.

HTH,
Stephan
Previous Topic:Weird message after stopping my plugin and re-executing it
Next Topic:Xtext validation queries
Goto Forum:
  


Current Time: Fri Apr 19 21:36:41 GMT 2024

Powered by FUDForum. Page generated in 0.02830 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top