Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#120): pos-bigger-than-line #195

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

h1alexbel
Copy link
Contributor

In this pull I've introduced new lint: pos-bigger-than-line, that issues critical defect if @pos is bigger than @line attribute of the object in XMIR.

closes #120

@h1alexbel
Copy link
Contributor Author

@maxonfjvipon please check

<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/">
<defects>
<xsl:for-each select="//o[(@pos and @line) and (number(@pos)&gt;number(@line))]">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel please read the original ticket more carefully. @pos must be less that LEGTH of the line it belongs to. When we parse EO every object has its line and position at this line, for example here object foo would have position 6:

hello foo

But it can't have position 20 because the line length is 9

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxonfjvipon Ah, got it, thanks for the clarification, I will adjust this PR

@h1alexbel h1alexbel marked this pull request as draft January 2, 2025 18:11
@h1alexbel h1alexbel marked this pull request as ready for review January 3, 2025 09:16
@h1alexbel
Copy link
Contributor Author

@maxonfjvipon updated. Take a look, please

@h1alexbel h1alexbel requested a review from maxonfjvipon January 3, 2025 09:17
<defects>
<xsl:for-each select="//o">
<xsl:variable name="line" select="number(@line)"/>
<xsl:variable name="length" select="string-length(normalize-space($lines[$line]))"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel I'm not sure if it's a right choice to take length from listing. For example, in JEO repository we create XMIR from Java bytecode which would look like binary one line text in listing. Maybe it would be better to find all the <o> with the same line, count and sum the lengths of their text() and compare with @pos?
@yegor256 WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxonfjvipon Agree, I think it will be more correct way to calculate the length of the <o/> line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel be careful because there may be a performance issue since for every <o> element you need to find all other elements with the same @line

@h1alexbel
Copy link
Contributor Author

@maxonfjvipon updated. Take a look, please.

P.S. I'm not sure that is right way to calculate line length still

@h1alexbel h1alexbel requested a review from maxonfjvipon January 3, 2025 14:01
@h1alexbel
Copy link
Contributor Author

@maxonfjvipon reminder

@h1alexbel
Copy link
Contributor Author

@maxonfjvipon take a look, please

@h1alexbel
Copy link
Contributor Author

@maxonfjvipon reminder

document: |
<program>
<objects>
<o line="2" pos="3" name="foo">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel this example in EO will look like this:

[] ([] ([]) > xyz) > foo

Yes, it's legal in EO, the only part which is not allowed is most deepest abstract object. It can't contain data and it cant' be nameless

document: |
<program>
<objects>
<o line="2" pos="20" name="foo">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel as I mentioned here, this example in EO will look like this:

[] ([] ([]) > xyz) > foo

It almost legal in your case, BUT this EO line has more that 20 symbols which means no error should be caught

<defects>
<xsl:for-each select="//o">
<xsl:variable name="line" select="number(@line)"/>
<xsl:variable name="length" select="sum(//o[@line = $line and not(descendant::o)]/string-length(normalize-space(text())))"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel no, it still looks not correct to me.
Here's how I would try to implement it:

  1. take EO code and convert it to XMIR. You'll get "real" XMIR, not a toy one which you made up
  2. look at XMIR and EO code and try to make up with an algorithm of calculating line length

In general:

  1. if you have @name - it EO it looks like this > foo, which is foo length + 2 extra symbols
  2. if you have @base - it just @base length
  3. if it's long horizontal application like this x (a b c) (y 1 2) (* (o 2) (q w e)) you may see that that there are 10 braces and some amount of spaces without them, so they should be counted as well

Maybe there're some more patterns, I'm not sure, so the task is not such trivial as it seems to be

@h1alexbel
Copy link
Contributor Author

@maxonfjvipon thanks for ideas, I will adjust this PR

@h1alexbel h1alexbel marked this pull request as draft January 14, 2025 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@pos may not be larger than the amount of characters in the line
2 participants