Skip to content

Commit

Permalink
Added a record variant declarations to the parsers.
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthkuruvila committed Jun 18, 2018
1 parent 1bbc6c1 commit 6468cce
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
2 changes: 1 addition & 1 deletion parser/OcamlLexer.flex
Expand Up @@ -277,4 +277,4 @@ KEY_CHARACTER=[^:=\ \n\r\t\f\\] | "\\ "



[^] { System.out.println("Bad char:" + yytext()); return BAD_CHARACTER; } //Copied this need to know how it works
[^] { return BAD_CHARACTER; } //Copied this need to know how it works
2 changes: 1 addition & 1 deletion parser/ocaml.bnf
Expand Up @@ -1094,7 +1094,7 @@ generalized_constructor_arguments ::=

constructor_arguments ::=
core_type_list
// | LBRACE label_declarations RBRACE
| LBRACE label_declarations RBRACE
//
label_declarations ::=
label_declaration (SEMI attributes ? label_declaration) * (SEMI attributes ?)?
Expand Down
Expand Up @@ -11,7 +11,7 @@ import org.ocaml.util.ReversedSubstringCharSequence

class OcamlCompletionContributor : CompletionContributor() {

val merlinService = ApplicationManager.getApplication().getComponent(MerlinServiceComponent::class.java)
val merlinService = ApplicationManager.getApplication().getComponent(MerlinServiceComponent::class.java)!!

init {

Expand All @@ -24,17 +24,17 @@ class OcamlCompletionContributor : CompletionContributor() {
val completions = merlinService.completions(parameters.originalFile,
findSuitablePrefix(parameters), ln.position(parameters.offset))
for(completion in completions) {
resultSet.addElement(LookupElementBuilder.create(completion.name).withTypeText(completion.desc));
resultSet.addElement(LookupElementBuilder.create(completion.name).withTypeText(completion.desc))
}
}
})
}

fun findSuitablePrefix(parameters: CompletionParameters): String {
private fun findSuitablePrefix(parameters: CompletionParameters): String {
return findEmacsOcamlAtom(parameters.originalFile.text, parameters.originalPosition!!.textOffset)?:""
}

fun findEmacsOcamlAtom(text:String, offset: Int): String? {
private fun findEmacsOcamlAtom(text:String, offset: Int): String? {
val re = Regex("[a-zA-Z0-9.']*[~?]?")
val endIndex = re.find(ReversedSubstringCharSequence(text, offset, 0))?.next()?.range?.last

Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/org/ocaml/lang/parser/SimpleExpressions.ml
Expand Up @@ -155,5 +155,7 @@ type t = [
| `B of string
]

type t = Record of {a: int; b: string}



53 changes: 53 additions & 0 deletions src/test/resources/org/ocaml/lang/parser/SimpleExpressions.txt
Expand Up @@ -3149,5 +3149,58 @@ FILE
PsiElement(LIDENT)('string')
PsiWhiteSpace('\n ')
PsiElement(RBRACKET)(']')
PsiWhiteSpace('\n\n')
ConstraintsImpl(CONSTRAINTS)
<empty list>
StructureItemImpl(STRUCTURE_ITEM)
TypeDeclarationsImpl(TYPE_DECLARATIONS)
TypeDeclarationImpl(TYPE_DECLARATION)
PsiElement(TYPE)('type')
PsiWhiteSpace(' ')
PsiElement(LIDENT)('t')
PsiWhiteSpace(' ')
TypeKindImpl(TYPE_KIND)
PsiElement(EQUAL)('=')
PsiWhiteSpace(' ')
ConstructorDeclarationsImpl(CONSTRUCTOR_DECLARATIONS)
ConstructorDeclarationImpl(CONSTRUCTOR_DECLARATION)
ConstrIdentImpl(CONSTR_IDENT)
PsiElement(UIDENT)('Record')
PsiWhiteSpace(' ')
GeneralizedConstructorArgumentsImpl(GENERALIZED_CONSTRUCTOR_ARGUMENTS)
PsiElement(OF)('of')
PsiWhiteSpace(' ')
ConstructorArgumentsImpl(CONSTRUCTOR_ARGUMENTS)
PsiElement(LBRACE)('{')
LabelDeclarationsImpl(LABEL_DECLARATIONS)
LabelDeclarationImpl(LABEL_DECLARATION)
LabelImpl(LABEL)
PsiElement(LIDENT)('a')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
PolyTypeNoAttrImpl(POLY_TYPE_NO_ATTR)
CoreTypeNoAttrImpl(CORE_TYPE_NO_ATTR)
CoreType2Impl(CORE_TYPE_2)
SimpleCoreTypeOrTupleImpl(SIMPLE_CORE_TYPE_OR_TUPLE)
SimpleCoreTypeImpl(SIMPLE_CORE_TYPE)
SimpleCoreType2Impl(SIMPLE_CORE_TYPE_2)
TypeLongidentImpl(TYPE_LONGIDENT)
PsiElement(LIDENT)('int')
PsiElement(SEMI)(';')
PsiWhiteSpace(' ')
LabelDeclarationImpl(LABEL_DECLARATION)
LabelImpl(LABEL)
PsiElement(LIDENT)('b')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
PolyTypeNoAttrImpl(POLY_TYPE_NO_ATTR)
CoreTypeNoAttrImpl(CORE_TYPE_NO_ATTR)
CoreType2Impl(CORE_TYPE_2)
SimpleCoreTypeOrTupleImpl(SIMPLE_CORE_TYPE_OR_TUPLE)
SimpleCoreTypeImpl(SIMPLE_CORE_TYPE)
SimpleCoreType2Impl(SIMPLE_CORE_TYPE_2)
TypeLongidentImpl(TYPE_LONGIDENT)
PsiElement(LIDENT)('string')
PsiElement(RBRACE)('}')
ConstraintsImpl(CONSTRAINTS)
<empty list>

0 comments on commit 6468cce

Please sign in to comment.