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.

entire-content:
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.

entire-content:
The
animal-name
is
characteristic-for-[-animal-name-]
----
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.

entire-standard-web-page:
web-page-begin-1-of-2
possible-javascript-in-heading
possible-error-message
web-page-begin-2-of-2
web-page-content
web-page-end
--------
page-welcome:
rectangle-outline-attention-begin
format-heading-level-1-begin-before-class
classWelcomeTitle  format-heading-level-1-begin-after-class
words-welcome-title  format-end-heading-level-1
format-heading-level-2-begin-before-class
classWelcomeIntro  format-heading-level-2-begin-after-class
words-welcome-intro  format-end-heading-level-2
rectangle-outline-attention-end
--------
words-welcome-title:
Welcome to NegotiationTool.com
--------
words-welcome-intro:
This free negotiation tool  line-break
produces fair outcomes for  line-break
complex (and simple) negotiations.
--------
format-heading-level-1-begin-before-class:
<h1 class="  no-space
--------
format-heading-level-1-begin-after-class:
no-space  ">
--------
format-end-heading-level-1:
no-space  </h1>
--------

 

Example 4

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

[-template-for-list-named-move-proposal-links-[-yes-no-permission-for-action-
[-next-move-link-action-for-action-[-output-requested-action-]-]-]-]

 

Example 5

Demonstrates list generation.

page-participants-list:
[-create-list-named: participant-names-]
[-heading-at-top-of-page-]
format-begin-heading-level-1
words-list-of-participants-usage-page-title  format-end-heading-level-1
rectangle-outline-attention-begin
table-begin-before-class  classTableStandard  table-begin-after-class
generated-list-named-participant-names
table-end
rectangle-outline-end
bottom-of-page
--------
parameter-name-for-list-named-participant-names:
parameter-participant-id
--------
list-of-parameter-values-for-list-named-participant-names:
[-case-info-idlistparticipants-]
--------
template-for-list-named-participant-names:
participant-name-for-participantid-[-parameter-participant-id-]
--------
prefix-for-list-named-participant-names:
table-row-begin  table-cell-begin
--------
suffix-for-list-named-participant-names
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.