Giter Site home page Giter Site logo

Comments (14)

sweetpi avatar sweetpi commented on July 23, 2024

predicate propably should be actionString ?

from pimatic-plugin-template.

sweetpi avatar sweetpi commented on July 23, 2024

and be carefull matchString has no option parameter, it just takes a callback at the moment, so

.matchString(optional: yes, setTitle)

will not work.

from pimatic-plugin-template.

thexperiments avatar thexperiments commented on July 23, 2024

ok you are right, copy&paste error...
thanks about the matchString, hmm will it work then if the "title:" is not supplied?

from pimatic-plugin-template.

thexperiments avatar thexperiments commented on July 23, 2024
      M(actionString, context)
        .match('send ', optional: yes)
        .match(['push ','pushover ','notification '])
        .match('tile:', optional: yes)
        .matchString(setTitle)
        .match('message:')
        .matchString(setMessage)
        .match('priority:', optional: yes)
        .matchNumber(setPriority)
        .onEnd( => matchCount++)

still doesn't seem to match

push title:"push" message:"test" priority:0

from pimatic-plugin-template.

sweetpi avatar sweetpi commented on July 23, 2024

thanks about the matchString, hmm will it work then if the "title:" is not supplied?

m = M(actionString, context)
    .match('send ', optional: yes)
    .match(['push ','pushover ','notification '])
next = m.match('tile:').matchString(setTitle)
unless next.hadNoMatches()
  m = next
m.match... 

from pimatic-plugin-template.

sweetpi avatar sweetpi commented on July 23, 2024

still doesn't seem to match

You don't match against the space between string end and message.

from pimatic-plugin-template.

thexperiments avatar thexperiments commented on July 23, 2024

with the "next" method you suggested I now get the following error:

< error: Could not parse rule "if Push Test is pressed then push title:"push" message:"test" priority:0": Error executing a action handler: inputs is not defined, Could not find an action handler for: push title:"push" message:"test" priority:0
< debug: Error: Error executing a action handler: inputs is not defined, Could not find an action handler for: push title:"push" message:"test" priority:0
<   at RuleManager.addRuleByString.parseRuleString.then.rule (/Users/thex/dev-pimatic/node_modules/pimatic/lib/rules.coffee:340:5)
<   at _fulfilled (/Users/thex/dev-pimatic/node_modules/pimatic/node_modules/q/q.js:798:54)
<   at Promise.then.self.promiseDispatch.done (/Users/thex/dev-pimatic/node_modules/pimatic/node_modules/q/q.js:827:30)
<   at Promise.promise.promiseDispatch (/Users/thex/dev-pimatic/node_modules/pimatic/node_modules/q/q.js:760:13)
<   at messages (/Users/thex/dev-pimatic/node_modules/pimatic/node_modules/q/q.js:574:44)
<   at flush (/Users/thex/dev-pimatic/node_modules/pimatic/node_modules/q/q.js:108:17)
<   at process._tickCallback (node.js:415:13)
<   at [object Object].Module.runMain [as _onTimeout] (module.js:499:11)
<   at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

code now looks like this:

      m = M(actionString, context)
        .match('send ', optional: yes)
        .match(['push ','pushover ','notification '])

      next = m.match(' tile:').matchString(setTitle)
      unless next.hadNoMatches()
        m = next

      next = m.match(' message:').matchString(setMessage)
      unless next.hadNoMatches()
        m = next

      next = m.match(' priority:').matchNumber(setPriority)
      unless next.hadNoMatches()
        m = next

      m.onEnd( => matchCount++)

from pimatic-plugin-template.

sweetpi avatar sweetpi commented on July 23, 2024

be welcome to development branch. Should be fixed now: pimatic/pimatic@21159dc

from pimatic-plugin-template.

sweetpi avatar sweetpi commented on July 23, 2024
    .match(['push ','pushover ','notification '])

  next = m.match(' tile:').matchString(setTitle)

Now you match against space twice. At the end of 'push ' and beginning of ' title'

from pimatic-plugin-template.

thexperiments avatar thexperiments commented on July 23, 2024

yes error is gone, sure it's development branch and might contain bug, this way we find them faster.

already removed the space after push but it still doesn't want to match. Couldn't we modify the regex to allow any number of spaces between the items to match?

from pimatic-plugin-template.

sweetpi avatar sweetpi commented on July 23, 2024

already removed the space after push but it still doesn't want to match. Couldn't we modify the regex to allow any number of spaces between the items to match?

We could, I will think about it. Try to debug how far it matches.

The matcher works like that: It tries to match its input (actionString for the first one) against the given string or regexp and if it matches it returns a new matcher that has the remaining part as input and so you can call match on the returned matcher with the next part as input. If it doesn't match it returns an matcher with an empty input.

You can check if the current matcher did its job by dumping the inputs of the next one:

m = M('push message...', context).match('push ')
console.log(m.inputs) # should be ["message..."]
m = m.match('message') 
console.log(m.inputs) # should be ["..."]

from pimatic-plugin-template.

thexperiments avatar thexperiments commented on July 23, 2024

found it... a tile is not a title ;)

from pimatic-plugin-template.

sweetpi avatar sweetpi commented on July 23, 2024

found it... a tile is not a title ;)

didn't see it, too :D

from pimatic-plugin-template.

thexperiments avatar thexperiments commented on July 23, 2024

ok great working now :) once you know how to use the matcher it makes defining the conditions much easier.

from pimatic-plugin-template.

Related Issues (10)

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.