Comments (8)
Hello @grazba, this is an issue we still have on the system #52, I was postponing this because it is somewhat complex, but I will put my hands on it so it is fixed asap.
In the short term, we will have to think of an alternative solution.
One suggestion would be to implement it as a update()
type-specific function, e.g.:
myClass.update(MyObj)
I am not entirely sure this solves it for you (at least temporarily), but inside the function you would have access to a "this" object that will be your "myClass" instance. e.g.:
packToken myClass_update(TokenMap scope) {
MyClass& m = scope["this"].as<MyClass>();
// ... do stuff ...
}
Also, if your class is based on the TokenMap type, you might prefer to put this function in the prototype of your class, since as a type-specific function it would affect all the tokens of type MAP, not only the ones which are instances of your class.
If you are curious the problem with assignment operations is that it should receive not only the left/right operands as most operations do but also some kind of reference of the TokenMap where the left operand is stored. Otherwise changing the left token would not necessarily affect the original object, e.g.:
a.b = 10
requires the function to replace the value o the key "b" of the map "a".
I will take some time to think the best way to do this. And hopefully, this weekend, I will have time to fix it permanently.
from cparse.
I have already considered other solutions for now since my projects relies on a user interface (it's a calculator for "special data objects") but the goal too is to develop a small scripting language so that the users could write complex scripts and run them directly without relying on the UI.
Well i hope you will find a solution soon until then i'll focus on finishing the project on using the Ui to execute reads and writes where it should.
Thanks again 👍 !
from cparse.
That's cool @grazba. I am happy to know you are really using this library in something interesting =].
And about the issue I think I have fixed it =].
There are still some steps before I close issue #52:
- I need to write some tests
- I need to write some documentation
- I want to add 2 new built-in operations: ++ and --
However, if you pull the most recent version of the library and read the builtin-features/operations.inc
file you'll see that the first operation defined is now the assignment operation. You may just copy it to your project and edit it as you would with any other operation. It should work fine.
from cparse.
Hi @VinGarcia sorry for the late reply, i was pretty busy with some other projects :) !
I have two questions about the assignment operator , what am i supposed to return ? and is the return value what makes the assignment ?
from cparse.
This type of operator usually return the same thing that was assigned and it is meant to be used for assignments in strange places e.g.:
a = b = c
// or:
f(d = e)
a
will receive the return value of the operation b = c
in the first case and in the second case the function f would receive the return value of the operation d = e
.
The actual assignment, i.e. changing the value in its original storage location, is performed on the object which stores the variable being assigned, i.e. the data->left->origin
object, which may be either a MAP or a LIST, in both cases you must use the index of the variable stored on data->left->key
, which on the first case is a string and on the second case is an integer. The lines on the built-in operation that actually perform the assignment are:
map[var_name] = right;
- if it is inside a local objectdata->scope[var_name] = right;
- if it is a new local variable (the scope is also of type MAP)(*map)[var_name] = right;
- if it is an existing local variable
And for list containers:
list[index] = right;
So as you can see this is a slightly more complicated operator, modifying it would probably be in the advanced features category, however, if you just want to implement a new behavior when the type in the left is an instance of your class you may just add an if (left->type == MY_TYPE) on the begining of the function, or alternatively add a new operation associated with the "=" operator and register it to be evaluated before the built-in one, e.g.:
opMap_t& opMap = calculator::Default().opMap;
opMap.add({MY_TYPE, "=", ANY_TYPE}, &MyAssign);
opMap.add({ANY_TYPE, "=", ANY_TYPE}, &Assign);
Should do the trick.
from cparse.
from cparse.
i deleted the messages because it was my fault , i tried to get rid of the .inc files replaced them with regular .h ones and for some reason it did not work, so every built-feature was missing assignment and str but weirdly enough my types were still there. So yeah i deleted the messages because everything is working as expected (y) !
from cparse.
@grazba, I just wanted you to know I have written a new section on the docs explaining how to create new operations of this type, I called it Creating Advanced Operations.
I will probably read it again someday, I never trust the first version I write =P.
Also, you don't have to read it but if you do, it would be great to have your feedback.
Regards
from cparse.
Related Issues (20)
- exception on simple calculatorexample
- Segmentation fault on bad inputs
- group/vector operation possible? Naive iteration can be expensive when number of elements is huge HOT 5
- terminating with uncaught exception of type syntax_error: Invalid operator: - HOT 4
- Token names cannot have UTF8 characters HOT 4
- Project doesn't install anything HOT 10
- Syntax errors cause crashes HOT 21
- Hexadecimal number computation HOT 4
- calculator ignores variable HOT 3
- Consider adding a namespace to cparse code HOT 6
- Program treats "." in numeric "0.x" as an operator and throw an exception! HOT 5
- Thread Safety HOT 4
- Is not operator supported? HOT 1
- Warning c4099 is everywhere. HOT 3
- Invalid operators, but with ALL operators HOT 1
- It doesn't compile in Windows and Linux, am I doing something wrong? HOT 3
- Buffer-overflow (out-of-bounds read) occured in two positions HOT 1
- cparse/builtin-features/operators.inc HOT 9
- Solved. Errors with Linux emulator using GCC. HOT 22
- TokenMap value change to None,when using getChild() HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cparse.