From 00d6182c9d9617b079f4a437b8e6f1f88b040e01 Mon Sep 17 00:00:00 2001 From: Sven Gestegard Robertz <sven.robertz@cs.lth.se> Date: Thu, 30 Apr 2015 12:22:20 +0200 Subject: [PATCH] added experimental docstring annotation --- compiler/2014/LabComm.ast | 2 -- compiler/2014/LabCommParser.parser | 20 +++++++++++--------- compiler/2014/LabCommScanner.flex | 3 +++ compiler/2014/Signature.jrag | 14 +++++++++++++- examples/user_types/test.lc | 2 +- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/compiler/2014/LabComm.ast b/compiler/2014/LabComm.ast index f1fd5c0..a89b9c6 100644 --- a/compiler/2014/LabComm.ast +++ b/compiler/2014/LabComm.ast @@ -2,8 +2,6 @@ Specification ::= Decl*; abstract Decl ::= TypeInstance /Signature/; -TypeInstance ::= DataType <Name:String> Intention*; - TypeDecl : Decl; SampleDecl : Decl; diff --git a/compiler/2014/LabCommParser.parser b/compiler/2014/LabCommParser.parser index 3575ee2..f95ca89 100644 --- a/compiler/2014/LabCommParser.parser +++ b/compiler/2014/LabCommParser.parser @@ -54,25 +54,27 @@ List var_decl_list = | var_decl_list.l var_decl.v {: return l.add(v); :} ; -List intentions = +List annotations = /* empty list */ {: return new List(); :} - | intention_list.l {: return l; :} + | annotation_list.l {: return l; :} ; -List intention_list = - intention.i {: return new List().add(i); :} - | intention_list.l intention.i {: return l.add(i); :} +List annotation_list = + annotation.i {: return new List().add(i); :} + | annotation_list.l annotation.i {: return l.add(i); :} ; String key = IDENTIFIER; String stringliteral = IDENTIFIER; -Annotation intention = LPAREN key.k COLON stringliteral.v RPAREN {: return new Annotation(k,v); :}; +Annotation annotation = intention.i | docstring.d; +Annotation intention = LPAREN key.k COLON stringliteral.v RPAREN {: return new Intention(k,v); :}; +Annotation docstring = QUOTEDSTRING.s {: return new DocString(s.substring(1,s.length()-1)); :}; TypeInstance type_instance = - intentions.i type.t IDENTIFIER {: return new TypeInstance(t, IDENTIFIER, i); :} - | intentions.i type.t IDENTIFIER dim_list.d - {: return new TypeInstance(new ParseArrayType(t, d), IDENTIFIER, i); :} + annotations.a type.t IDENTIFIER {: return new TypeInstance(t, IDENTIFIER, a); :} + | annotations.a type.t IDENTIFIER dim_list.d + {: return new TypeInstance(new ParseArrayType(t, d), IDENTIFIER, a); :} ; Field var_decl = diff --git a/compiler/2014/LabCommScanner.flex b/compiler/2014/LabCommScanner.flex index 6d4f7c1..0b28eff 100644 --- a/compiler/2014/LabCommScanner.flex +++ b/compiler/2014/LabCommScanner.flex @@ -52,6 +52,8 @@ Digits = {Digit}+ Digit = 0 | {NonZeroDigit} NonZeroDigit = [1-9] +QuotedString = "\"" {InputCharacter}* "\"" + %% <YYINITIAL> { @@ -84,6 +86,7 @@ NonZeroDigit = [1-9] "," { return sym(Terminals.COMMA); } {Identifier} { return sym(Terminals.IDENTIFIER); } + {QuotedString} { return sym(Terminals.QUOTEDSTRING); } } // fall through errors diff --git a/compiler/2014/Signature.jrag b/compiler/2014/Signature.jrag index 89010e7..6cba875 100644 --- a/compiler/2014/Signature.jrag +++ b/compiler/2014/Signature.jrag @@ -8,6 +8,18 @@ aspect Annotations { TypeInstance contributes getAnnotationString() to Decl.allAnnotations() for parentDecl(); + + public DocString.DocString(String s) { + super("DOCSTRING", s); + } + + public String Intention.toString() { + return("("+getKey()+" : "+getValue()+") "); + } + + public String DocString.toString() { + return "\""+getValue()+"\""; + } } aspect Signature { @@ -41,7 +53,7 @@ aspect Signature { StringBuilder sb = new StringBuilder(); List<Annotation> ints = getAnnotationList(); for(Annotation i : ints) { - sb.append("("+i.getKey()+" : "+i.getValue()+") "); + sb.append(i.toString()); } return sb.toString(); } diff --git a/examples/user_types/test.lc b/examples/user_types/test.lc index a0ad602..05b94c9 100644 --- a/examples/user_types/test.lc +++ b/examples/user_types/test.lc @@ -7,7 +7,7 @@ typedef int anInt; typedef void avoid; sample (function:trigger)(foo:bar) avoid doavoid; -sample (a:b) struct { +sample (a:b) "a struct with an int and a ref" struct { (c:d)(e:f) int x; sample reference; } intAndRef; -- GitLab