Commit eb0ae2b4 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Implemented document comment parser; lexer improvements


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent c9785386
......@@ -75,6 +75,7 @@
@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
@java %ANTLR% Ttcn3DocCommentParser.g4 -no-listener -no-visitor -encoding UTF-8 -package org.eclipse.titan.designer.parsers.ttcn3parser
@REM Extension attribute
@echo Compiling ext attr
......
......@@ -167,6 +167,7 @@
<include name="ttcn3parser/Ttcn3Reparser.g4" />
<include name="ttcn3parser/PatternStringLexer.g4" />
<include name="ttcn3parser/Ttcn3DocCommentLexer.g4" />
<include name="ttcn3parser/Ttcn3DocCommentParser.g4" />
<!-- TODO: add new g4 files here -->
</fileset>
</apply>
......
......@@ -2,12 +2,18 @@ package org.eclipse.titan.designer.AST;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CommonTokenFactory;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.UnbufferedCharStream;
import org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3DocCommentLexer;
import org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3DocCommentParser;
/**
* A helper class for documentation comment handling
......@@ -31,6 +37,17 @@ public class DocumentComment implements ILocateableNode {
**/
private Location location;
private List<String> authors = new ArrayList<String>();
private List<String> configs = new ArrayList<String>();
private List<String> descs = new ArrayList<String>();
private Map<String,String> exceptions = new HashMap<String, String>();
private Map<String,String> members = new HashMap<String, String>();
private Map<String,String> params = new HashMap<String, String>();
private String purpose = null;
private String return_ = null;
private String since = null;
private List<String> remarks = new ArrayList<String>();
public DocumentComment(String comment, Token first, Token last) {
this.comment = comment;
this.first = first;
......@@ -55,12 +72,67 @@ public class DocumentComment implements ILocateableNode {
return location;
}
public void addAuthor(String text) {
authors.add(text.trim());
}
public void addConfig(String text) {
configs.add(text.trim());
}
public void addParam(String id, String text) {
if (id != null) {
params.put(id.trim(), text.trim());
}
}
public void addDesc(String text) {
descs.add(text.trim());
}
public void addSince(String text) {
if (since == null) {
since = text.trim();
}
}
public void addPurpose(String text) {
if (purpose == null) {
purpose = text.trim();
}
}
public void addException(String id, String text) {
if (id != null) {
exceptions.put(id.trim(), text.trim());
}
}
public void addMember(String id, String text) {
if (id != null) {
members.put(id.trim(), text.trim());
}
}
public void addRemark(String text) {
remarks.add(text.trim());
}
public void addReturn(String text) {
if (return_ == null) {
return_ = text.trim();
}
}
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));
// List<? extends Token> tokens = lexer.getAllTokens();
final List<? extends Token> tokens = lexer.getAllTokens();
final CommonTokenStream cts = new CommonTokenStream(lexer);
final Ttcn3DocCommentParser parser = new Ttcn3DocCommentParser(cts);
parser.pr_DocComment(this);
}
}
......@@ -183,6 +183,7 @@ public abstract class Definition extends Assignment implements IAppendableSyntax
*/
public void setDocumentComment(DocumentComment docComment) {
documentComment = docComment;
//documentComment.parseComment();
}
/**
......
......@@ -22,3 +22,7 @@
/Ttcn3ReparserListener.java
/PatternStringLexer.java
/PatternStringLexer.tokens
/Ttcn3DocCommentLexer.java
/Ttcn3DocCommentLexer.tokens
/Ttcn3DocCommentParser.java
/Ttcn3DocCommentParser.tokens
\ No newline at end of file
......@@ -11,46 +11,43 @@ lexer grammar Ttcn3DocCommentLexer;
*/
/*
* Lexer grammar for documentation comments (ETSI ES 201 873-10 V4.5.1)
*
* author Miklos Magyari
*/
BLOCK_BEGIN: '/**' '*'* ;
BLOCK_BEGIN: '/**' ;
BLOCK_END: '*/' ;
WS: [ \t]+ ;
AUTHOR: '@author' WS;
DESC: '@desc' WS;
PARAM: '@param' WS;
SINCE: '@since'WS;
CONFIG: '@config' WS;
EXCEPTION: '@exception' WS;
MEMBER: '@member' WS;
PURPOSE: '@purpose' WS;
REMARK: '@remark' WS;
RETURN: '@return' WS;
SEE: '@see' WS;
STATUS: '@status' WS;
URL: '@url' WS;
VERDICT: '@verdict' WS;
VERSION: '@version' WS;
PRIORITY: '@priority' WS;
REQUIREMENT: '@requirement' WS;
REFERENCE: '@reference' WS;
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-Za-z][A-Za-z0-9_]* ;
IDENTIFIER: [A-Z][A-Za-z0-9_]* ;
FREETEXTCHAR: [\u0021-\u0029\u002b-\u003f\u0041-\u007e\u00a1-\u00ac\u00ae-\u00ff]
| '*'{ _input.LA(1) != '/'}? ;
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
parser grammar Ttcn3DocCommentParser;
/*
******************************************************************************
* 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
******************************************************************************
*/
/*
* Parser grammar for documentation comments (ETSI ES 201 873-10 V4.5.1)
*
* author Miklos Magyari
*/
options {
tokenVocab=Ttcn3DocCommentLexer;
}
@header
{
import java.lang.StringBuilder;
import org.eclipse.titan.designer.AST.*;
}
pr_DocComment[DocumentComment documentComment]:
( pr_BlockComment[documentComment]
| pr_LineComments
);
pr_BlockComment[DocumentComment documentComment]:
BLOCK_BEGIN
( pr_Tag[documentComment]
| WS
| NEWLINE
| IDENTIFIER
| FREETEXT
)*
BLOCK_END
;
pr_LineComments:
LINE
;
pr_AuthorTag[DocumentComment documentComment]:
AUTHOR
txt = pr_FreeText { documentComment.addAuthor( $txt.text ); }
;
pr_ConfigTag[DocumentComment documentComment]:
CONFIG
txt = pr_FreeText { documentComment.addConfig( $txt.text ); }
;
pr_DescTag[DocumentComment documentComment]:
DESC
txt = pr_FreeText { documentComment.addDesc( $txt.text ); }
;
pr_ExceptionTag[DocumentComment documentComment]
@init {
String freetext = null;
}:
EXCEPTION
id = pr_Identifier
( ft = pr_FreeText { freetext = $ft.text; } )?
{
documentComment.addException( $id.text, freetext );
};
pr_MemberTag[DocumentComment documentComment]
@init {
String freetext = null;
}:
MEMBER
id = pr_Identifier
( ft = pr_FreeText { freetext = $ft.text; } )?
{
documentComment.addMember( $id.text, freetext );
};
pr_ParamTag[DocumentComment documentComment]
@init {
String freetext = null;
}:
PARAM
id = pr_Identifier
WS?
( ft = pr_FreeText { freetext = $ft.text; } )?
{
documentComment.addParam( $id.text, freetext );
};
pr_SinceTag[DocumentComment documentComment]:
SINCE
txt = pr_FreeText { documentComment.addSince( $txt.text ); }
;
pr_PurposeTag[DocumentComment documentComment]:
PURPOSE
txt = pr_FreeText { documentComment.addPurpose( $txt.text ); }
;
pr_RemarkTag[DocumentComment documentComment]:
REMARK
txt = pr_FreeText { documentComment.addRemark( $txt.text ); }
;
pr_ReturnTag[DocumentComment documentComment]:
RETURN
txt = pr_FreeText { documentComment.addReturn( $txt.text ); }
;
pr_Tag[DocumentComment documentComment]:
( pr_AuthorTag[documentComment]
| pr_ConfigTag[documentComment]
| pr_DescTag[documentComment]
| pr_ExceptionTag[documentComment]
| pr_MemberTag[documentComment]
| pr_ParamTag[documentComment]
| pr_SinceTag[documentComment]
| pr_PurposeTag[documentComment]
| pr_RemarkTag[documentComment]
| pr_ReturnTag[documentComment]
);
pr_Identifier returns[String text]:
IDENTIFIER { $text = $IDENTIFIER.getText(); }
;
pr_FreeText returns[String text]
@init {
StringBuilder sb = new StringBuilder();
}:
(
( IDENTIFIER { sb.append( $IDENTIFIER.getText()); }
| FREETEXT { sb.append( $FREETEXT.getText()); }
)
( WS { sb.append( $WS.getText() ); } )?
)+
{
$text = sb.toString();
}
;
\ No newline at end of file
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