trueagi-io / metta-wam

A Hyperon MeTTa Interpreter/Transpilier that targets the Warren Abstract Machine
7 stars 9 forks source link

Implement the parse Function and Add Test Cases #56

Open TeamSPoon opened 1 month ago

TeamSPoon commented 1 month ago

Implement the parse Function and Add Test Cases

This issue involves implementing the parse function in MeTTa and creating test cases to verify its correctness. The parse function should convert a string representing an expression into its corresponding internal structure (e.g., an abstract syntax tree). The goal is to ensure that various expressions are parsed correctly, including nested expressions, symbolic expressions, and edge cases.


Task Description

  1. Implement the parse Function:

    • The parse function should take a string input and convert it into a MeTTa expression. For example:

      (parse "(+ 1 2)") -> (+ 1 2)
    • The function should handle nested expressions, symbols, and other language constructs like conditionals and lambdas.

  2. Create the Test File:

    • A new file named parse_test.metta should be added to the tests/baseline_compat/hyperon-mettalog_sanity directory.
  3. Include the Following Test Cases:

    ;; Simple Expressions
    !(assertEqual (parse "(+ 1 2)") (+ 1 2))
    !(assertEqual (parse "(* 3 4)") (* 3 4))
    !(assertEqual (parse "(/ 10 5)") (/ 10 5))
    
    ;; Nested Expressions
    !(assertEqual (parse "(+ 1 (* 2 3))") (+ 1 (* 2 3)))
    !(assertEqual (parse "(and (== 1 1) (not false))") (and (== 1 1) (not false)))
    
    ;; Empty Expression
    !(assertEqual (parse "()") ())
    
    ;; Symbolic Expressions
    !(assertEqual (parse "(foo bar baz)") (foo bar baz))
    !(assertEqual (parse "(let x 42)") (let x 42))
    
    ;; Complex Expressions
    !(assertEqual (parse "(if (> 3 2) (print \"Yes\") (print \"No\"))") (if (> 3 2) (print "Yes") (print "No")))
    !(assertEqual (parse "(lambda (x) (+ x 1))") (lambda (x) (+ x 1)))
  4. Run and Verify:

    • Once the test cases are in place, ensure they run correctly within the MeTTa test suite.

Expected Outcome

The parse function should be implemented and tested to confirm that it correctly converts string inputs into MeTTa expressions. The tests should cover a range of scenarios, ensuring that expressions of varying complexity are parsed accurately.