Source Code Semantics from Styles

The idea is to make styling a language feature, which defines semantics of language elements. Also, the idea of projection editors is not new, so combine styling and projection editor into a hybrid editor.

This is an experiment to present a source code and work with it in hybrid, text and tree nodes, manner.

In modern programming language, source code is a pure non-styled text, where semantics of all language elements are retrieved from language grammar and syntax. Though, modern IDEs highlight and colorize source code for readability.

A source code is not written anymore, but is composed from statements and other language elements with predefined structure. Source code still looks like a text, but it is a tree (which is close to AST). Every statement or expression has a specific style that specifies the semantic of statement/expression.

Styling and predefined structures remove all possible uncertain issues with source code as a text, like tabs vs spaces, how long should be an indentation step, empty lines, on which line put open brace etc. Moreover, some programming language keywords become redundant, because the semantic is defined by the style of a statement/expression.

There are a few interesting consequences from this hybrid editor approach.

Some language elements can be a result of semantics of a statement/expression. For example, quotes for string literals are not required at all: a style specifies a sequence of characters that compose a string. No problem with escaping, new line symbols etc. So, any text marked up with string literal style is a string, and the style adds quotes before/after the text.

The number of commas, semicolons, braces, and other separating symbols, which delimit such elements like statements in a block or parameters in a parameter list, are decreased significantly. Styles specify the boundaries of statements/expressions or some lists.

Possible use cases for the such hybrid editor could like these. A one types a text that by default interpreted as a comment, then selects the text and specifies its style as an if statement for example. The text converted into styled block with fixed structure for a predicate and if/else code blocks. Or other user case, where a one just puts an if statement with fixed structure and fills predicate and code blocks.

Of course, the idea of projection editors is not new one. But seems it practically is not applicable to modern programming languages because of the complexity of their grammars/syntaxes. In Paml, there are a few statements and expressions, because Paml is a modeling language with high abstract statements/expressions. So, a hybrid editor for Paml can have a chance in the experiment to be a useful tool.

object
{
string
Alonzo.Polo.ProcessStatus
Alonzo.Polo.Kernel
Kind Routine
Id
Name
Tags
StopProcess this.Kernel
this
Kind Routine
Id
Name
Tags
StartProcess this.Kernel
this.Name
priority Alonzo.Polo.ThreadPriority
Kind Routine
Id
Name
Tags
Alonzo.Polo.Thread
Start thread
this.Threads thread
or
this.Threads
thread
Kind Routine
Id
Name
Tags
string
This is a text.
1000 1900
120,-35 10,10 -100,-3
points point
select
Kind Routine
Id
Name
Tags
point.X x
or
Kind Routine
Id
Name
Tags
point.X
x
forEach
Kind Routine
Id
Name
Tags
x
This is a return statement
var2
}

Write a comment

Comments: 0

Pallada project, Copyright © 2015 - 2018.

For any mentions and citations of the site materials, a link to the Pallada project site is obligatory.