Xtext 2.8+ formatter, formatting HiddenRegion with comment - eclipse

I am using Xtext 2.9 formatter and I am trying to format hiddenRegion which contains comment. Here is part of my document region i am trying to format:
Columns: 1:offset 2:length 3:kind 4: text 5:grammarElement
Kind: H=IHiddenRegion S=ISemanticRegion B/E=IEObjectRegion
35 0 H
35 15 S ""xxx::a::b"" Refblock:namespace=Namespace
50 0 H
50 1 S "}" Refblock:RCBRACKET
E Refblock PackageHead:Block=Refblock path:PackageHead/Block=Package'xxx_constants'/head=Model/packages[0]
51 0 H
51 1 S ":" PackageHead:COLON
E PackageHead Package:head=PackageHead path:Package'xxx_constants'/head=Model/packages[0]
52 >>>H "\n " Whitespace:TerminalRule'WS'
"# asd" Comment:TerminalRule'SL_COMMENT'
15 "\n " Whitespace:TerminalRule'WS'<<<
B Error'ASSD' Package:expressions+=Expression path:Package'xxx_constants'/expressions[0]=Model/packages[0]
67 5 S "error" Error:'error'
72 1 H " " Whitespace:TerminalRule'WS'
and corresponding part of the grammar
Model:
{Model}
(packages+=Package)*;
Expression:
Error | Warning | Enum | Text;
Package:
{Package}
'package' name=Name head=PackageHead
(BEGIN
(imports+=Import)*
(expressions+=Expression)*
END)?;
Error:
{Error}
('error') name=ENAME parameter=Parameter COLON
(BEGIN
(expressions+=Estatement)+
END)?;
PackageHead:
Block=Refblock COLON;
Problem is that when i try prepend some characters before error keyword
for example
error.regionFor.keyword('error').prepend[setSpace("\n ")]
This indentation is prepended before the comment and not behind it. This results into improper formatting in case of single line comment before the 'error' keyword.
To provide more clarity, here is example code from my grammar and description of desired behavior:
package xxx_constants {namespace="xxx::a::b"}:
# asd
error ASSD {0}:
Hello {0,world}
This is expected result: (one space to the left)
package xxx_constants {namespace="xxx::a::b"}:
# asd
error ASSD {0}:
Hello {0,world}
and this is the actual result with prepend method
package xxx_constants {namespace="xxx::a::b"}:
# asd
error ASSD {0}:
Hello {0,world}
As the document structure says, the HiddenRegion is in this case is the statement:
# asd
error
How can i prepend my characters directly before the keyword 'error' and not before the comment? Thanks.

