jgm/skylighting

quoted atom parsed as errors in prolog

Opened this issue · 8 comments

Hi, reporting here per suggestion on pandoc user list. I was told this is the upstream dep and replicated the error in skylighting (as far as I understand it, first time user, brew install)

echo  'afact("Fact").' | skylighting --syntax prolog -f latex

<preamble omitted>
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{afact(}\OtherTok{"}\ErrorTok{Fact}\OtherTok{"}\NormalTok{)}\KeywordTok{.}
\end{Highlighting}
\end{Shaded}

You can see the \ErrorTok command in there. Similar story with html output (span class="er")

</style></head><body><div class="sourceCode"><pre class="sourceCode"><code class="sourceCode"><span id="1"><a href="#1" aria-hidden="true" tabindex="-1"></a>afact(<span class="ot">&quot;</span><span class="er">Fact</span><span class="ot">&quot;</span>)<span class="kw">.</span></span></code></pre></div></body></html>

I am told that skylighting relies on data shared or derived from the kate editor. I could not reproduce the problem in Kate on Mac OS, or at least I can say the quote atoms appear in green and not bold red. Not sure which style Kate is using by default. I am a complete Prolog noob, but that looks fine to me and SWI Prolog accepts it. Thanks

Antonio

jgm commented

I don't know much Prolog. Is the "Fact" just supposed to be a string?

jgm commented

Looking at prolog.xml, I'm baffled. It seems that the dq context just emits a syntax error whenever it sees something that looks like an identifier. Why?

Well, it's two of us then. But yes, from what I understand it is perfectly fine. To test this assumption, I created a file containing afact("Fact").. Opened it with swipl (SWI prolog) and performed a query afact(X) and the reply was X = "Fact".. You may have seen Prolog used with bare atoms, without quotes. skylighting works with those. The quotes are always permissible and mandatory when the atom contains a space or starts with an uppercase letter (which would qualify it as a variable).

So you are looking at this

	    <context name="dq" lineEndContext="#stay" attribute="&quot;double-quoted&quot;" noIndentationBasedFolding="true" >
<!-- 	    <context name="double-quoted" lineEndContext="#stay" attribute="&quot;double-quoted&quot;" > -->
		<IncludeRules context="quoted_1st"/>
		<RegExpr String="(&quot;&quot;|&esc_oct_iso;|&esc_hex_iso;|\\&any;|[^&quot;\\]+)$"
			context="syntax_error_dq" attribute="Syntax Error" />
		<Detect2Chars char="&quot;" char1="&quot;" context="#stay" attribute="escaped (!use background)" />
		<DetectChar char="&quot;" context="#pop#pop" endRegion="quoted" attribute="&quot;double-quoted&quot;" />
		<IncludeRules context="quoted_last"/>
	    </context>

I don't fully understand, but it seems to emit a syntax error for everything that's double quoted. "Fact" is actually a type of atom, not an identifier. There is a context name atomic but not one for atom. It would be nice to see the original in Kate.

jgm commented

This is the xml syntax definition that is being used in Kate.
It's possible that there is some error in our implementation, but I'm not sure what it would be.

Thanks, I don't think an intelligent person should go through 1000 lines of xml to try and fix this, I just switched it off for now. For a grammar that may be 10 lines of BNF.

jgm commented

I emailed the author - if we're lucky we may get some help understanding what it is supposed to do.

jgm commented

See comment #170 (comment)