spell1 icon indicating copy to clipboard operation
spell1 copied to clipboard

List pattern matching might not be working with LFE 0.9.0

Open jfacorro opened this issue 10 years ago • 1 comments

While trying the LFE example out I couldn't get the generated parser code to be different from the include/spell1inc.lfe template. I tracked the problem down to the patterns used in this case:

     (case line
       (`(,@"##module" . ,_) (output-module out st))
       (`(,@"##code" . ,_) (output-user-code out st))
       (`(,@"##entry" . ,_) (output-entry out st))
       (`(,@"##table" . ,_) (output-table out st))
       (`(,@"##reduce" . ,_) (output-reduce out st))
       (_ (io:put_chars out line)))

I tried a similar approach in the shell and I got the following result:

> (set `(,@"hello" . ,_) "hello!")
1: Warning: deprecated pattern
1: Warning: deprecated pattern
exception error: #(badmatch "hello!")

If I change the patterns to the actual contents of the line (with the newline char and all) then everything the generated code gets inserted as expected:

     (case line
       ("##module\n" (output-module out st))
       ("##code\n" (output-user-code out st))
       ("##entry\n" (output-entry out st))
       ("##table\n" (output-table out st))
       ("##reduce" (output-reduce out st))
       (_ (io:put_chars out line)))

I might be doing something really wrong though.

jfacorro avatar Jul 22 '15 03:07 jfacorro

No, you are not doing anything wrong. The problem is that this code happened between two different ways of handling the backquote with a literal string as the first element. It is matching the corresponding erlang case

    case Line of
        "##module" ++ _ -> output_module(Out, St);
        "##export" ++ _ -> output_export(Out, St);
        "##code" ++ _ -> output_user_code(Out, St);
        "##entry" ++ _ -> output_entry(Out, St);
        "##table" ++ _ -> output_table(Out, St);
        "##reduce" ++ _ -> output_reduce(Out, St);
        _ -> io:put_chars(Out, Line),
    end,

The reason for doing it this way is to not force only having that symbol on the line.

Thanks for pointing out, I will fix it.

rvirding avatar Jul 25 '15 17:07 rvirding