Skip to content

Commit

Permalink
Fix Keywords in Alan XSLHL Syntax
Browse files Browse the repository at this point in the history
- Alan XSHL: Fix syntax:
  - Add missing keywords: `meta`, `transitively`, `indirectly`.
  - Add `literal` to predefined classes.
  - Create new group `hero` for highligting `hero` instance (optional).
- XSL Stylesheets: integrate new `hero` syntax element.
- Add to `_dev/hl/syntax-highlighting.asciidoc` new code to test predefined
  classes and `hero`.
(see #15 and #17 for details)
  • Loading branch information
tajmone committed Sep 12, 2018
1 parent a945bc7 commit 22165ce
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 155 deletions.
65 changes: 64 additions & 1 deletion _dev/hl/snippets.alan
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- "snippets.alan" v1.0.0 (2018/09/09) | Alan 3.0beta6
-- "snippets.alan" v1.0.1 (2018/09/12) | Alan 3.0beta6
--+============================================================================+
--|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//////////////////////////////////////|
--++--------------------------------------------------------------------------++
Expand All @@ -22,6 +22,14 @@
--=============================================================================
-- Full code examples (working) to be included as snippets...

--==============================================================================
--------------------------------------------------------------------------------
-- � 1.1 - Generic Example
--------------------------------------------------------------------------------
--==============================================================================
-- A small generic code example trying to show as many features of the syntax
-- in one place as possible.

-- tag::sample[]
--==============================================================================
-- "Barracks Example" by Tristano Ajmone
Expand Down Expand Up @@ -49,3 +57,58 @@ End The trolley.
--------------------------------------------------------------------------------
Start at canteen.
-- end::sample[]

--==============================================================================
--------------------------------------------------------------------------------
-- � 1.2 - Predefined Classes and Instances
--------------------------------------------------------------------------------
--==============================================================================
-- A code example showing all the predefined classes and the 'hero'.

-- tag::predefined_classes[]
Synonyms me = hero.

The basement IsA location.
Description "What a dark ang gloomy place!"
End The.

The vampire IsA actor At basement.
End The.

The coffin IsA object At basement.
Container taking thing.
End The.

ADD TO EVERY thing
VERB examine
Does
"You examine $+1, but find nothing unusual."
END VERB.
END ADD TO.

ADD TO EVERY string
VERB 'say'
Does
"You say ""$$" Say This. "$$""!"
END VERB.
END ADD TO.

ADD TO EVERY integer
VERB shout
Does
"You shout ""$$" Say This. "$$"" out loud!"
END VERB.
END ADD TO.

ADD TO EVERY literal
VERB whisper
Does
"You whisper ""$$" Say This. "$$""!"
END VERB.
END ADD TO.

--------------------------------------------------------------------------------

Start at basement.

-- end::predefined_classes[]
14 changes: 13 additions & 1 deletion _dev/hl/syntax-highlighting.asciidoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
= Syntax Highlighting in Alan Documentation
Tristano Ajmone <tajmone@gmail.com>
v1.0, September 9, 2018: Code styling previews
v1.1, September 12, 2018: Code styling previews
:version-label: v
:authorinitials: T.J.A.
// =====================
Expand Down Expand Up @@ -112,6 +112,18 @@ The following example shows all the various Alan syntax elements groups that are

Here follow some code snippets for testing both common- and edge-cases in the language and ensure they are rendered as expected.

==== Predefined Classes and Instances

Although it's usually unnecessary to highlight with separate styling the predefined Alan classes and instances (i.e. the `hero`), it might be desirable to be able to do so in tutorials and documentation, for educational purposes.
For this reason, I've added a special highlighting group for the predefined classes, and another one for the `hero`.
Both can be optionally enabled by assigning styles to them, or just be ignored (or set to the same style as normal text) to hide them in the highlighted source.

[source,alan]
--------------------
include::snippets.alan[tag=predefined_classes]
--------------------


==== Quoted Identifiers

Although quoted identifiers shouldn't receive any special coloring in the highlighted code, the syntax definition must be made aware of them to prevent false-positive keywords matches for tokens inside quoted identifiers:
Expand Down
65 changes: 61 additions & 4 deletions _dev/hl/syntax-highlighting.html
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ <h1>Syntax Highlighting in Alan Documentation</h1>
<div class="details">
<span id="author" class="author">Tristano Ajmone</span><br>
<span id="email" class="email"><a href="mailto:[email protected]">[email protected]</a></span><br>
<span id="revnumber">v 1.0,</span>
<span id="revdate">September 9, 2018</span>
<span id="revnumber">v 1.1,</span>
<span id="revdate">September 12, 2018</span>
<br><span id="revremark">Backend: Asciidoctor&#8217;s native HTML5</span>
</div>
<div id="toc" class="toc2">
Expand All @@ -455,6 +455,7 @@ <h1>Syntax Highlighting in Alan Documentation</h1>
<ul class="sectlevel2">
<li><a href="#_syntax_tests">Syntax Tests</a>
<ul class="sectlevel3">
<li><a href="#_predefined_classes_and_instances">Predefined Classes and Instances</a></li>
<li><a href="#_quoted_identifiers">Quoted Identifiers</a>
<ul class="sectlevel4">
<li><a href="#_single_quotes_escaping">Single Quotes Escaping</a></li>
Expand Down Expand Up @@ -549,6 +550,62 @@ <h3 id="_syntax_tests">Syntax Tests</h3>
<p>Here follow some code snippets for testing both common- and edge-cases in the language and ensure they are rendered as expected.</p>
</div>
<div class="sect3">
<h4 id="_predefined_classes_and_instances">Predefined Classes and Instances</h4>
<div class="paragraph">
<p>Although it&#8217;s usually unnecessary to highlight with separate styling the predefined Alan classes and instances (i.e. the <code>hero</code>), it might be desirable to be able to do so in tutorials and documentation, for educational purposes.
For this reason, I&#8217;ve added a special highlighting group for the predefined classes, and another one for the <code>hero</code>.
Both can be optionally enabled by assigning styles to them, or just be ignored (or set to the same style as normal text) to hide them in the highlighted source.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-alan" data-lang="alan">Synonyms me = hero.

The basement IsA location.
Description "What a dark ang gloomy place!"
End The.

The vampire IsA actor At basement.
End The.

The coffin IsA object At basement.
Container taking thing.
End The.

ADD TO EVERY thing
VERB examine
Does
"You examine $+1, but find nothing unusual."
END VERB.
END ADD TO.

ADD TO EVERY string
VERB 'say'
Does
"You say ""$$" Say This. "$$""!"
END VERB.
END ADD TO.

ADD TO EVERY integer
VERB shout
Does
"You shout ""$$" Say This. "$$"" out loud!"
END VERB.
END ADD TO.

ADD TO EVERY literal
VERB whisper
Does
"You whisper ""$$" Say This. "$$""!"
END VERB.
END ADD TO.

--------------------------------------------------------------------------------

Start at basement.</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_quoted_identifiers">Quoted Identifiers</h4>
<div class="paragraph">
<p>Although quoted identifiers shouldn&#8217;t receive any special coloring in the highlighted code, the syntax definition must be made aware of them to prevent false-positive keywords matches for tokens inside quoted identifiers:</p>
Expand Down Expand Up @@ -636,8 +693,8 @@ <h2 id="_bnf_syntax">BNF Syntax</h2>
</div>
<div id="footer">
<div id="footer-text">
v 1.0<br>
Last updated 2018-09-08 23:46:19 ora legale Europa occidentale
v 1.1<br>
Last updated 2018-09-12 10:59:31 ora legale Europa occidentale
</div>
</div>
</body>
Expand Down
Binary file modified _dev/hl/syntax-highlighting.pdf
Binary file not shown.
56 changes: 53 additions & 3 deletions _dev/hl/syntax-highlighting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<book xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en">
<info>
<title>Syntax Highlighting in Alan Documentation</title>
<date>September 9, 2018</date>
<date>September 12, 2018</date>
<author>
<personname>
<firstname>Tristano</firstname>
Expand All @@ -15,8 +15,8 @@
<authorinitials>T.J.A.</authorinitials>
<revhistory>
<revision>
<revnumber>1.0</revnumber>
<date>September 9, 2018</date>
<revnumber>1.1</revnumber>
<date>September 12, 2018</date>
<authorinitials>T.J.A.</authorinitials>
<revremark>Backend: Asciidoctor&#8217;s native HTML5</revremark>
</revision>
Expand Down Expand Up @@ -75,6 +75,56 @@ For PDF conversion, the usable highlighting tool(s) will be dictated by the thir
<section xml:id="_syntax_tests">
<title>Syntax Tests</title>
<simpara>Here follow some code snippets for testing both common- and edge-cases in the language and ensure they are rendered as expected.</simpara>
<section xml:id="_predefined_classes_and_instances">
<title>Predefined Classes and Instances</title>
<simpara>Although it&#8217;s usually unnecessary to highlight with separate styling the predefined Alan classes and instances (i.e. the <literal>hero</literal>), it might be desirable to be able to do so in tutorials and documentation, for educational purposes.
For this reason, I&#8217;ve added a special highlighting group for the predefined classes, and another one for the <literal>hero</literal>.
Both can be optionally enabled by assigning styles to them, or just be ignored (or set to the same style as normal text) to hide them in the highlighted source.</simpara>
<programlisting language="alan" linenumbering="unnumbered">Synonyms me = hero.

The basement IsA location.
Description "What a dark ang gloomy place!"
End The.

The vampire IsA actor At basement.
End The.

The coffin IsA object At basement.
Container taking thing.
End The.

ADD TO EVERY thing
VERB examine
Does
"You examine $+1, but find nothing unusual."
END VERB.
END ADD TO.

ADD TO EVERY string
VERB 'say'
Does
"You say ""$$" Say This. "$$""!"
END VERB.
END ADD TO.

ADD TO EVERY integer
VERB shout
Does
"You shout ""$$" Say This. "$$"" out loud!"
END VERB.
END ADD TO.

ADD TO EVERY literal
VERB whisper
Does
"You whisper ""$$" Say This. "$$""!"
END VERB.
END ADD TO.

--------------------------------------------------------------------------------

Start at basement.</programlisting>
</section>
<section xml:id="_quoted_identifiers">
<title>Quoted Identifiers</title>
<simpara>Although quoted identifiers shouldn&#8217;t receive any special coloring in the highlighted code, the syntax definition must be made aware of them to prevent false-positive keywords matches for tokens inside quoted identifiers:</simpara>
Expand Down
11 changes: 6 additions & 5 deletions manual/manual-xsl/common.xsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
"common.xsl" v0.2.3 (2018/09/09)
"common.xsl" v0.3.0 (2018/09/12)
==============================================================================
This file was taken from the asciidoctor-fopub project, Copyright (C) 2013
Dan Allen (MIT License):
Expand Down Expand Up @@ -122,14 +122,15 @@
-->
<xsl:param name="AlanHL.background">#F8F8F8</xsl:param>

<xsl:param name="AlanHL.normal" >#333333</xsl:param>
<xsl:param name="AlanHL.quotedId" select="$AlanHL.normal"></xsl:param>
<xsl:param name="AlanHL.keyword" >#990000</xsl:param>
<xsl:param name="AlanHL.class" >#000080</xsl:param>
<xsl:param name="AlanHL.comment" >#999988</xsl:param>
<xsl:param name="AlanHL.string" >#008080</xsl:param>
<xsl:param name="AlanHL.hero" select="$AlanHL.normal"></xsl:param>
<xsl:param name="AlanHL.keyword" >#990000</xsl:param>
<xsl:param name="AlanHL.normal" >#333333</xsl:param>
<xsl:param name="AlanHL.number" >#DD1144</xsl:param>
<xsl:param name="AlanHL.operator" select="$AlanHL.normal"></xsl:param>
<xsl:param name="AlanHL.quotedId" select="$AlanHL.normal"></xsl:param>
<xsl:param name="AlanHL.string" >#008080</xsl:param>

<xsl:param name="AlanHL.border.color">transparent</xsl:param>
<xsl:param name="AlanHL.border.width">0</xsl:param>
Expand Down
8 changes: 7 additions & 1 deletion manual/manual-xsl/highlight.xsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
"highlight.xsl" v0.2.1 (2018/09/09)
"highlight.xsl" v0.3.0 (2018/09/12)
==============================================================================
This file was taken from the asciidoctor-fopub project, Copyright (C) 2013
Dan Allen (MIT License):
Expand Down Expand Up @@ -45,6 +45,12 @@
<xsl:template match="xslthl:class" mode="xslthl">
<fo:inline font-weight="normal" color="{$AlanHL.class}"><xsl:apply-templates mode="xslthl"/></fo:inline>
</xsl:template>
<!--=======================================================================-->
<!-- THE HERO -->
<!--=====================================================================-->
<xsl:template match="xslthl:hero" mode="xslthl">
<fo:inline font-weight="normal" color="{$AlanHL.hero}"><xsl:apply-templates mode="xslthl"/></fo:inline>
</xsl:template>
<!--=====================================================================-->
<!-- STRINGS -->
<!--=====================================================================-->
Expand Down
Loading

0 comments on commit 22165ce

Please sign in to comment.