0

I want to check syntax for multiple defrules. How should I implement this operation?

I know (check-syntax <construct-or-function-string>) can check one rule, but it does not support multiple rules in one string.

Example (in clips cli):

CLIPS> (check-syntax "(defrule output1 => (printout t \"test for check-syntax 1\")
)")
FALSE
CLIPS> (check-syntax "(defrule output1 => (printout t \"test for check-syntax 1\")
) (defrule output2 => (printout t \"test for check-syntax 2\")
)")
EXTRANEOUS-INPUT-AFTER-LAST-PARENTHESIS

If there is a string containing multiple rules,do I have to split it as a single rule for check-syntax?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Javin Fan
  • 17
  • 1
  • 5

1 Answers1

0

The check-syntax function will only check a single construct. If you have a string containing multiple rules, you must split that string into multiple strings in order to check each one.

Gary Riley
  • 10,130
  • 2
  • 19
  • 34
  • Is there a recommended split method? Regular matching? – Javin Fan Oct 14 '19 at 04:04
  • Alternatively, we can count the open brackets (openBr++) and the stop brackets (openBr--). When openBr is reduced to zero, the string represents a single construct.Like this:[Regular expression to match balanced parentheses](https://stackoverflow.com/questions/524548/regular-expression-to-detect-semi-colon-terminated-c-for-while-loops/524624#524624) – Javin Fan Oct 14 '19 at 04:57
  • In addition to counting parentheses, for completeness you must also ignore parentheses contained within comments and strings. – Gary Riley Oct 14 '19 at 16:50