<commit_before>grammar Occi;

options {
  language = Java;
}

@header {
    package occi.lexpar;
    import java.util.HashMap;
    import java.util.ArrayList;
}

@lexer::header {
  package occi.lexpar;
}

@members{

  static String occi_categories = "occi.categories";
  static String occi_links = "occi.links";
  static String occi_attributes = "occi.attributes";
  static String occi_locations = "occi.locations";
  static String occi_core_term = "occi.core.term";
  static String occi_core_scheme = "occi.core.scheme";
  static String occi_core_class = "occi.core.class";
  static String occi_core_class_kind = "kind";
  static String occi_core_class_mixin = "mixin";
  static String occi_core_class_action = "action";
  static String occi_core_title = "occi.core.title";
  static String occi_core_rel = "occi.core.rel";
  static String occi_core_location = "occi.core.location";
  static String occi_core_attributes = "occi.core.attributes";
  static String occi_core_actions = "occi.core.actions";
  static String occi_core_target = "occi.core.target";
  static String occi_core_actionterm = "occi.core.actionterm";
  static String occi_core_self = "occi.core.self";
  static String occi_core_category = "occi.core.category";
}

headers                returns [HashMap values] :
                         (category | link | attribute | location)*
                         {
                           $values = new HashMap();

                           if($category.cats != null)
                             $values.put(occi_categories, $category.cats);

                           if($link.link != null)
                             $values.put(occi_links, $link.link);<commit_msg>added convienience method to get a parser instance from Occi.g<commit_after>grammar Occi;

options {
  language = Java;
}

@header {
    package occi.lexpar;
    import java.util.HashMap;
    import java.util.ArrayList;
}

@lexer::header {
  package occi.lexpar;
}

@members{

  static String occi_categories = "occi.categories";
  static String occi_links = "occi.links";
  static String occi_attributes = "occi.attributes";
  static String occi_locations = "occi.locations";
  static String occi_core_term = "occi.core.term";
  static String occi_core_scheme = "occi.core.scheme";
  static String occi_core_class = "occi.core.class";
  static String occi_core_class_kind = "kind";
  static String occi_core_class_mixin = "mixin";
  static String occi_core_class_action = "action";
  static String occi_core_title = "occi.core.title";
  static String occi_core_rel = "occi.core.rel";
  static String occi_core_location = "occi.core.location";
  static String occi_core_attributes = "occi.core.attributes";
  static String occi_core_actions = "occi.core.actions";
  static String occi_core_target = "occi.core.target";
  static String occi_core_actionterm = "occi.core.actionterm";
  static String occi_core_self = "occi.core.self";
  static String occi_core_category = "occi.core.category";

  public static OcciParser getParser(String occiHeader) throws Exception {

    CharStream stream = new ANTLRStringStream(occiHeader);
    OcciLexer lexer = new OcciLexer(stream);
    CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    OcciParser parser = new OcciParser(tokenStream);

    if(parser.getNumberOfSyntaxErrors() > 0)
      throw new Exception("Errors (" + parser.getNumberOfSyntaxErrors() + ") in parsing the input string");

    return parser;
  }
}

headers                returns [HashMap values] :
                         (category | link | attribute | location)*
                         {
                           $values = new HashMap();

                           if($category.cats != null)
                             $values.put(occi_categories, $category.cats);

                           if($link.link != null)
                             $values.put(occi_links, $link.link);
{'fraction_non_alphanumeric': 0.10094798872662054, 'fraction_numerical': 0.00025621316935690495, 'mean_word_length': 2.904, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3346404', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1181, 'n_words': 266}