colorer / Colorer-schemes

Syntax and color schemes for colorer library
31 stars 25 forks source link

Java stops highlighting after a certain point #69

Closed k-poole closed 5 years ago

k-poole commented 5 years ago

Confirmed an issue with java.hrc by replacing with vbasic.hrc and the issue went away.

Test on tohtml.com eg:

image

sharpedavid commented 5 years ago

I'm the one who reported this over email. I played around with this example and discovered something: only code surrounded by braces is highlighted. So if you surround the whole example with {...}, then syntax highlighting works throughout.

image

I don't think that it should require the braces. I think a common use-case of this tool (tohtml) is syntax highlighting snippets, not complete code blocks.

ctapmex commented 5 years ago

please attach this example

k-poole commented 5 years ago

50565780-41a7b780-0ce7-11e9-8793-f4fdd52bef53 Here ya go @ctapmex ... wait, that did the same thing again. I have no idea what you mean by attaching the example then!

Also @sharpedavid this isn't specifically tohtml, this is just part of the library that the code uses :)

sharpedavid commented 5 years ago

I bet he means text instead of image. I won’t be able to post that example until tomorrow, but here’s a simpler example:

With Java syntax highlighting, System.out.println(“Hello world!”); does not highlight, but {System.out.println(“Hello world!”);} does.

(Posting on mobile.)

k-poole commented 5 years ago

Ah yep nice one!

@ctapmex does that help?

Cheers guys.

ctapmex commented 5 years ago

where do you check ? colorer.exe , far, Eclipse ? if Eclipse - I do not know how to help you. I do not know how to build a plugin for Eclipse

k-poole commented 5 years ago

@ctapmex any implementation of java.hrc will have this issue. I have confirmed this by replacing it with another HRC file, and the issue goes away. Something in java.hrc is causing it to stop processing the code without curly brackets.

k-poole commented 5 years ago

You can test it on https://tohtml.com by selecting 'Java' (instead of autodetect) and pasting some code in.

ctapmex commented 5 years ago

hrc is just the rules. It needs a rule handler (colorer binary, farcolorer, eclipse colorer, etc) . The handler can fail . What handler is used on this site, I do not know. This is not "our" site. take FarManager https://farmanager.com/download.php?l=en and check file in far text editor (F4).

k-poole commented 5 years ago

@ctapmex Yeah I figured as much. I don't know much about how it all works, but I inherited tohtml.com when Oleg could no longer run it. It uses colorer binary I believe, but regardless of that, I confirmed the problem seemingly in the java.hrc file by replacing its contents with another HRC file and just changing "type name=".

I just did a quick test with Far and reproduced the issue. As shown: farjavafail

Note the obvious issue with "user" being highlighted when the entire snippet is within {}, but not when outside.

Cheers -KP

ctapmex commented 5 years ago

ok. can you send this file? or I will have to type it manually for tests ;)

k-poole commented 5 years ago

@ctapmex it was just some random code:

       boolean userHeaderFound = false;
        for (SoapHeader soapHeader : soapHeaders) {
            if (soapHeader.getName().getLocalPart().equals("user")) {
                assertFalse("Multiple user headers found.", userHeaderFound);
                userHeaderFound = true;
                String nodeValue = ((SOAPElement) soapHeader.getObject()).getFirstChild().getNodeValue();
                assertEquals("BESTSystem", nodeValue);
            }
        }
        assertTrue("No user header found.", userHeaderFound);

        List<String> userHeaderValues = new ArrayList<>();
        for (SoapHeader soapHeader : soapHeaders) {
            if (soapHeader.getName().getLocalPart().equals("user")) {
                userHeaderValues.add(((SOAPElement) soapHeader.getObject()).getFirstChild().getNodeValue());
            }
        }
        assertEquals(1, userHeaderValues.size());
        assertEquals("BESTSystem", userHeaderValues.get(0));

        List<SoapHeader> userHeader = soapHeaders.stream()
                .filter(header -> header.getName().getLocalPart().equals("user"))
                .collect(Collectors.toList());
        assertEquals(1, userHeader.size());
        String nodeValue = ((Element) userHeader.get(0).getObject()).getFirstChild().getNodeValue();
        assertEquals("BESTSystem", nodeValue);
ctapmex commented 5 years ago

well, I understood what was the matter. I will try to explain through 'google translate'. Colorer doesn't just color the text by seeing keywords and symbols. Coloring goes according to context. If the file has incorrect language syntax, then the coloring will not be correct. The test case contains the contents of the function. A function must begin with a name and {.

k-poole commented 5 years ago

Ah okay.

@sharpedavid thoughts? I am no Java expert sorry, so did not even consider this partial syntax issue.

I did a test with https://www.cs.utexas.edu/~scottm/cs307/javacode/codeSamples/PrimeEx.java and it appears to highlight fine.

@ctapmex While that makes sense, the vbasic.hrc file does not seem to work this way, and still highlights type descriptors such as String, and quoted text such as "user".

Thanks

ctapmex commented 5 years ago

as far I remember vbasic, this is the correct syntax for it

sharpedavid commented 5 years ago

Hi everyone, thanks for spending time on this. This all sounds fine to me. It sounds like the library is working as intended.

Really the only reason I reported this is because it appeared to work for half of the sample, but not for the other half. This made me think there was a defect, but I understand now it's working as intended.

Again, thanks for your support, everyone. I recommend closing this ticket.