I assume you're creating an indentation-sensitive language, because you're explicitly calling BEGIN and END.
For indentation-sensitive language my answer is: You'll want to overwrite
org.eclipse.xtext.formatting2.internal.HiddenRegionReplacer.applyHiddenRegionFormatting(List<ITextReplacer>)
The methods append[] and prepend[] you're using are agnostic to comments and at a later time applyHiddenRegionFormatting() is called to decide how that formatting is weaved between comments.
To make Xtext use your own subclass of HiddenRegionReplacer, overwrite
org.eclipse.xtext.formatting2.AbstractFormatter2.createHiddenRegionReplacer(IHiddenRegion, IHiddenRegionFormatting)
For languages that do not do whitespace-sensitive lexing/parsing (that's the default) the answer is to not call setSpace() to create indentation or line-wraps.
Instead, do
pkg.interior[indent]
pkg.regionFor.keyword(":").append[newLine]
pkg.append[newLine]

Related

Updating my current script which modifies multiple lines into a single one

My current script copies text like this with a shortcut:
:WiltedFlower: aetheryxflower ─ 4
:Alcohol: alcohol ─ 3,709
:Ant: ant ─ 11,924
:Apple: apple ─ 15
:ArmpitHair: armpithair ─ 2
and pastes it modified into a single line
Pls trade 4 aetheryxflower 3 alcohol 11 ant 15 apple 2 armpithair <#id>
As you can see there are already two little problems, the first one is that it copies only the number/s before a comma if one existed instead of ignoring it. The second is that I always need to also copy before hitting the hotkey and start re/start the script, I've thought of modifying the script so that it uses the already selected text instead of the copied one so that I can bind it with a single hotkey.
That is my current script, it would be cool if anyone can also tell me what they used and why exactly, so that I also get better with ahk
!q::
list =
While pos := RegExMatch(Clipboard, "(\w*) ─ (\d*)", m, pos ? pos + StrLen(m) : 1)
list .= m2 " " m1 " "
Clipboard := "", Clipboard := "Pls trade " list " <#951737931159187457>"
ClipWait, 0
If ErrorLevel
MsgBox, 48, Error, An error occurred while waiting for the clipboard.
return
If the pattern of your copied text dont change, you can use something like this:
#Persistent
OnClipboardChange:
list =
a := StrSplit(StrReplace(Clipboard, "`r"), "`n")
Loop,% a.Count() {
b := StrSplit( a[A_Index], ": " )
c := StrSplit( b[2], " - " )
list .= Trim( c[2] ) " " Trim( c[1] ) " "
}
Clipboard := "Pls trade " list " <#951737931159187457>"]
ToolTip % Clipboard ; just for debug
return
With your example text, the output will be:
Pls trade aetheryxflower ─ 4 alcohol ─ 3,709 ant ─ 11,924 apple ─ 15 armpithair ─ 2 <#951737931159187457>
And this will run EVERY TIME your clipboard changes, to avoid this, you can add at the top of the script #IfWinActive, WinTitle or #IfWinExist, WinTitle depending of your need.
The answer given would solve the problem, assuming that it never changes pattern as Diesson mentions.
I did the explanation of the code you provided with comments in the code below:
!q::
list = ; initalize a blank variable
; regexMatch(Haystack, regexNeedle, OutputVar, startPos)
; just for frame of reference in explanation of regexMatch
While ; loop while 'pos' <> 0
pos := RegExMatch(Clipboard ; Haystack is the string to be searched,
in this case the Clipboard
, "(\w*) ─ (\d*)" ; regex needle in this case "capture word characters
(a-z OR A-Z OR 0-9 OR _) any number of times, space dash space
then capture any number of digits (0-9)"
, m ; output var array base name, ie first capture will be in m1
second m2 and so on.
, pos ? pos + StrLen(m) : 1) ; starting position for search
"? :"used in this way is called a ternary operator, what is saying
is "if pos<>0 then length of string+pos is start position, otherwise
start at 1". Based on the docs, this shouldn't actually work well
since 'm' in this case should be left blank
list .= m2 " " m1 " " ; append the results to the 'list' variable
followed with a space
Clipboard := "" ; clear the clipboard.
Clipboard := "Pls trade " list " <#951737931159187457>"
ClipWait, 0 ; wait zero seconds for the clipboard to change
If ErrorLevel ; if waiting zero seconds for the clipboard to change
doesn't work, give error msg to user.
MsgBox, 48, Error, An error occurred while waiting for the clipboard.
return
Frankly this code is what I would call quick and dirty, and seems unlikely to work well all the time.

CLLE SNDRCVF command not allowed

I am trying to compile this piece of CL code using Rational Series but keep getting error.
This is my CL code:
PGM
DCLF FILE(LAB4DF)
SNDRCVF RCDFMT(RECORD1) /* send, recieve file */
DOWHILE (&IN03 = '0')
SELECT
WHEN (&USERINPUT = '1' *OR &USERINPUT = '01') CALLSUBR OPTION1
OTHERWISE DO
*IN03 = '1'
ENDDO
ENDSELECT
ENDDO
SUBR OPTION1
DSPLIBL
ENDSUBR
ENDPGM
And this is my DSPF code
A R RECORD1
A 1 38'LAB 4'
A 3 3'Please select one of the following-
A options:'
A 6 11'3. Maximum Invalid Signon Attempt-
A s allowed'
A 8 11'5. Run Instructor''s Insurance Pr-
A ogram'
A 5 11'2. Signed on User''s Message Queu-
A e'
A 1 3'Yathavan Parameshwaran'
A 7 11'4. Initial number of active jobs -
A for storage allocation'
A 4 11'1. Previous sign on by signed on -
A user'
A 14 11'F3 = Exit'
A 14 31'F21 = Command Line'
A 2 70TIME
A 1 72DATE
A 9 11'Option: '
A USERINPUT 2 B 9 19
A 91 DSPATR(RI)
A 92 DSPATR(PC)
A MSGTXT1 70 O 11 11
A MSGTXT2 70 O 12 11
Is there a problem with my CL code or DSPF code?
You forgot to say what error you were getting. It's always important to put all the information about error messages into your questions.
There are two errors.
&IN03 is not defined
Your assignment to *IN03 should be to &IN03, but that's not how you do an assignment in CLP
If you want to be able to press F3, you have to code something like CA03(03) in the "Functions" for the record format.
To assign a variable in CL, code
CHGVAR name value
Looking at the documentation here, I suspect you need to add RCDFMT to your DCLF spec like so:
DCLF FILE(LAB4DF) RCDFMT(RECORD1)
SNDRCVF RCDFMT(RECORD1) /* send, recieve file */
If you really do only have 1 record format in your display file, then you can also omit the RCDFMT from both commands like so:
DCLF FILE(LAB4DF)
SNDRCVF /* send, recieve file */

OWL2: Is it possible put Annotation on an ObjectIntersectionOf?

I know I can put annotations on a SubClassOf relation:
SubClassOf(
Annotation(rdfs:comment "This annotation is valid")
ObjectIntersectionOf(
ObjectHasValue(:prop1 :instance1)
ObjectHasValue(:prop2 :instance2)
)
ObjectHasValue(:prop3 :instance3)
)
However, what I really wanted to do is this:
SubClassOf(
ObjectIntersectionOf(
Annotation(rdfs:comment "This annotation is invalid")
ObjectHasValue(:prop1 :instance1)
ObjectHasValue(:prop2 :instance2)
)
ObjectHasValue(:prop3 :instance3)
)
What I want is to create an annotation meaningful to all objects with the relations :prop1 :instance1 and :prop2 :instance, and not to the subclass relation.
I don't want to create a class for the ObjectIntersectionOf, as I will have thousands of such classes on my real example.
Running pellet 2.3.1 on the file below yields the following error:
$ pellet.sh explain draft2.owl
There are 1 input files:
./draft2.owl
Start loading
org.semanticweb.owlapi.io.UnparsableOntologyException: Problem parsing file:/home/users/djogo/Desktop/ontologia%20tnm/draft2.owl
Could not parse ontology. Either a suitable parser could not be found, or parsing failed. See parser logs below for explanation.
The following parsers were tried:
1) RDFXMLParser
2) OWLXMLParser
3) OWLFunctionalSyntaxOWLParser
4) TurtleOntologyParser
5) OWLOBOParser
6) KRSS2OWLParser
7) ManchesterOWLSyntaxOntologyParser
Detailed logs:
--------------------------------------------------------------------------------
Parser: RDFXMLParser
org.xml.sax.SAXParseException; systemId: file:/home/users/djogo/Desktop/ontologia%20tnm/draft2.owl; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
--------------------------------------------------------------------------------
Parser: OWLXMLParser
org.xml.sax.SAXParseException; systemId: file:/home/users/djogo/Desktop/ontologia%20tnm/draft2.owl; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
--------------------------------------------------------------------------------
Parser: OWLFunctionalSyntaxOWLParser
Encountered "" at line 8, column 9.
Was expecting one of:
(Line 7)
--------------------------------------------------------------------------------
Parser: TurtleOntologyParser
uk.ac.manchester.cs.owl.owlapi.turtle.parser.ParseException: Encountered "" at line 1, column 1.
Was expecting one of:
--------------------------------------------------------------------------------
Parser: OWLOBOParser
org.coode.owlapi.obo.parser.TokenMgrError: Lexical error at line 6, column 12. Encountered: "\n" (10), after : ""
--------------------------------------------------------------------------------
Parser: KRSS2OWLParser
de.uulm.ecs.ai.owlapi.krssparser.ParseException: Encountered " <NAME> "Prefix "" at line 1, column 1.
Was expecting:
<EOF>
--------------------------------------------------------------------------------
Parser: ManchesterOWLSyntaxOntologyParser
Encountered Prefix at line 1 column 1. Expected one of:
DifferentIndividuals:
Individual:
Class:
AnnotationProperty:
Import:
DisjointClasses:
ObjectProperty:
Datatype:
EquivalentClasses:
SameIndividual:
Prefix:
DataProperty:
DisjointProperties:
ValuePartition:
(Line 1)
at uk.ac.manchester.cs.owl.owlapi.ParsableOWLOntologyFactory.loadOWLOntology(ParsableOWLOntologyFactory.java:236)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntology(OWLOntologyManagerImpl.java:880)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOntologyDocument(OWLOntologyManagerImpl.java:818)
at com.clarkparsia.pellet.owlapiv3.OWLAPILoader.parseFile(OWLAPILoader.java:142)
at org.mindswap.pellet.KBLoader.parse(KBLoader.java:99)
at com.clarkparsia.pellet.owlapiv3.OWLAPILoader.parse(OWLAPILoader.java:128)
at org.mindswap.pellet.KBLoader.createKB(KBLoader.java:65)
at pellet.PelletCmdApp.getKB(PelletCmdApp.java:210)
at pellet.PelletCmdApp.getKB(PelletCmdApp.java:198)
at pellet.PelletExplain.parseArgs(PelletExplain.java:204)
at pellet.Pellet.run(Pellet.java:104)
at pellet.Pellet.main(Pellet.java:59)
draft2.owl
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
Prefix(:=<http://cipe.accamargo.org.br/ontologias/tnm.owl#>)
Ontology(<http://cipe.accamargo.org.br/ontologias/tnm.owl>
SubClassOf(
ObjectIntersectionOf(
Annotation(rdfs:comment "This annotation is invalid")
ObjectHasValue(:prop1 :instance1)
ObjectHasValue(:prop2 :instance2)
)
ObjectHasValue(:prop3 :instance3)
)
No, I don't think you can do this. The OWL 2 spec allows for annotations of ontologies, axioms, and entities, and complex class expressions are neither of those (see §10 Annotations).
Pellet has nothing to do with this, you get the error from the OWL API FSS parser since your ontology is syntactically invalid.

read .yml files in matlab

I would like to read .yml files in Matlab. These files contain coordinates x and y of key points on a face image. I looked for different tools but I don't seem to find any answers.
My .yml files look like this
YAML:1.0
Image file: "00032009.jpg"
Contours count: 8
Contours:
-
Name: FO
Count: 41
Closed: 0
Points:
-
x: 682.5947265625000000
y: 743.1998901367187500
-
x: 685.9638061523437500
y: 771.3800659179687500
......
and so on
Note 00032009.jpg is an image of a face
x and y are coordinates of a point on a face Eg: the right corner of an eye etc
Could you please point out a way to read the file and then display the points on the face image?
Edit 1: Here is the error I get
Error: File: ReadYamlRaw.m Line: 14 Column: 11
Expression or statement is incorrect--possibly unbalanced (, {, or [.
Error in ==> ReadYaml at 38
ry = ReadYamlRaw(filename, 0, nosuchfileaction);
What is weird is line 14 in ReadYamlRaw.m
[pth,~,~]= fileparts(mfilename('fullpath'));
Parse error at ','(second one) and ']' usage appears to be invalid matlab syntax.
So what is the use of ~ in there and why is there an error?
Edit2: I replaced the ~ in the line above with dummy variables then I get this errors O_O
Error using ==> ReadYamlRaw>scan at 81
Unknown data type: logical
Error in ==> ReadYamlRaw>scan_map at 138
result.(ich) = scan(r.get(java.lang.String(ich)));
Error in ==> ReadYamlRaw>scan at 79
result = scan_map(r);
Error in ==> ReadYamlRaw>scan_list at 116
result{ii} = scan(i);
Error in ==> ReadYamlRaw>scan at 77
result = scan_list(r);
Error in ==> ReadYamlRaw>scan_map at 138
result.(ich) = scan(r.get(java.lang.String(ich)));
Error in ==> ReadYamlRaw>scan at 79
result = scan_map(r);
Error in ==> ReadYamlRaw>load_yaml at 48
result = scan(yaml.load(fileread([filename, fileext])));
Error in ==> ReadYamlRaw at 19
result = load_yaml(filename, nosuchfileaction);
Error in ==> ReadYaml at 38
ry = ReadYamlRaw(filename, 0, nosuchfileaction);
I also tried with a different yml file that looks like this
%YAML:1.0
RE-C:
x: 919
y: 580
LE-C:
x: 1209
y: 597
N-C:
x: 1063
y: 698
FO-B:
x: 1045
y: 1114
REL-O:
x: 852
y: 597
REL-I:
x: 986
y: 600
REL-T:
x: 918
y: 564
And I get the following errors
Java exception occurred:
while scanning a directive
in "<string>", line 1, column 1:
%YAML:1.0
^
expected alphabetic or numeric character, but found :(58)
in "<string>", line 1, column 6:
%YAML:1.0
^
at org.yaml.snakeyaml.scanner.ScannerImpl.scanDirectiveName(ScannerImpl.java:1028)
at org.yaml.snakeyaml.scanner.ScannerImpl.scanDirective(ScannerImpl.java:990)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchDirective(ScannerImpl.java:534)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:251)
at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:179)
at
org.yaml.snakeyaml.parser.ParserImpl$ParseImplicitDocumentStart.produce(ParserImpl.java:198)
at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)
at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146)
at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105)
at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:121)
at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:399)
Error in ==> ReadYamlRaw>load_yaml at 48
result = scan(yaml.load(fileread([filename, fileext])));
Error in ==> ReadYamlRaw at 19
result = load_yaml(filename, nosuchfileaction);
Error in ==> ReadYaml at 38
ry = ReadYamlRaw(filename, 0, nosuchfileaction);
Maybe someone can make something out of these or you could point out another set of functions that would work? I searched but didn't find any except this one.
It's YAML file indeed (as #DavidBrown mentioned in his comment, the extension does not matter). But it has some problems. Don't know if it's due to wrong YAML format or MATLAB implementation.
I've installed YAMLMATLAB and played a little with your file.
YamlStruct = ReadYaml(yaml_file);
YAMLMATLAB returns error if the files is feed as is. It works only if I comment the first line and remove spaces from field names. So the beginning of the file looks like this:
#YAML:1.0
Imagefile: 00032009.jpg
Contourscount: 8
...skipped the rest...
Then I get the correct structure. For example you can access the 1st point's x coordinate as
YamlStruct.Contours{1}.Points{1}.x
ans =
682.5947
UPDATE
Space in filed names is actually a known problem in YAMLMATLAB. See the report and possible solution here.
UPDATE 2
According to comment from #Jirka_cigler (YAMLMATLAB developers group):
In the program release 0.4.3 we added support for whitespaces in field
names, so the problem should not appear again.
Great!
I've also removed previous developers comment on the problem in the first UPDATE since it's not true any more.
ZozaniDB Database Toolbox comes with a Matlab-native YAML implementation that handles the .yml file here. To parse a string or a file, use:
>> yaml_parse ( str )
>> yaml_read ( filename )

Display Superscript in SSRS reports

I m working on SSRS 2008.
i want to display date as 1st January 2011..
but "st" should be in superscipt ..
not like "1st".
is there any way to display "st", "nd","rd" and "th" in superscipt without installing any custom font type(other Font Type).
just copy and paste from the following list:
ABC⁰ ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ ⁺ ⁻ ⁼ ⁽ ⁾
ABC₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉ ₊ ₋ ₌ ₍ ₎
ABCᵃ ᵇ ᶜ ᵈ ᵉ ᶠ ᵍ ʰ ⁱ ʲ ᵏ ˡ ᵐ ⁿ ᵒ ᵖ ʳ ˢ ᵗ ᵘ ᵛ ʷ ˣ ʸ ᶻ
ABCᴬ ᴮ ᴰ ᴱ ᴳ ᴴ ᴵ ᴶ ᴷ ᴸ ᴹ ᴺ ᴼ ᴾ ᴿ ᵀ ᵁ ᵂ
ABCₐ ₑ ᵢ ₒ ᵣ ᵤ ᵥ ₓ
ABC½ ¼ ¾ ⅓ ⅔ ⅕ ⅖ ⅗ ⅘ ⅙ ⅚ ⅛ ⅜ ⅝ ⅞ № ℠ ™ © ®
ABC^ ± ¶
Maybe...
You are limited to what can be done with String.Format. Font size and spacing also refer to the whole text box. So it isn't "native"
However, superscript is unicode so you may be able to to do it with some fancy expression that concatenate characters. I'd suggest custom code.
I haven't tried this, but these articles mention it
http://beyondrelational.com/blogs/jason/archive/2010/12/06/subscripts-and-superscripts-in-ssrs-reports.aspx
http://www.codeproject.com/KB/reporting-services/SSRSSuperscript.aspx
I am not looking for credit here as above solution has answered it for you but for beginners sake, I use a code function within my report.
So in my SQL say I have Number field, then I add a new field OrdinalNumber:
SELECT ..., Number,
CASE WHEN (Number % 100) BETWEEN 10 AND 20 THEN 4
WHEN (Number % 10) = 1 THEN 1
WHEN (Number % 10) = 2 THEN 2
WHEN (Number % 10) = 3 THEN 3
ELSE 4 END AS OrdinalNumber,
...
Then my code function:
Function OrdinalText(ByVal OrdinalNumber As Integer) As String
Dim result As String
Select Case OrdinalNumber
Case 1
result = "ˢᵗ"
Case 2
result = "ⁿᵈ"
Case 3
result = "ʳᵈ"
Case Else
result = "ᵗʰ"
End Select
Return result
End Function
Then in the report textbox I use the expression:
=CStr(Fields!Number.Value) & Code.OrdinalText(Fields!OrdinalNumber.Value)