Code Monkey home page Code Monkey logo

Comments (5)

VinGarcia avatar VinGarcia commented on May 30, 2024

The masking system is a little complicated. I can think of 2 possible reasons for this problem:

  1. ARR ID is colliding with some existing type making the operation be processed by some built-in one instead of the one you were expecting.
  2. You have defined a more specific operation for this same types, e.g. opMap.add({ANY_TYPE, "=%", ANY_TYPE})

@astlin can you provide the code you use to declare all your operations as well as the hex numeral of ARR? Then I should be able to diagnose what is happening.

from cparse.

astlin avatar astlin commented on May 30, 2024

Well, actually there is a declaration of '=%' for ANY_TYPE on ANY_TYPE right before the last one 'ANY ANY ANY'.

opMap.add({ARR, ANY_OP, ANY_TYPE}, &ArrayOnAnyOperation);
opMap.add({ARR, "=%", ANY_TYPE}, &ArrayOnAnyOperation);
....
opMap.add({ANY_TYPE, "=%", ANY_TYPE}, &AnyLike);
opMap.add({ANY_TYPE, ANY_OP, ANY_TYPE}, &AnyOnAny);

from cparse.

VinGarcia avatar VinGarcia commented on May 30, 2024

This {ANY, =%, ANY} operation is most likely taking precedence.

The ANY_OP operations are only evaluated if there is no match with a specific operation, quoting the code:

// Resolve the operation: 
result = exec_operation(p_left, p_right, &data, data.op); 
if (!result) {
  // ANY_OP will only run if no other match is found:
  result = exec_operation(p_left, p_right, &data, ANY_OP); 
}

This could probably be better explained in the docs. In any case I suggest you group your ANY_OP operation declarations and set put them after the rest, so it will be more clear the actual precedence order:

// The order is important between 2 operations with the same operator
// So ARR "=%" ANY will have precedence over ANY "=%" ANY
opMap.add({ARR, "=%", ANY_TYPE}, &ArrayOnAnyOperation);
opMap.add({ANY_TYPE, "=%", ANY_TYPE}, &AnyLike);

// Likewise {ARR ANY_OP ANY} will have precedence over {ANY ANY_OP ANY}
// But ANY_OP will always have less precedence than specific operations so they should
// be put in last to make it clear.
opMap.add({ARR, ANY_OP, ANY_TYPE}, &ArrayOnAnyOperation);
opMap.add({ANY_TYPE, ANY_OP, ANY_TYPE}, &AnyOnAny);

I will add this example to the docs and then, if it works for you, close this issue.

from cparse.

VinGarcia avatar VinGarcia commented on May 30, 2024

I have updated the doc section on this, and it should be clearer now.

Let me know if this helps.

from cparse.

astlin avatar astlin commented on May 30, 2024

Ok. Thanx for explanation.

from cparse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.