Skip to content

Files

Latest commit

Nov 13, 2019
1650ca3 · Nov 13, 2019

History

History
55 lines (28 loc) · 6.62 KB

Developer.md

File metadata and controls

55 lines (28 loc) · 6.62 KB

EasyCoder Developer's Manual

EasyCoder is a high-level scripting language for web browsers. It is designed to enable the construction of interactive websites and web applications of any size without the need to learn any JavaScript or its associated frameworks. It can be used successfully for just about anything except projects that require high-speed animation, such as platform games.

This does not imply that EasyCoder is complete in all respects and able to tackle any job without any help. The core of the language, as supplied here, can deal with most common needs but there are always special cases that go beyond what was envisaged by its creators. So we built in a plugin mechanism that allows you to add extensions to the language that then provide seamless additions to its vocabulary and syntax. Whenever it become clumsy - or impossible - to express something using the system as provided, a plugin will usually deal with the problem in a more efficient way.

The raw performance of EasyCoder code is admittedly well below what can be achieved in JavaScript alone. However, the power of JavaScript is now so great that it permits considerable coding inefficiency while still delivering good results. The trade-off here is between performance on the one hand and ease of construction allied to ease of maintenance on the other. In the case of most websites the latter is by far the more important.

This manual describes how EasyCoder works and how to add plugin extensions to it.

EasyCoder was built as a WordPress plugin, in which environment a PHP file (easycoder.php) performs various duties to ensure the environment is set up for EasyCoder itself. However, EasyCoder is not dependant upon WordPress and can be used just as easily outside that environment. The only difference is the programmer must attend to the setup details when installing EasyCoder but this is not an onerous task and I'll mention the relevant issues as I come to them.

The system comprises a number of JavaScript files; one core script and several plugin modules in their own directory. The core script is specified in the HEAD of the page; it's called either easycoder.js or easycoder-min.js depending if you need to debug your scripts at that level. These files aren't to be found in the GitHub repository as they're constructed by the build process, so here are a few words about that.

The Build Process

EasyCoder is a relatively simple project so its build needs are also fairly simple, requiring only a shell script. The Bash script build shows how it's done on one particular Linux setup, where the project is kept in a DropBox folder and the final file set is sent to a top-level folder called EasyCoder. Most other developers would need to make appropriate alterations to the file paths.

The tools required for the build are the 2 Node modules babel and browserify, plus Google's closure, which minifies the core script.

From the top

The script EasyCoder.js is where things start. When it loads it initializes a timestamp variable and waits for the page to finish its initial load. On receipt of the window.onload() signal it logs the elapsed time and resets the timestamp, which is used to report progress as the page loads to help the developer optimise things and achieve a good load time.

Next it looks for a DOM element with the id easycoder-script, which identifies the main script. You can use any container but a PRE or a DIV are recommended. The contents of this element are passed to the start() function in Main.js.

Main.js

Much of the functionality of EasyCoder is in plugins, not all of which are required by every page. To avoid loading code that won't be needed we have a small script, plugins.js,located in a folder called easycoder at the top level of the site installation, that defines which plugins should be loaded up front for this website. In a WordPress environment this file will be created when the EasyCoder plugin is installed, but for other systems the developer must do this when installing EasyCoder. There's a sample file, plugins-sample.js in the EasyCoder directory that you can use either "as is" or suitably modified.

plugins.js also defines plugins that should be made available for scripts to load on demand. These can be local files or can be external URLs. In the latter case you will almost certainly have to deal with CORS issues that prevent browsers from loading potentially harmful files.

loadPluginsJS() attempts to load plugins.js. This will usually succeed except for special cases where your site code is not at the level of the site root. If the load fails the script backs up one level and tries again.

When the load succeeds, the script calls getGlobalPlugins(), handing it the number of plugins required and a list of those plugins. Each of these is requested in turn, and when all have been loaded successfully a call is made to tokenize() to process the script that was handed in at the start.

Whether you use WordPress or are building a site without it you may need to edit the contents of plugins.js to include plugins that aren't listed by default. In WordPress this file is not affected by updates to either the theme or to the EasyCoder plugin.

tokenize(), tokeniseAndCompile() and tokenizeFile()

These 3 functions work together to convert the incoming text file into a list of tokens for the compiler to process. They also create a list of script lines, which is used for debugging and for error reporting. The list of tokens has all comments removed (to save space) and each token is an object with the source line number and the text of the token. Tokens are delimited by white space but string values are single tokens that may include spaces, so the tokenizer has to go through the script looking for the backticks that bracket strings. Note that the compiler pretty well ignores line breaks so a command can be on one line or may span several, but neither a string nor a comment can extend from one line to another.

So now we have a list of source lines, a list of tokens and a list of plugins. It's time to start the compiler.

compileScript()

This function injects some properties into the EasyCoder_Compiler script then calls the compile() function in that script. If compilation succeeds it gets back a program object. It then sets a rather longer list of properties into that object before returning it to the tokenizer, which passes it to EasyCoder_Run for execution.

Next: The EasyCoder Compiler

The Keyword Compilers

The Runtime Engine

The ReST Server