Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar of S-expressions #1

Open
ahmet-celik opened this issue Dec 2, 2018 · 1 comment
Open

Grammar of S-expressions #1

ahmet-celik opened this issue Dec 2, 2018 · 1 comment

Comments

@ahmet-celik
Copy link

I am using this library in one of my projects. It is very convenient, and simple.
However, I am not sure why vertical bar (|) is treated in a special way. Could you provide the complete grammar of the s-expression you recognize?

Thanks,
Ahmet

@lvijay
Copy link

lvijay commented Nov 1, 2020

The | is a secondary escape mechanism. With just quotes, there's no way to include an atom that contains a " (double quote). The below code helps illustrate:

import static de.tudresden.inf.lat.jsexp.SexpFactory.parse;

import de.tudresden.inf.lat.jsexp.SexpParserException;

public class Foo {
    public static void main(String[] args) throws SexpParserException {
        String s1 = "abcd";      // normal
        String s2 = "a\"bcd";    // error, missing quotation mark
        String s3 = "a|bcd";     // error (unhelpfully throws NPE)
        String s4 = "|ab\"cd|";  // how to include a "
        String s5 = "\"ab|cd\""; // how to include a |

        System.out.println(parse(s1));
        try {
            parse(s2);
        } catch (SexpParserException e) {
            System.out.println("expected");
        }
        try {
            System.out.println(parse(s3));
        } catch (SexpParserException e) {
            System.out.println("expected but not encountered");
        } catch (NullPointerException e) {
            System.out.println("it is what it is");
        }
        System.out.println(parse(s4));
        System.out.println(parse(s5));
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants