question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CST Creation customizations

See original GitHub issue

I noticed something strange about this:

  body = this.RULE('body', () => {
    this.MANY(() => {
      this.SUBRULE(this.key);
      this.SUBRULE(this.value);
    });
  });

vs

  body = this.RULE('body', () => {
    this.MANY(() => {
      this.SUBRULE(this.keyValue);
    });
  });

  keyValue = this.RULE('keyValue', () => {
    this.SUBRULE(this.key);
    this.SUBRULE(this.value);
  });

In the first case, the output CST results in a case where the keys are grouped into their own array, and the values are then grouped in their own array. While in the second case the key and value are kept within a single key value combination, and then grouped into an array.

I had it the first way first, and tried to create an interpreter for the resulting output cst, but realised that it wasn’t going to work because of how the key and value was separated. So I tried to do it the second way instead. But I think it’s somewhat non-intuitive that:

this.MANY(() => {
  this.SUBRULE(this.k);
  this.SUBRULE(this.v);
});

Doesn’t mean how (kv)* would be interpreted to mean a sequence of kvs, and should give [kv, kv, kv]. But instead right now it’s [k,k,k,k], [v,v,v,v].

Another example is:

  value = this.RULE('value', () => {
    this.MANY(() => {
      this.OR([
        {ALT: () => { this.CONSUME(ValueSpaceT); }},
        {ALT: () => { this.CONSUME(ValueStringT); }},
        {ALT: () => { this.CONSUME(ValueQuotedStringT); }}
      ]);
    });
  });

In the output CST I get ValueSpaceT: [...], ValueStringT: [...], ValueQuotedStringT: [...]. Now I don’t know what the relative order between each token is, so I cannot concatenate the value of all these tokens.

Compare to the usage of embedded actions: https://github.com/sgarciac/bombadil/blob/master/src/parser.ts#L8-L21 which shows the ability to rely on the exact ordering to perform side effects during the parsing.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
bd82commented, Nov 17, 2018

I got one of the methods to compile using some casing and “@ts-ignore” comments.

    cstPostTerminal(this:any, key, consumedToken) {
        // "standard" addition to the children dictionary
        // @ts-ignore
        super.cstPostTerminal(key, consumedToken)

        // Add Terminal to childList
        const previousCstNode = this.CST_STACK[this.CST_STACK.length - 1]
        previousCstNode.childList.push(consumedToken)
    }
1reaction
bd82commented, Feb 21, 2018

Looked deeper into this. This could be implemented using the following overrides of the Parser methods:

class MyParserWithCstLists extends Parser {
    cstInvocationStateUpdate(fullRuleName, shortName) {
        // default initialization
        super.cstInvocationStateUpdate(fullRuleName, shortName)

        // Init the child List
        const currentCstNode = this.CST_STACK[this.CST_STACK.length - 1]
        currentCstNode.childList = []
    }

    cstPostNonTerminal(newCstNode, newRuleName) {
        // "standard" addition to the children dictionary
        super.cstPostNonTerminal(newCstNode, newRuleName)

        // Add nonTerminal to childList
        const previousCstNode = this.CST_STACK[this.CST_STACK.length - 1]
        previousCstNode.childList.push(newCstNode)
    }

    cstPostTerminal(key, consumedToken) {
        // "standard" addition to the children dictionary
        super.cstPostTerminal(key, consumedToken)

        // Add Terminal to childList
        const previousCstNode = this.CST_STACK[this.CST_STACK.length - 1]
        previousCstNode.childList.push(consumedToken)
    }

   // ...

Of course the CST visitor would also have to be modified to expose that “childList”. Or alternatively the “childList” itself could be placed on the children dictionary to work around that issue.

I think this example should suffice for now, I will reconsider investing more effort into this (proper interfaces / runnable examples) if and when there would be more requests for such capabilities.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CST Creation customizations · Issue #603 - GitHub
In the first case, the output CST results in a case where the keys are grouped into their own array, and the values...
Read more >
CST Studio Suite - Circuit Simulation and SAM
Customizing Result View Properties . ... Creation and insertion of text boxes and images inside the drawing for documentation purposes.
Read more >
Customizing the CST | Steel-Belted Radius Carrier 8.3.0 ...
A key benefit of Session State Register is that you can modify the CST to meet ... Creation of custom stored procedures requires...
Read more >
CST MICROWAVE STUDIO - Workflow and Solver Overview
In the material creation dialog box, enter the Material name “air," select Normal dielectric properties (Type) and check the material properties ...
Read more >
Training | Introduction to CST Studio Suite - Dassault Systèmes®
Throughout this course you will become familiar with the CST Studio Suite interface and how to perform basic tasks in terms of modeling,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found