How to use Roslyn to determine code's line and column position in a source file - roslyn

I am using Roslyn within a source generator to find certain c# method calls in a syntax tree. When found, I want to note the line and column number.
This answer works for the line number but not the column number.
This is how I get the LineSpan for an InvocationExpression node:
syntaxTree.GetLineSpan(node.Span, cancellationToken)
In my case, the returned FileLinePositionSpan's starting Character is 5. Accounting for it being zero-based, it's character number 4. This matches Visual Studio's
Ch value shown below.
Col, however, is 13. VS figures that out by multiplying each tab character by 5. Two tabs and three spaces lands you on column 13. 5+5+3 = 13.
How can I accurately get the Column number with Roslyn?
p.s. There seemed to be cases where GetLineSpan returned Character values that did not coincide with Visual Studio, but I am unable to reproduce that now.

Related

How to get all cells that appear more than 5 times?

enter image description here
I have a table in OpenOffice that contains a column with region's codes (column J). Using table functions, how to get all codes that appear more than 5 times and write them in one cell?
Normally I would recommend breaking this problem down into smaller parts using helper columns. Or better yet, move the data into LibreOffice Base which can easily work with distinct values.
However, I managed to come up with a rather large formula that seems to do what you asked. Enter it as an array formula.
=TEXTJOIN(",";1;IF(COUNTIF(исходник.J$2:J$552;исходник.J2:J552)>5;IF(ROW(исходник.J2:J552)=MATCH(исходник.J2:J552;исходник.J$2:J$552;0)+ROW(J$2)-1;исходник.J2:J552;"")))
I can't test this on your actual data since your example is only an image, but let's say that there are six of both 77 and 37. Then this would show 77,37 as the result.
Here is a breakdown. Look up the functions in LibreOffice Online Help for more information.
=TEXTJOIN(",";1; — Join all results into a single cell, separated by commas.
IF(COUNTIF(исходник.J$2:J$552;исходник.J2:J552)>5; — Find codes that occur more than 5 times. This is the same as what you wrote.
IF(ROW(исходник.J2:J552)= — Compare the next result to the row number that we are currently looking at.
MATCH(исходник.J2:J552;исходник.J$2:J$552;0)+ROW(J$2)-1; — Determine the first row that has this code. We do this to get unique results instead of 6 or more of each code in the result.
исходник.J2:J552;""))) — Return the code. (Your formula simply returns 1 here, which doesn't seem to be what you want.) If it doesn't match, return an empty string rather than 0, because TEXTJOIN ignores empty strings.

problem with define dimensions of variables fortran 77

I found this one old fortran 77 program printed in one old book, and i typed in the program but it isnt running. When I give the dimensions of variables, appear the next:
DIMENSION XN(20),YN(20),W(20),NUMAJ(20),NUMAAJ(20),SSW(20)
1,NEJI(5,20),QX(20,20),QY(20,20),IACTE(20),N1(20),N2(20),X(20)
2,Y(20),DD(20),TT(20),NUMAJA(20)
And the error code:
Error: Non-numeric character in statement label at (1)
Error: Unclassifiable statement at (1)
Thanks a lot,
Comparing the original and edited version shows still incorrect indenting: fixed format reserves columns 1-5 for labels, 6 for the continuation character and starting from 7 for the statements. If column 6 is not a space the line continues the previous line.
In the 3 line example above the characters "1" and "2" are the continuation characters of line 2 and 3, so they have to be exactly in column 6. The first line has no label or continuation character so it must start in column 7. The comment from #melpomene was incomplete regarding continuation character and based on the old version where one space less was used (the edited version has one space too much).

Meaning of 3F7.1 in Fortran data format

I am trying to create an MDM file using HLM 7 Student version, but since I don't have access to SPSS I am trying to import my data using ASCII input. As part of this process I am required to input the data format Fortran style. Try as I might I have not been able to understand this step. Could someone familiar with Fortran (or even better HLM itself) explain to me how this works? Here is my current understanding
From the example EG3.DAT they give
(A4,1X,3F7.1)
I think
A4 signifies that the ID is 4 characters long.
1X means skip a space.
F.1 means that it should read 1 decimal places.
I am very confused about what 3F7 might mean.
EG3.DAT
2020 380.0 40.3 12.5
2040 502.0 83.1 18.6
2180 777.0 96.6 44.4
Below are examples from the help documents.
Rules for format statement
Format statement example
EG1 data format
EG2 data format
EG3 data format
One similar question is Explaining Fortran Write Format. Unfortunately it does not explicitly treat the F descriptor.
3F7.1 means 3 floating point numbers, each printed over 7 characters, each with one decimal number behind the decimal point. Leading characters are blanks.
For reading you don't need the .1 info at all, just read a floating point number from those 7 characters.
You guessed the meaning of A4 (string of four characters) and 1X (one blank) correctly.
In Fortran, so-called data edit descriptors (which format the input or output of data) may have repeat specifications.
In the format (A4,1X,3F7.1) the data edit descriptors are A4 and F7.1. Only F7.1 has a repeat specification (the number before the F). This simply means that the format is as though the descriptor appeared repeated: like F7.1, F7.1, F7.1. With a repeat specification of 1, or not given, there is just the single appearance.
The format of the question, then, is like
(A4,1X,F7.1,F7.1,F7.1)
This format is one that is covered by the rules provided in one of the images of the question. In particular, the aspect of repeat specification is given in rule 2 with the corresponding example of rule 3.
Further, in Fortran proper, a repeat count specifier may also be * as special case: that's like an exceptionally large repeat count. *(F7.1) would be like F7.1, F7.1, F7.1, .... I see no indication that this is supported by HLM but if this is needed a very large repeat count may be given instead.
In 1X the 1 isn't a repeat specification but an integral, and necessary, part of the position edit descriptor.
Procedure for making MDM file from excel for HLM:
-Make sure ALL the characters in ALL the columns line up
Select a column, then right click and select Format Cells
Then click on 'Custom' and go to the 'Type' box and enter the number
of 0s you need to line everything up
-Remove all the tabs from the document and replace them with spaces.
Open the document in word and use find and replace
-To save the document as .dat
First save it as .txt
Then open it in Notepad and save it as .dat
To enter the data format (FORTRAN-Style)
The program wants to read the data file space by space, so you have to specify it perfectly so that it reads the whole set properly.
If something is off, even by a single space, then your descriptive stats will be wonky compared to if you check them in another program.
Enclose the code with brackets ()
Divide the entries with commas ,
-Need ID column for all levels
ID column needs to be sorted so that it is in order from smallest to
largest
Use A# with # being the number of characters in the ID
Use an X1 to
move from the ID to the next column
-Need to say how many characters are needed in each column
Use F
After F is the number of characters needed for that column -Use F# (#= number)
There need to be enough character spaces to provide one 'gap' space
between each column
There need to be enough to character spaces to allow for the decimal
As part of the F you need to specify the number of decimal places
You do this by adding a decimal point after the F number and then a
number to represent the spaces you need -F#.#
You can use a number in front of the F so as to 'repeat' it. Not
necessary though. -#F#.#
All in all, it should look something like this:
(A4,X1,F4.0,F5.1)
Helpful links:
https://books.google.de/books?id=VdmVtz6Wtc0C&pg=PA78&lpg=PA78&dq=data+format+fortran+style+hlm&source=bl&ots=kURJ6USN5e&sig=fdtsmTGSKFxn04wkxvRc2Vw1l5Q&hl=en&sa=X&ved=0ahUKEwi_yPurjYrYAhWIJuwKHa0uCuAQ6AEIPzAC#v=onepage&q&f=false
http://www.ssicentral.com/hlm/help6/error/Problems_creating_MDM_files.pdf
http://www.ssicentral.com/hlm/help7/faq/FAQ_Format_specifications_for_ASCII_data.pdf

Proper Fortran compiler to execute a program

I have little knowledge of the Fortran language. I have come across some programs written in the 90s (see attached snapshot showing just a portion of a long script).
I'd like to know what kind of compiler is appropriate to execute such codes? I have installed gfortran-4.2.3 on my mac. I'm also not sure about the indentation in the attached code: if C (comment) is at column 1, does the main code start at column 9 or 7? what about the position of numbers placed in between referred by GO TO?
This is not Fortran 90. This is Fortran 77.
That said, gfortran is able to compile this code. Make sure that the file extension for the file is .f so that gfortran realises it's fixed-form.
The C needs to be in the first column, the numbers that you reference are labels, they can be between column 1 and 5. The asterisk at line 198 is a continuation character, meaning that this should be treated as part of the previous line. It must be in column 6. Everything else needs to be between columns 7 and 72 (inclusive)
Oh, and the 3-digit numbers at the very beginning are line numbers, and must not be in the source code.
Edited to add: Since you have to type it all again anyway, you might as well make it free-form:
Replace the C in the first column with !, and change the way continuation lines are marked: Turn this:
write (*, *) "This is some long text,
* which doesn't fit into a line"
Into this:
write(*, *) "This is some long text, " // &
"which doesn't fit into a line"
Everything else can stay like it is. (You can now use proper indentation, too!)
New Edit
So you've pasted the code that you wrote and the error messages, so I'm replying to that now.
In Fixed Form, any character past column 72 is ignored. You have a few lines with long strings, where the terminating quotation mark is in that ignored region.
Make sure that no line exceeds the 72nd row.

Select a node where an attribute contains a text that is of certain length after a certain character

I'm using Selenium IDE and can't figure out how to select a given element that has a certain attribute which contains some text (number) of a certain length after a specified character.
In order to better understand what exactly I would like to achieve please see below an example.
I have the following HTML element:
<div><h2 class="attribute" onclick="PropertyPopup.Show(63854, 4065)">test test</h2></div>
In my case both the numbers in the bracket (63854 and 4065) are changing dynamically and I'm mostly interested in the second number (4065). This can have a length of 4 or 7 so I would need an XPATH (combined with regexp?) that would extract only those elements where this number has a length of 4 for example (like in the above example).
So far I've used the following XPATH:
//div[h2[#onclick][string-length(#onclick)<=31]]
This is working fine at the moment (since in most cases when the second number has a length of 4, the whole line will have less (or equal) than 31 characters) but if the first number will contain 6 numbers (and the whole line will have 32 characters), the above example will not be selected. If I would put "<=32", then in some cases, it would select those elements where the second number has a length of 7 (like when the first number has a length of 3 and the second 7).
I've tried to use something like the below:
//div[h2[#onclick][contains(#onclick,', \d{4}']]
but this will not be recognized as a regexp and will look for an 'onclick' attribute that contain the word ", \d{4}".
Is there anything I could do in order to select the node only based on the second number (its length)?
thank you,
Szabi
You could try something like this:
//div[string-length(normalize-space(substring-before(substring-after(h2/#onclick,','),')')))=4]