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

Draft version of OCaml indexer. #4753

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.opengrok.indexer.analysis.kotlin.KotlinAnalyzerFactory;
import org.opengrok.indexer.analysis.lisp.LispAnalyzerFactory;
import org.opengrok.indexer.analysis.lua.LuaAnalyzerFactory;
import org.opengrok.indexer.analysis.ocaml.OCamlAnalyzerFactory;
import org.opengrok.indexer.analysis.pascal.PascalAnalyzerFactory;
import org.opengrok.indexer.analysis.perl.PerlAnalyzerFactory;
import org.opengrok.indexer.analysis.php.PhpAnalyzerFactory;
Expand Down Expand Up @@ -298,6 +299,7 @@ public class AnalyzerGuru {
new HaskellAnalyzerFactory(),
new GolangAnalyzerFactory(),
new LuaAnalyzerFactory(),
new OCamlAnalyzerFactory(),
new PascalAnalyzerFactory(),
new AdaAnalyzerFactory(),
new RubyAnalyzerFactory(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/

/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, 2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.ocaml;

import java.util.HashSet;
import java.util.Set;

/**
* Represents a container for a set of OCaml keywords.
*/
public class Consts {

static final Set<String> kwd = new HashSet<>();

/* From parsing/lexer.mll of OCaml 5.3.0. */
static {
kwd.add("and");
kwd.add("as");
kwd.add("assert");
kwd.add("begin");
kwd.add("class");
kwd.add("constraint");
kwd.add("do");
kwd.add("done");
kwd.add("downto");
kwd.add("effect");
kwd.add("else");
kwd.add("end");
kwd.add("exception");
kwd.add("external");
kwd.add("false");
kwd.add("for");
kwd.add("fun");
kwd.add("function");
kwd.add("functor");
kwd.add("if");
kwd.add("in");
kwd.add("include");
kwd.add("inherit");
kwd.add("initializer");
kwd.add("lazy");
kwd.add("let");
kwd.add("match");
kwd.add("method");
kwd.add("module");
kwd.add("mutable");
kwd.add("new");
kwd.add("nonrec");
kwd.add("object");
kwd.add("of");
kwd.add("open");
kwd.add("or");
kwd.add("parser");
kwd.add("private");
kwd.add("rec");
kwd.add("sig");
kwd.add("struct");
kwd.add("then");
kwd.add("to");
kwd.add("true");
kwd.add("try");
kwd.add("type");
kwd.add("val");
kwd.add("virtual");
kwd.add("when");
kwd.add("while");
kwd.add("with");
kwd.add("lor");
kwd.add("lxor");
kwd.add("mod");
kwd.add("land");
kwd.add("lsl");
kwd.add("lsr");
kwd.add("asr");
}

/** Private to enforce static. */
private Consts() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/

/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, 2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.ocaml;

import org.opengrok.indexer.analysis.AbstractAnalyzer;
import org.opengrok.indexer.analysis.FileAnalyzerFactory;
import org.opengrok.indexer.analysis.JFlexTokenizer;
import org.opengrok.indexer.analysis.JFlexXref;
import org.opengrok.indexer.analysis.plain.AbstractSourceCodeAnalyzer;

import java.io.Reader;

/**
* Represents an analyzer for the OCaml language.
*/
@SuppressWarnings("java:S110")
public class OCamlAnalyzer extends AbstractSourceCodeAnalyzer {

/**
* Creates a new instance of {@link OCamlAnalyzer}.
* @param factory instance
*/
protected OCamlAnalyzer(FileAnalyzerFactory factory) {
super(factory, () -> new JFlexTokenizer(new OCamlSymbolTokenizer(
AbstractAnalyzer.DUMMY_READER)));
}

/**
* @return {@code "ocaml"}
*/
@Override
public String getCtagsLang() {
return "ocaml";
}

/**
* Gets a version number to be used to tag processed documents so that
* re-analysis can be re-done later if a stored version number is different
* from the current implementation.
* @return 20250403_00
*/
@Override
protected int getSpecializedVersionNo() {
return 20250403_00; // Edit comment above too!
}

/**
* Creates a wrapped {@link OCamlXref} instance.
* @return a defined instance
*/
@Override
protected JFlexXref newXref(Reader reader) {
return new JFlexXref(new OCamlXref(reader));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/

/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, 2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.ocaml;

import org.opengrok.indexer.analysis.AbstractAnalyzer.Genre;
import org.opengrok.indexer.analysis.FileAnalyzer;
import org.opengrok.indexer.analysis.FileAnalyzerFactory;

/**
* Represents a factory to create {@link OCamlAnalyzer} instances.
*/
public class OCamlAnalyzerFactory extends FileAnalyzerFactory {

private static final String NAME = "OCaml";

private static final String[] SUFFIXES = {"ML", "MLI"};

/**
* Initializes a factory instance to associate a file extensions ".ml",
* ".mli" with {@link OCamlAnalyzer}.
*/
public OCamlAnalyzerFactory() {
super(null, null, SUFFIXES, null, null, "text/plain", Genre.PLAIN,
NAME, true);
}

/**
* Creates a new {@link OCamlAnalyzer} instance.
* @return a defined instance
*/
@Override
protected FileAnalyzer newAnalyzer() {
return new OCamlAnalyzer(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/

/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, 2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.ocaml;

import org.opengrok.indexer.analysis.JFlexJointLexer;
import org.opengrok.indexer.analysis.JFlexSymbolMatcher;
import org.opengrok.indexer.analysis.Resettable;

/**
* Represents an abstract base class for OCaml lexers.
*/
@SuppressWarnings("Duplicates")
abstract class OCamlLexer extends JFlexSymbolMatcher
implements JFlexJointLexer, Resettable {

/**
* Calls {@link #phLOC()} if the yystate is not COMMENT or SCOMMENT.
*/
public void chkLOC() {
if (yystate() != COMMENT() && yystate() != SCOMMENT()) {
phLOC();
}
}

/**
* Subclasses must override to get the constant value created by JFlex to
* represent COMMENT.
*/
@SuppressWarnings("java:S100")
abstract int COMMENT();

/**
* Subclasses must override to get the constant value created by JFlex to
* represent SCOMMENT.
*/
@SuppressWarnings("java:S100")
abstract int SCOMMENT();
}
Loading