I've been following the JetBrains MPS Shapes tutorial:
https://confluence.jetbrains.com/display/MPSD32/Shapes+-+an+introductory+MPS+tutorial
In the tutorial section "A more robust generation for Squares" there is the following definition:
template reduce_Square
input Square
parameters
<< ... >>
content node:
{
Graphics g = null;
<TF {
->$g.setColor(Color.->$red);
->$g.drawRect($10, $10, $10, $10);
} TF>
}
And the reference macro for g (which you can see in the Inspector part of the editor if you put the cursor at ->$g) is:
(outputNode, genContext, operationContext, node)->join(node<VariableDeclaration> | string) {
genContext.get output graphicParam for (node.parent : Canvas);
}
Yet when trying to rebuild the "Shapes" language I get the following error message (4 times, twice for each ->$g):
type node<> is not a subtype of node<VariableDeclaration>
Could you please check that you specify the from and to concepts for the mapping label correctly? It should be
"label graphicsParam : Canvas -> ParameterDeclaration", as specified in the tutorial.
Related
I'm new to Function Programming(FP) and Elm, so thinking in FP way is quite challenging for me.
I'm working on a web-app which is very similar to the example of Elm Tutorial.
For the sake of simplicity, we assume the sub-module is a counter.
It will display an initial value of 0 and two buttons to increase/decrease that value.
,---. ,---.
| + | 123 | - |
`---' `---'
And simplified version of my app is shown below:
-------------------------------------
type alias Model =
{ contents : List Contents.Content
, routing : Routing
}
type Routing = List | Edit Int
view : Model -> Html
view model =
case model.routing of
Edit id ->
let
maybe = List.head << (List.filter (\c -> c.id == id)) model.contents
in
case maybe of
Just content -> Contents.EditView content
Nothing -> div [] [ text "Error" ]
List -> Contents.listView model.contents
------------------------------------
module Contents where
type alias Content = { someKey : SomeType }
editView : Content -> Html
editView content =
div []
[ Counter.view WHERE_SHOULD_I_GOT_A_Counter.Model_FOR_THIS_CALL
, someOtherViews content
]
listView : List Content -> Html
listView =
listViewImp
---------------------------
module Counter where
type alias Model = Int
view : Model -> Html
view model =
div []
[ button [] [ text "+" ]
, text (toString model)
, button [] [ text "-" ]
]
There is three-level view hierarchy :
main view ----> edit view --> counter
|-> list view
The counter value should be 0 every time I navigate to edit view from other views, and then it should be modified only by clicking those two buttons until I leave that page.
The question is where should I get a Counter.Model to pass to Counter.view?
Because the counter is totally independent, so I don't want top level view to know its existence, so it can't be sent from view function.
If I initialize a Counter.Model in editView function, every call to editView (invoked by other actions maybe) will re-initialize the counter to 0
I hope that I have made myself understood.
Thanks for reading all of these.
Thanks to all of you commenting.
After going through the Elm Architecture tutorial again, I noticed that its code structure is somehow different from the one used in Elm Tutorial Gitbook. And for my app, it's better to use the one described in Elm Architecture tutorial.
There is the difference:
Elm Architecture defines Model Action update view and init for all the sub module
Utility modules are not counted as sub module here
some of the Model Action... may be omitted when it is quite simple
Elm Tutorial puts the Models and Actions of a certain concept into separate .elm files and has a few View files (Edit.elm List.elm etc.) which are importing the Models and Actions
When a certain concept's different views depend on its Model ONLY(or its variant, List Model for example), we can adopt the structure used in the Elm Tutorial. The reason is any high level modules using that concept would initialize the Model as a part of HighLevelModel. But when there is a view that not only depends on its own 'Model' but also needs another sub module, we can not use the structure of Elm Tutorial. In this case, that view can be treated as a new module (in fact, it is a new module), so it should have its own Model type and be imported by the high level module.
I currently have a xtext grammar that looks like the following :
Features:
'feature' name = ID
'{'(
('action' '{' action+=Actions (',' action+=Actions)* '}')? &
('dependencies' '{' dependencies = Dependencies '}')? &
('children' '{' children = Children '}')?
)'}'
;
What I want to do with this is add an action to an already existing source file programatically, for that I am using the IUnitOfWork.Void class that I subclass for easier implementation , it currently looks like this (the meaningful part of it) :
final XtextEditor editor = (XtextEditor)sourcepart;
final IXtextDocument document = editor.getDocument();
document.modify(new IUnitOfWork.Void<XtextResource>(){
public void process (XtextResource resource) throws Exception {
IParseResult parseResult = resource.getParseResult();
if(parseResult ==null)
return;
CompositeNode rootNode=(CompositeNode) parseResult.getRootNode();
LeafNode node = (LeafNode)NodeModelUtils.findLeafNodeAtOffset(rootNode, 0);
EObject object =NodeModelUtils.findActualSemanticObjectFor(node);
Through this I traverse the tree of the model and get to my Features object to which I want to add an action to (this is done through a pop up menu in a custom Tree View I'm implementing)
Here's my problem : whenever I want to add an action it screws up the way the tags are placed in the source file , and by that I mean that instead of :
action {
act1.set (foo),
act2.set (bar),
act3.set (baz),
act4.set (booze) //where this is the new action that I add
}
it will add it as
action {
act1.set (foo),
act2.set (bar),
act3.set (baz)
}
action {
act4.set(booze)
}
And this is illegal by the rules of my grammar, and I'm not allowed to change the way it should be written. (I am allowed to make small changes to the way the rules are implemented, but would really want to avoid it as it would mean a whole new amount of work to reimplement other things that depend on them)
I've tried :
adding it directly through Features.getAction().add(*the new action);
copying the items in the list into an array with the toArray() method so as to avoid referencing, adding my action to the array, clearing the list then adding all the elements again one by one
creating an entirely new Features object and setting everything in it to be the same as the currently edited one then replacing the feature with the new one
And I'm out of ideas after that. The frustrating part is that the 3rd method worked for a different kind of object in my grammar and had no errors there.
How could I make this work ?
this is a bug in xtext. (can you please file a ticket?)
as a workaround you may use the following
Features:
'feature' name = ID
'{'(
('action' '{' actionList=ActionList '}')? &
('dependencies' '{' dependencies = Dependencies '}')? &
('children' '{' children = Children '}')?
)'}';
ActionList:
(action+=Action (',' action+=Action)*)
;
I am learning qml,quick and pyqt5 and write a small test script.
In this script, I want to drop something on my UI and print the url of it.
test.qml
import QtQuick 2.3
Rectangle {
id : root
signal clicked(int x, int y)
signal filedroped(list url)
width: 800
height: 450
MouseArea {
anchors.fill: parent
onClicked: {
parent.clicked(mouseX, mouseY)
}
DropArea {
anchors.fill: parent
onDropped: {
root.filedroped(drop.urls)
}
}
}
}
The doc says:Any of the QML Basic Types aside from the enumeration type can be used as custom property types.
But I got error like this in signal filedroped:
Invalid signal parameter type: list
Also, I have tried urllist and string.
urllist failed and string works.
What's wrong with my script?
EDIT
Since I use qml with pyqt, I do not want to use the type var.
With var, I'll got a QJSValue object instead of basic type of python in my python script.
Why qml performs different with the official document? Is the document wrong?
It seems on there's indeed an error in the Qt Documentation. It is said (here) that
the allowed parameter types [for signal parameters] are the same as those listed under
Defining Property Attributes on this page.
Yet one can define a property as follow:
property list<Item> items
whereas this is invalid:
signal mysignal(list<Item> items)
But anyway, the QML list type was not a solution. The official documentation is quite clear:
A list can only store QML objects, and cannot contain any basic type
values. (To store basic types within a list, use the var type
instead.).
In other words you can't use list to store strings, url, int. You have to use var. Another solution would be to use a formatted string with a custom separator instead of your url list, and split it on the Python side.
It looks that urllist is an array of urls so you can use var in this case:
signal filedroped(var urls)
Chapter 3 of the AngularDart tutorial defines a rating #NgComponent (see excerpt below), that is used in index.html like this:
<rating max-rating="5" rating="ctrl.selectedRecipe.rating"></rating>
In that chapter it is also suggested that that the max-rating #NgAttr can be set via a {{...}} like this:
<rating max-rating="{{ctrl.max}}" rating="ctrl.selectedRecipe.rating"></rating>
In the RecipeController I have simply declared:
int max = 5;
If I add print("maxRating('$value')") at the top of the component's maxRating() setter body (see below), then in running the app I get the following output:
maxRating('') // printed 7 times
maxRating('5') // printed 7 times
Questions: Why is the value initially empty? I assume that it is because the interpolation has not been done yet, but then why is the setter called at all before the value is "ready"?
Excerpt of RatingComponent class definition:
#NgComponent(
selector: 'rating', ...
publishAs: 'cmp'
)
class RatingComponent {
...
#NgTwoWay('rating')
int rating;
#NgAttr('max-rating')
set maxRating(String value) {
var count = value == null ? 5 : int.parse(value);
stars = new List.generate(count, (i) => i+1);
}
As far as I know, angular dart is very eager in applying values. As soon as angular is running it starts applying values, I guess to provide a feel of responsiveness.
I've been bitten by this too and had to write more than one workaround for not yet initialized values.
The setter and getters are called by the binding mechanism to stabilize the values, as some values may depend on each other and the mechanism "brute forces" this by just setting and getting values multiple times (7 by default, IIRC).
How to check whether a given point is contained in a rectangle using the contains() function in Rect_ construct... Please give me the exact function and its parameters. Like when I type this
Point b(2,2);
Rect a(10,10,50,50);
cout<< Rect_::contains(b);
There is a compile error saying 1>c:\users\kaushal\documents\visual studio 2008\projects\test1\test1.cpp(23) : error C2352: 'cv::Rect_<_Tp>::contains' : illegal call of non-static member function
1>c:\opencv2.1\include\opencv\cxcore.hpp(385) : see declaration of 'cv::Rect_<_Tp>::contains'
You want to use the instance of a defining the area to run the method for deciding a contains b. The method contains is not static, therefor you cannot call it on the class Rect.
Point b(2,2);
Rect a(10,10,50,50);
cout<< Rect_::contains(b); // error here - contains is not static so can't be called on class
cout<< a.contains(b); // this is what you want - use instance with knowledge of rect