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

EditorConfig validator: support for line/column, offset info with ParsingException #9

Open
angelozerr opened this issue May 26, 2016 · 3 comments

Comments

@angelozerr
Copy link

angelozerr commented May 26, 2016

It should be cool if we could have an utility method validate which waits a String content of an editorconfig and throws ParsingException when this content is not well formatted:

public class  EditorConfig {

....
  public void validate(String editorConfigContent) throws ParsingException {
    // here parse editorConfigContent and throws ParsingException  with line/column, offset info
  }
}

Here a sample with miss of close of [ for section names:

[*]
charset = utf-8

[*.md // <- here there is an error because section is not closed

The exception ParsingException should contains offset and line/column info where there is an error.

With this utility method validate, any IDE could support validation with marker.

Many thanks!

@angelozerr angelozerr changed the title Support for line/column, offset info with ParsingException EditorConfig validator: support for line/column, offset info with ParsingException May 26, 2016
@angelozerr
Copy link
Author

angelozerr commented May 26, 2016

As I have worked about this topic several month ago, I have pushed my POC at https://github.com/angelozerr/editorconfig-java-parser

You can find a very basic demo which uses the parser:

EditorConfigDemo

If you are interested tell me.

@xuhdev
Copy link
Member

xuhdev commented May 27, 2016

@angelozerr Thanks for your validator! The syntax validator is definitely useful. However, the core library should not validate any property/value names, as the editor plugins should be able to make some extensions on their own, without modifying core libraries.

@angelozerr
Copy link
Author

@angelozerr Thanks for your validator!

Glad this idea please you.

However, the core library should not validate any property/value names,

The parser DO NOT that. It throws an exception if section is not closed, etc, but it doesn't validate option name, value.

as the editor plugins should be able to make some extensions on their own, without modifying core libraries.

At first, the EditorConfig parser is a parser of editorconfig content. You can compare it to SAX parser which works with handler. See https://github.com/angelozerr/editorconfig-java-parser/blob/master/fr.opensagres.editorconfig/src/fr/opensagres/editorconfig/handlers/EditorConfigHandler.java

The parser is able to call those events. So after that you can implement handler like you wish:

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