Home  |   Learn  |   Demo  |   Specs  |   Downloads  |   Convert  |   Discuss

Learning the Dashrep language

Learning by example

The best way to learn any language is through examples.  So here are examples that progressively reveal how the Dashrep language works.

Example 1

Demonstrates simple replacement.  First, here is the Dashrep code.

i-b book-title i-e
book-title: Tom Sawyer ----
i-b: <i> no-space ----
i-e: no-space </i> ----

And here is the result after a Dashrep engine expands the entire-content phrase.

<i>Tom Sawyer</i>

Notice that each hyphenated phrase is defined as the text that follows its name, up to (but not including) the adjacent hyphens.  (Line breaks at the beginning and ending of the definition are ignored, and elsewhere a line break is replaced by a single space.)  The phrase entire-content is expanded by replacing each phrase in its definition with the definition of that phrase.  After those replacements, the no-space phrases are removed and all the spaces are removed from those locations.

This example demonstrates that Dashrep code can be used as a markup language for a document.  In fact, an early version of this language was used to write the book titled The Creative Problem Solver's Toolbox.


Example 2

Demonstrates a parameter.  First, here is the Dashrep code.

animal-name: parrot ----
characteristic-for-parrot: talkative ----

And here is the result after a Dashrep engine expands the entire-content phrase.

The parrot is talkative

The hyphenated phrase surrounded by [- and -] is replaced (by the word parrot) before the full hyphenated phrase is determined to be characteristic-for-animal-named-parrot, which then replaced by the word talkative.  Parameters (with their square brackets) can be nested to any level.


Example 3

Demonstrates more advanced replacement.  This code was extracted from a website (www.NegotiationTool.com) that builds each unique web page when the page is requested.  To complete this example, executable code (in Perl, Java, Python, etc.) would define the hyphenated phrase web-page-content to equal page-welcome.

classWelcomeTitle  format-heading-level-1-begin-after-class
words-welcome-title  format-end-heading-level-1
classWelcomeIntro  format-heading-level-2-begin-after-class
words-welcome-intro  format-end-heading-level-2
Welcome to NegotiationTool.com
This free negotiation tool  line-break
produces fair outcomes for  line-break
complex (and simple) negotiations.
<h1 class="  no-space
no-space  ">
no-space  </h1>


Example 4

Demonstrates nested parameter replacement capability.  (Line is wrapped here.)



Example 5

Demonstrates list generation.

[-create-list-named: participant-names-]
words-list-of-participants-usage-page-title  format-end-heading-level-1
table-begin-before-class  classTableStandard  table-begin-after-class
table-row-begin  table-cell-begin
table-cell-end  table-row-end


More examples

The Demo and Downloads pages contain more examples. 

If you want to experiment with translating some of your own Dashrep code, go to the Convert page.


Full specifications

See the specifications page for the full Dashrep language specifications.


Debugging tips

Most bugs can be fixed using one of these tips.

Symptom How to fix
A hyphenated phrase unexpectedly appears in the result. Search the Dashrep code for that phrase, or the unexpected portion of that phrase.  That phrase, or the unexpected portion, with that spelling should appear at least twice, once for its definition, and at least once for its use.
Square brackets unexpectedly appear in the result. There are two possibilities.  If they appear in the definition of the phrase being expanded, remove those square brackets.  Otherwise, add square brackets (with adjacent hyphens) around each hyphenated phrase that leads to those untranslated square brackets.
An endless-loop error occurs. Search for all occurrences of the hyphenated phrase that is named in the endless-loop error message, and look for a replacement path that includes the hyphenated phrase in its definition.  If the Dashrep translation intentionally produces a large result, try increasing the endless-loop-count limit.
You don't know what value is (or, in a list, what values are) getting assigned to a specific hyphenated phrase. Insert the phrase as a separate item (in the same area of code) and view its value(s) in the result.

Additional tips

To delay the expansion of a phrase (such as “no-space”) use a different, temporary phrase (such as “delayed-nospace”) and later replace the temporary phrase with the desired phrase (which will then be expanded or converted).

Whereas in a traditional language you would use the "print" statement to display the value of a variable, in the Dashrep language you can simply write whatever you want to view (without the need for a "print" statement or quotation marks).  This approach is useful whenever you want to know the expanded value of any hyphenated phrase.

When you want to see what's going on and don't know what to look for, try writing all the definitions to a file (using the “write-all-dashrep-definitions-to-file” action) and viewing the file.

Some simple “trace” viewing capabilities can be turned on and off using special dashrep phrases.


Top of Page                © Copyright 2009 through 2011 by Richard Fobes at www.Dashrep.org.