Language::Dashrep - Dashrep language translator/interpreter
The following sample code executes the Dashrep-language actions specified in the standard input file.
The module also supports direct access to functions that define Dashrep phrases, expand text that contains Dashrep phrases, and more.
See www.Dashrep.org for details about the Dashrep language.
Although Dashrep code is not directly executable, it can generate executable code. Although it does not directly define loops, it generates lists in which any delimited (using commas and/or spaces) list of text strings (including integers) specifies the unique values for the list items. Although the Dashrep language does not directly implement a branching structure, the translated code can be completely changed at any level (including within lists) based on parameterized hyphenated phrases such as [-template-for-move-proposal-link-for-action-[-output-requested-action-]-].
The design goals for the Dashrep language were:
Provide a convenient way to move descriptive code out of executable code.
Keep it simple, and keep it flexible.
Make the language speakable. (This characteristic is useful for various purposes, including circumventing keyboard-induced repetitive-stress injury, and using microphone-equipped mobile devices.)
Note about Version 2 and later: These versions, if they are from GitHub instead of CPAN, can be used without the CPAN envioronment. The GitHub version only needs the Perl interpreter, which means that on the Windows operating system only the perl.exe and perl512.dll and libgcc_s_sjlj-1.dll files (or their more-recent equivalents) are needed.
The following subroutines are exported.
Initialize the phrases with special "dashrep_..." names.
Associates a replacement text string with the specified hyphenated phrase.
First parameter is the hyphenated phrase. Second parameter is its replacement text string.
Return value is 1 if the definition is successful. Return value is zero if there are not exactly two parameters.
Parses text that associates Dashrep phrases with the definitions for those phrases.
First, and only, parameter is the text string that uses the Dashrep language.
Return value is the count for how many hyphenated phrases were defined (or redefined). Return value is zero if there is not exactly one parameter.
Gets/returns the replacement text string that is associated with the specified hyphenated phrase.
First, and only, parameter is the hyphenated phrase.
Return value is the replacement string that is associated with the specified hyphenated phrase. Return value is an empty string if there is not exactly one parameter.
Returns an array that lists all the hyphenated phrases that have been defined so far.
There are no parameters.
Return value is an array that lists all the hyphenated phrases that have been defined. Return value is an empty array if there is not exactly zero parameters.
Deletes the specified hyphenated phrase.
First parameter is the hyphenated phrase.
Return value is 1 if the deletion is successful. Return value is zero if there is not exactly one parameter.
Deletes all the hyphenated phrases.
Return value is 1 if the deletion is successful. Return value is zero if there is not exactly zero parameters.
Parses a text string that is written in the Dashrep language and handles parameter replacements and special operations. The special operations must be within "[- ... -]" text strings. If the supplied text string is just a hyphenated phrase, it is expanded to its replacement string. Otherwise, any hyphenated phrase that does not appear within the square-bracket pattern is not replaced. (Those hyphenated phrases must be replaced using either the dashrep_expand_phrases, dashrep_expand_phrases_except_special, or dashrep_expand_special_phrases subroutines.)
First, and only, parameter is the text -- or hyphenated phrase -- that is to be expanded.
Return value is the text after expanding any parameters. Return value is an empty string if there is not exactly one parameter.
Internal subroutine, not exported. It is only needed within the Dashrep module.
Expands the hyphenated phrases in a text string that is written in the Dashrep language -- except the special (built-in) hyphenated phrases that handle spaces, hyphens, tabs, and line breaks, and except the parameterized phrases.
Return value is the expanded text string. Return value is an empty string if there is not exactly one parameter.
Expands only the the special (built-in) hyphenated phrases that handle hyphens, tabs, spaces and line breaks,
First, and only, parameter is the text string that contains the special hyphenated phrases.
Expands all the hyphenated phrases in a text string that is written in the Dashrep language. This includes expanding the special (built-in) hyphenated phrases that handle spaces, hyphens, and line breaks.
First, and only, parameter is the text string that may contain hyphenated phrases to be expanded.
Converts a single line of XML code into Dashrep code in which XML tags are replaced by Dashrep phrases. Tags are replaced by hyphenated phrases that are named according to the accumulated XML tag names, with "begin-" and "end-" to indicate the beginning and ending tags. The prefix "begin-and-end-" indicates a self-terminating XML tag (e.g. "<br />"). If the resulting phrase has a Dashrep definition, that definition (which is assumed to be a single phrase) is used instead. If the non-tag content contains any hyphens, they are replaced with the phrase "hyphen-here". If a tag's opening bracket (<) and closing bracket (>) are not both on the same line, the tag will not be recognized.
Handles a top-level action such as a transfer to and from files.
First, and only, parameter is the text string that contains any text, which may include one top-level action (which is a hyphenated phrase).
Return value is the text string after removing the executed action, or the original text string if there was no action phrase. Return value is an empty string if there is not exactly one parameter.
Reads from the standard input file, does the specified Dashrep translations, and writes any requested translations into the standard output file.
Return value is a text string that is either empty -- if there is no error -- or else contains an error message (although currently no errors are defined).
Richard Fobes, "CPSolver" at GitHub.com
Please report any bugs or feature requests to "CPSolver" at GitHub.com.
See www.Dashrep.org for descriptions of possible future developments.
Richard Fobes designed the Dashrep (TM) language and developed the original version of this code over a period of many years. Richard Fobes is the author of the book titled The Creative Problem Solver's Toolbox.
Copyright 2009 through 2011 Richard Fobes at www.Dashrep.org, all rights reserved.
You can redistribute and/or modify this library module under the Perl Artistic License 2.0, a copy of which is included in the LICENSE file.
Conversions of this code into other languages are also covered by the above license terms.
The Dashrep (TM) name is trademarked by Richard Fobes at www.Dashrep.org to prevent the name from being co-opted.
The Dashrep (TM) language is in the public domain.
To install Language::Dashrep, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.