Loading ...
Sorry, an error occurred while loading the content.

2242Re: suitability of using JSLint for validate single-line JavaScript equations?

Expand Messages
  • Douglas Crockford
    Jun 2, 2011
      --- In jslint_com@yahoogroups.com, "tmswhite2011" <tom.white.md@...> wrote:
      > I'm trying to find a good tool for evaluating the following types of equations:
      > (1) All variables names externally pre-defined
      > (2) All allowable function names externally pre-defined - ideally with some degree of syntax checking (my functions tend to have 0, 1, 2, 3, or unlimited numbers of arguments, and I have about 100 of them)
      > (3) All math operators and Math functions
      > (4) Ideally, properly assess whether left and right hand parts are string, numeric, or date (so can provide warnings if try to multiply two strings, for example)
      > (5) Strict enforcement of other syntax elements (e.g. to start, I probably want to avoid arrays, dot notation on variables, any variable assignment or new object creation)
      > (6) Good error reporting if there are syntax errors.
      > JSLint seems to do all of this and more. My question is whether I can fairly easily modify it to enforce this more limited set of functionality.
      > In case you are interested, I'm trying to build an equation parser into the open-source LimeSurvey tool. Each survey question has an associated variable name. The equation parser must only allow variables that have been pre-defined, and only allow functions that are pre-configured within LimeSurvey (to avoid scripting attacks).
      > I had planned to use a compiler-compiler to generate the needed equation parser and execution engine in PHP and JavaScipt, but I've been unable to find a well supported compiler-compiler that generates PHP or JavaScript (I'm spoiled by how well JavaCC and Bison/Lex work for Java and C respectively). So instead, if I can get JSLint to validate the syntax, I can safely use the PHP and JavaScript eval() functions to process the equations.
      > So, can JSLint do what I want, or do I need to modify/ extend it.
      > If JSLint is too powerful a tool for my stated needs, can anyone recommend an alternative?

      JSLint does what it does. If you want it to do something else, you will need to modify it. It is written completely in JavaScript with no dependence on external tools. It is open. You are free to use the source however you like as long as you not use it for evil. That is because I don't like evil. Evil is bad.

      If you decide to modify JSLint, you are on your own. You will get no support from me.
    • Show all 2 messages in this topic