Commit 0b3e5b80 authored by Miklos Magyari's avatar Miklos Magyari Committed by Arpad Lovassy
Browse files

added document comment lexer and helper class


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent ac95e140
......@@ -74,6 +74,7 @@
@java %ANTLR% Ttcn3Parser.g4 -no-listener -no-visitor -encoding UTF-8 -package org.eclipse.titan.designer.parsers.ttcn3parser
@java %ANTLR% Ttcn3Reparser.g4 -no-listener -no-visitor -encoding UTF-8 -package org.eclipse.titan.designer.parsers.ttcn3parser
@java %ANTLR% PatternStringLexer.g4 -no-listener -no-visitor -encoding UTF-8 -package org.eclipse.titan.designer.parsers.ttcn3parser
@java %ANTLR% Ttcn3DocCommentLexer.g4 -no-listener -no-visitor -encoding UTF-8 -package org.eclipse.titan.designer.parsers.ttcn3parser
@REM Extension attribute
@echo Compiling ext attr
......
......@@ -165,7 +165,8 @@
<include name="ttcn3parser/Ttcn3CharstringLexer.g4" />
<include name="ttcn3parser/Ttcn3Parser.g4" />
<include name="ttcn3parser/Ttcn3Reparser.g4" />
<include name= "ttcn3parser/PatternStringLexer.g4" />
<include name="ttcn3parser/PatternStringLexer.g4" />
<include name="ttcn3parser/Ttcn3DocCommentLexer.g4" />
<!-- TODO: add new g4 files here -->
</fileset>
</apply>
......
package org.eclipse.titan.designer.AST;
import java.io.Reader;
import java.io.StringReader;
import java.util.List;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CommonTokenFactory;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.UnbufferedCharStream;
import org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3DocCommentLexer;
/**
* A helper class for documentation comment handling
*
* ETSI ES 201 873-10 V4.5.1 (2013-04)
*
* @author Miklos Magyari
*
*/
public class DocumentComment implements ILocateableNode {
/* Raw text of the comment */
private String comment;
/* First and last tokens of the comment */
private Token first;
private Token last;
/* Location of the document comment.
*
* For now, all semantic problems will be reported for the whole comment.
**/
private Location location;
public DocumentComment(String comment, Token first, Token last) {
this.comment = comment;
this.first = first;
this.last = last;
}
public Token getFirstToken() {
return first;
}
public Token getLastToken() {
return last;
}
@Override
public void setLocation(Location location) {
this.location = location;
}
@Override
public Location getLocation() {
return location;
}
public void parseComment() {
final Reader reader = new StringReader(comment);
final CharStream charStream = new UnbufferedCharStream(reader);
final Ttcn3DocCommentLexer lexer = new Ttcn3DocCommentLexer(charStream);
lexer.setTokenFactory(new CommonTokenFactory(true));
final List<? extends Token> tokens = lexer.getAllTokens();
}
}
......@@ -32,6 +32,7 @@ import org.eclipse.titan.designer.Activator;
import org.eclipse.titan.designer.GeneralConstants;
import org.eclipse.titan.designer.AST.ASTVisitor;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.DocumentComment;
import org.eclipse.titan.designer.AST.FieldSubReference;
import org.eclipse.titan.designer.AST.IType;
import org.eclipse.titan.designer.AST.Identifier;
......@@ -114,6 +115,9 @@ public abstract class Definition extends Assignment implements IAppendableSyntax
private static boolean markOccurrences;
/** Optional documentation comment according to ETSI ES 201 873-10 */
private DocumentComment documentComment = null;
static {
final IPreferencesService ps = Platform.getPreferencesService();
if ( ps != null ) {
......@@ -172,7 +176,15 @@ public abstract class Definition extends Assignment implements IAppendableSyntax
public final Location getVisibilityModifierLocation() {
return visibilityLocation;
}
/** Sets the documentation comment for this definition (ETSI ES 201 873-10 format)
*
* @param docComment
*/
public void setDocumentComment(DocumentComment docComment) {
documentComment = docComment;
}
/**
* Sets the with attributes for this definition if it has any. Also
* creates the with attribute path, to store the attributes in.
......
lexer grammar Ttcn3DocCommentLexer;
/*
******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
******************************************************************************
*/
/*
* author Miklos Magyari
*/
BLOCK_BEGIN: '/**' '*'* ;
BLOCK_END: '*/' ;
WS: [ \t]+ ;
STAR: '*' ;
NEWLINE: (WS* STAR WS*)? '\r'? '\n' (WS? (STAR { _input.LA(1) != '/'}?)+)?;
FREETEXTCHAR: [\u0020-\u0029\u002b-\u003f\u0041-\u007e\u00a1-\u00ac\u00ae-\u00ff]
| '*'{ _input.LA(1) != '/'}? ;
IDENTIFIER: [A-Z][A-Za-z0-9_]* ;
FREETEXT: ('@@' | FREETEXTCHAR)+ ;
LINE_BEGIN: '//*' ;
LINE: WS* LINE_BEGIN STAR* WS* ;
AUTHOR: '@author' WS+ FREETEXT ;
PARAM: '@param' WS+ FREETEXT ;
SINCE: '@since' WS+ FREETEXT ;
/*
CONFIG: '@config' ;
DESC: '@desc' ;
EXCEPTION: '@exception' ;
MEMBER: '@member' ;
PURPOSE: '@purpose' ;
REMARK: '@remark' ;
RETURN: '@return' ;
SEE: '@see' ;
STATUS: '@status' ;
URL: '@url' ;
VERDICT: '@verdict' ;
VERSION: '@version' ;
PRIORITY: '@priority' ;
REQUIREMENT: '@requirement' ;
REFERENCE: '@reference' ;
*/
\ No newline at end of file
......@@ -284,10 +284,14 @@ public void reset() {
*
* Both single line and multiline doc comments are supported
*/
public String getDocCommentText() {
public DocumentComment getDocumentComment() {
BufferedTokenStream stream = (BufferedTokenStream)_input;
Token start = _ctx.getStart();
Token first = null;
Token last = null;
List<Token> t = null;
DocumentComment dc;
if (start != null) {
int pos = start.getTokenIndex();
......@@ -310,10 +314,13 @@ public String getDocCommentText() {
}
prev = t.get(len - 2);
if (prev.getType() == BLOCK_DOCUMENT) {
return prev.getText();
dc = new DocumentComment(prev.getText(), prev, prev);
dc.setLocation(getLocation(prev));
return dc;
}
StringBuilder builder = new StringBuilder();
boolean stop = false;
last = prev;
for (int i = len - 2; !stop && i >= 0; i--) {
prev = t.get(i);
switch (prev.getType()) {
......@@ -321,13 +328,18 @@ public String getDocCommentText() {
case WS:
continue;
case LINE_DOCUMENT:
first = prev;
builder.insert(0, prev.getText() + "\n");
break;
default:
stop = true;
}
}
return builder.length() > 0 ? builder.toString() : null;
if (builder.length() > 0) {
dc = new DocumentComment(builder.toString(), first, last);
dc.setLocation(getLocation(first, last));
return dc;
}
}
return null;
}
......@@ -522,7 +534,7 @@ pr_TTCN3Module
MultipleWithAttributes attributes = null;
List<String> languageSpecifications = null;
String docComment = getDocCommentText();
DocumentComment docComment = getDocumentComment();
}:
( m = pr_TTCN3ModuleKeyword { col = $m.start; }
i = pr_TTCN3ModuleId { act_ttcn3_module = new TTCN3Module( $i.identifier, project ); }
......@@ -545,7 +557,7 @@ pr_TTCN3Module
controlpart.setAttributeParentPath( act_ttcn3_module.getAttributePath() );
}
// if (docComment != null) {
// // act_ttcn3_module.setDocumentationComment(docComment);
// // act_ttcn3_module.setDocumentatComment(docComment);
// }
};
......@@ -2853,7 +2865,7 @@ pr_FunctionDef returns[Def_Function def_func]
boolean isControl = false;
Location modifierLocation;
String docComment = getDocCommentText();
DocumentComment docComment = getDocumentComment();
}:
( col = pr_FunctionKeyword
fm = pr_FunctionModifier {
......@@ -2895,7 +2907,7 @@ pr_FunctionDef returns[Def_Function def_func]
$def_func.setLocation(getLocation( $col.start, $s.stop));
$def_func.setCommentLocation( getLastCommentLocation( $start ) );
if (docComment != null) {
// $def_func.setDocumentationComment(docComment);
$def_func.setDocumentComment(docComment);
}
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment