Code Monkey home page Code Monkey logo

textgengen's Introduction

Fork by Fumapps

This fork is an extension of the TextGenGen MPS plugin. It mainly extends it by:

  • unit tests: several automated tests, which are used to fix several spacing issues
  • generator-based contents check: a (light) diff mechanism, which tries to detect if TextGen nodes have not really changed
  • github actions: contains GitHub actions workflows for integration or release builds
  • GrammarCells: support for generating mps-extensino grammarcells (without adding a dependency on it)
  • single node TextGenGen: support to generate TextGenGen only on a single concept node

TextGenGen

TextGenGen is an MPS plugin for generation of TextGen definitions derived from Editor definitions, so that the text generated by TextGen is the same as the one rendered on the screen by the Editor.

Getting started

This version/fork of the plugin is not on the JetBrains MPS Marketplace. A zip with the built plugin is supplied with every release on the github releases page.

However, if you want to make any modification to the plugin, you could find useful these guides:

To build the plugin:

  • Define the TEXTGENGEN_HOME path variable
    • Go to File > Settings > Apppereance & Behavior > Path Variables
    • Add a new variable with the name TEXTGENGEN_HOME and the value of the path to the top-most directory of the TextGenGen project (e.g. C:\Users\yourName\MPSProjects\textGenGen)
  • Open the TextGenGen project in MPS
  • Expand the TextGeGEn.build item in the project explorer
  • Right-click the TextGenGen item with a spider icon
  • Trigger Run TextGenGen
  • The plugin ZIP file is located in the directory hierarchy of the project (build/artifacts/TextGenGen)

To install the plugin:

  • Open MPS
  • Go to File > Settings > Plugins > Install plugin from disk... and locate the ZIP archive
  • After a MPS restart, the plugin should be loaded

To use the plugin:

For the primary function of the plugin:

  • Make sure you do not have any local work in the TextGen Aspect of your language, as it will be overwritten
  • Right click your language in the MPS logical view and select Generate TextGen
  • The TextGen Aspect of your language will be generated based on the implemented Editor Aspect
  • Possibilities to customize the behavior:
    • Editor cells that should be ignored when generating the TextGen Aspect can be marked as such by setting their cell id to ignoreTextGenGen

For the second function

  • Right click any model (i.e. model in a Solution or Aspect (or other kind of model) in a Language) and select Save as Text.
  • You will be prompted for the filesystem location and file extension to use.
  • After entering the data and pressing Ok, the plugin will export a textual representation of all nodes in the model as they are rendered on the screen.

Release log

For changes on this fork please look at the github releases page.

Changes brought by version 1.1, 11/2019:

  • Fix spacing between elements of a ref-node list
  • Add support for editor cells representing AST references
  • Implementation of enumeration support
  • Refactoring of deprecated parts

Major changes brought by version 1.0, 9/2019:

  • Generation of TextGen removes the previously generated TextGen and does not ask for a prefix anymore
  • Newly supported aspects of the Editor (so that the generated TextGen respects them):
    • Show if at an Editor cell
    • Editor components (the #alias# component too)
    • Empty cell models at a child reference list and/or a child reference
  • Improved implementation of indentation and spacing generation
  • Refactoring: redesign of the plugin core to a more pure form, documentation of the code

Version 0.4

  • Support of simple Editor constructs
  • The design is basically prepared to be extended by support of more complex Editor constructs

Development notes

Design overview

Plugin Core

The entry-point object of the plugin core is EditorToTextGenConvertor, which provides generation of TextGen for a given Editor. This object uses the EditorCellToTextGenConvertor object to generate TextGen chunks corresponding to individual Editor cells. This object uses the Gang-of-Four Builder pattern: it delegates generation of smaller, general chunks of the TextGen to the TextGenBuilder object.

TextGenBuilder is intended to be Editor-independent so it should not contain any knowledge of the Editor structure and should understand the TextGen structure only.

The utils virtual package contains some helper classes:

  • CustomStyleContainer: A wrapper for styling from Editor cells
  • Value, Constant, Query: Wrappers for (run-time evaluated) conditions
  • NameProvider: A generator of unique identifiers
  • StatementsBuffer: A holder for TextGen statements which executes some basic optimizations of the inserted statements
  • Utils: General utility methods

textgengen's People

Contributors

fumapps avatar wirthma avatar kripner avatar vaclav avatar neumantm avatar

Stargazers

 avatar  avatar

Forkers

neumantm

textgengen's Issues

Exception when running the textGenGen while no TextGen Aspect exists

When running the Gen TextGen action, while the language has no TextGen Aspect, I get the following error.
The TextGen Aspect is created, but empty after this.

java.lang.Throwable: Assertion failed: Write access is allowed inside write-action only (see com.intellij.openapi.application.Application.runWriteAction())
	at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:220)
	at com.intellij.openapi.application.impl.ApplicationImpl.assertWriteAccessAllowed(ApplicationImpl.java:1336)
	at jetbrains.mps.ide.vfs.IdeaFile.openOutputStream(IdeaFile.java:499)
	at jetbrains.mps.extapi.persistence.FileDataSource.openOutputStream(FileDataSource.java:118)
	at jetbrains.mps.util.JDOMUtil.writeDocument(JDOMUtil.java:132)
	at jetbrains.mps.smodel.persistence.def.ModelPersistence.saveModel(ModelPersistence.java:238)
	at jetbrains.mps.persistence.DefaultModelPersistence$PersistenceFacility.saveModel(DefaultModelPersistence.java:370)
	at jetbrains.mps.smodel.DefaultSModelDescriptor.saveModel(DefaultSModelDescriptor.java:138)
	at jetbrains.mps.extapi.model.EditableSModelBase.save0(EditableSModelBase.java:280)
	at jetbrains.mps.extapi.model.EditableSModelBase.save(EditableSModelBase.java:238)
	at jetbrains.mps.project.SModuleOperations.createModelWithAdjustments(SModuleOperations.java:132)
	at jetbrains.mps.project.SModuleOperations.createModelWithAdjustments(SModuleOperations.java:107)
	at jetbrains.mps.smodel.LanguageAspect.createNew(LanguageAspect.java:169)
	at jetbrains.mps.smodel.LanguageAspect.createNew(LanguageAspect.java:156)
	at TextGenGen.plugin.plugin.TextGenGenerationProcessor.executeGenerateAction(TextGenGenerationProcessor.java:76)
	at TextGenGen.plugin.plugin.TextGenGenerationProcessor.lambda$generateTextGen$0(TextGenGenerationProcessor.java:51)
	at TextGenGen.plugin.plugin.AsyncWriteAction.lambda$execute$0(AsyncWriteAction.java:19)
	at jetbrains.mps.smodel.ActionDispatcher.dispatch(ActionDispatcher.java:98)
	at jetbrains.mps.smodel.ActionDispatcher.lambda$wrap$0(ActionDispatcher.java:135)
	at jetbrains.mps.smodel.LockRunnable.run(LockRunnable.java:60)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:915)
	at jetbrains.mps.smodel.WorkbenchModelAccess.runWriteAction(WorkbenchModelAccess.java:100)
	at jetbrains.mps.smodel.ModelAccessBase.runWriteAction(ModelAccessBase.java:66)
	at TextGenGen.plugin.plugin.AsyncWriteAction.lambda$execute$1(AsyncWriteAction.java:18)
	at java.base/java.lang.Thread.run(Thread.java:833)

Version 2022.2-beta2

punctuation style ignored on boundries between multiple children in horizontal child collection

When the editor has a horizontal child collection, where the last editor cell of the children has punctuation-right: true (or the first has punction-left: true) there is no space between the children of the collection in the editor.

However, textGenGen always generates this:

if (elem.next-sibling.isNotNull) { 
  // horizontal child collection: insert spaces between the elements  
  append { } ; 
}

This is not in line with how the editor renders it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.