Skip to content

Instantly share code, notes, and snippets.

View spoenemann's full-sized avatar

Miro Spönemann spoenemann

View GitHub Profile
@spoenemann
spoenemann / extension.ts
Last active May 18, 2022 05:25
VS Code language client with stdio + socket
import * as net from 'net';
import * as vscode from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, StreamInfo } from 'vscode-languageclient';
const DEBUG = false;
const SERVER_PORT = 5008;
export function activate(context: vscode.ExtensionContext) {
const languageClient = DEBUG
? getSocketLanguageClient({ serverPort: SERVER_PORT })
@spoenemann
spoenemann / class-service.ts
Last active May 14, 2021 07:24
Comparison of class-based vs. function-based DI service
export const ScopeComputationKey: BindingKey<ScopeComputation> = { id: 'ScopeComputation' };
export class ScopeComputation implements DIService {
private nameProvider: NameProvider;
initialize(services: ServiceHolder): void {
this.nameProvider = services.get(NameProvider);
}
@spoenemann
spoenemann / example_c.txt
Created May 24, 2017 08:40
Example of generated C code
Bag* __local_0 = this->bag;
Wallet* __local_1 = __local_0->wallet;
double __local_2 = __local_1->cash;
@spoenemann
spoenemann / tracing_codegen_4.xtend
Created May 24, 2017 08:39
Example code that constructs a traced generator subtree
val n = trace(expression)
val receiverVar = expression.receiver?.generateExpression(n, scope)
val resultVar = scope.nextVarName
n.append(generateType(expression.feature?.type))
n.append(' ')
n.append(resultVar)
...
n.append(' = ')
n.append(receiverVar ?: 'this')
n.append('->')
@spoenemann
spoenemann / tracing_codegen_3.xtend
Created May 24, 2017 08:38
Example usage of the TracedAccessors active annotation
@TracedAccessors(MyDslFactory)
class MyDslTraceExtensions {
}
@spoenemann
spoenemann / tracing_codegen_2.xtend
Created May 24, 2017 08:37
Traced method for translating a class declaration into a C struct
@Traced protected def generateHeader(ClassDeclaration it) '''
/*
* Declaration of «name» class
*/
struct _«_name»
{
«FOR p : members.filter(Property)»
/* Property «name».«p.name» */
«generateDeclaration(p)»
«ENDFOR»
@spoenemann
spoenemann / tracing_codegen_1.xtend
Created May 24, 2017 08:36
Entry method of the example code generator with tracing
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
val model = resource.contents.head as Model
val baseName = resource.baseName
fsa.generateTracedFile(baseName + '.h', model, '''
/********************************
* Header file for «resource.URI.lastSegment»
*/
#ifndef «baseName.toUpperCase»_H
#define «baseName.toUpperCase»_H
@spoenemann
spoenemann / example_classes.mydsl
Created May 24, 2017 08:34
Simple class DSL example
class Person {
name: string
bag: Bag
getCash(): number {
bag.wallet.cash
}
}
class Bag {
wallet: Wallet
}
@spoenemann
spoenemann / HomeAutomation.xtext
Last active October 21, 2021 15:35
vJUG Demo
grammar org.xtext.example.home.HomeAutomation with org.eclipse.xtext.common.Terminals
generate homeAutomation "http://www.xtext.org/example/home/HomeAutomation"
//--- Model Example
// Device Window can be OPEN, CLOSED
// Device Heating can be ON, OFF
//
// Rule 'Close the window when heating is turned on'
@spoenemann
spoenemann / gist:6c7259458e52ff998acf
Last active August 29, 2015 14:21
Configuration code for embedding an Xtext editor in a web page (beta2 version)
<link rel="stylesheet" type="text/css" href="xtext/2.9.0.beta2/xtext.css"/>
<script src="webjars/requirejs/2.1.17/require.min.js"></script>
<script type="text/javascript">
require.config({
paths: {
"text": "webjars/requirejs-text/2.0.10-3/text",
"jquery": "webjars/jquery/2.1.4/jquery.min",
"xtext/xtext": "xtext/2.9.0.beta2/xtext"
}
});