Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jun 12 22:52
    bd82 closed #1537
  • Jun 12 22:52
    bd82 commented #1537
  • Jun 12 22:51
    dependabot[bot] edited #1543
  • Jun 12 22:48
    dependabot[bot] edited #1543
  • Jun 12 22:48
    dependabot[bot] synchronize #1543
  • Jun 12 22:48

    dependabot[bot] on npm_and_yarn

    build(deps-dev): bump typescrip… (compare)

  • Jun 12 22:48
    dependabot[bot] edited #1543
  • Jun 12 22:46
    dependabot[bot] edited #1543
  • Jun 12 22:46

    bd82 on v9.0.2

    (compare)

  • Jun 12 22:46

    bd82 on master

    chore(release): release (compare)

  • Jun 12 22:46

    bd82 on gh-pages

    Update Website (compare)

  • Jun 12 22:45

    bd82 on gh-pages

    update api website (compare)

  • Jun 12 18:42
    bd82 commented #1543
  • Jun 12 18:41

    bd82 on master

    chore: prepare changelog for re… (compare)

  • Jun 12 18:33
    bd82 edited #1537
  • Jun 12 18:32
    bd82 edited #1538
  • Jun 12 14:20
    dependabot[bot] edited #1467
  • Jun 12 14:19
    dependabot[bot] edited #1543
  • Jun 12 14:16
    dependabot[bot] synchronize #1543
  • Jun 12 14:16
    dependabot[bot] edited #1543
Lukas Kohler
@luxferresum
I dont know what datatype it must return, a boolean or a number
especially in assignments. sometimes I do know, but sometimes dont
Matthew Dean
@matthew-dean
i don't follow
Lukas Kohler
@luxferresum
I have
foo1 := bar + baz;
foo2 := bla AND blaz;
Matthew Dean
@matthew-dean
remember that each of those joins is optional
Lukas Kohler
@luxferresum
hm, I see, and how would I sometimes enforce them?
like, then I know it must be a boolean (for an if) I want to enforce it
Matthew Dean
@matthew-dean
you use GATEs
Lukas Kohler
@luxferresum

remember that each of those joins is optional

but this is probably my problem, I did not think about that

Matthew Dean
@matthew-dean
one way to think about the above is that it's like:
foo := compare(addition(bar, '+' baz), null, null) In other words, in your CST -> AST, anything with only left-side nodes just returns the left-side node
like once you get that the nodes are always nested at parsing time, it starts to click
every time there's just a left-side node and no operator, return the left side
Lukas Kohler
@luxferresum
so something like this:
    $.RULE('mathVal', () => {
      $.OPTION(() => $.CONSUME(Sym.Minus));
      $.SUBRULE(() => $.SUBRULE($.plainVal));
    });

    $.RULE('mathExpression', () => {
      $.SUBRULE($.mathVal);
      $.MANY(() => {
        $.CONSUME(MathOP);
        $.SUBRULE2($.mathVal);
      });
    });

    $.RULE('compExpression', () => {
      $.SUBRULE($.mathExpression);
      $.MANY(() => {
        $.CONSUME(MathCompOP);
        $.SUBRULE2($.mathExpression);
      });
    });

    $.RULE('expression', () => {
      $.SUBRULE($.compExpression);
      $.MANY(() => {
        $.CONSUME(BoolOP);
        $.SUBRULE2($.compExpression);
      });
    });
Matthew Dean
@matthew-dean
ha dude I need to get back to work
Lukas Kohler
@luxferresum
hey, :thumbsup: MANY MANY thanks!
Matthew Dean
@matthew-dean
one last note: what helped me was looking at examples of other Chevrotain parsers that parse similar expressions. It will click
Lukas Kohler
@luxferresum
yeah, sadly there are not that many simple examples
Matthew Dean
@matthew-dean
I know, mine isn't simple either, but there are a few in the Chevrotain repo
Lukas Kohler
@luxferresum
thanks a lot
Matthew Dean
@matthew-dean
no problem
Shahar Soel
@bd82
@matthew-dean : Longer ALT cannot be chained, only one alternative may be given.
Can you create a single token to handle both your dash and none dash identifiers? You could theoretically create it as a custom token type if there is some logic needed to avoid it consuming chars as an Identifier in edge cases.
Matthew Dean
@matthew-dean
@bd82 I previously had a single token to handle both cases. So in tokenization, that works fine, the problem is in parsing, I want to distinguish cases.
Matthew Dean
@matthew-dean
is there a way to use a custom token to "mark" a token in such a way that CONSUME can distinguish tokens?

Longer ALT cannot be chained, only one alternative may be given.

Is there a reason why it doesn't check the next longer_alt on the token that the first longer_alt points to?

Matthew Dean
@matthew-dean
Like, if the custom token could produce a custom category (or categories), for example, that would be really sweet.
Just some way to alter the token output in a way that the parser can distinguish in a CONSUME hmmm
Matthew Dean
@matthew-dean
I guess the worse-case scenario is I could detect dash-idents at the CST->AST phase
Shahar Soel
@bd82
I don't think there is a direct way to acomplish what you want.
But I think your custom token can mark it's instances somehow (e.g custom payloads feature) and then you can process the tokens between the lexer and the parsing stage.
There is no "good" reason for not testing multiple "longer_alts" I just did not have such a need in the past.
Maybe one good reason to avoid it, is the risk of cyclic loops of longer_alts that could cause infinite loops.

The Custom Token is more like a custom matcher that would produce any kind of random token type.
It is a matcher that produces a single token type.

I would be hesitant to upgrade the lexer to support this functionality, both because its the first time I heard a use case for it and because at some point I'd like to re-write the lexer to be a simpler more streaming lexer and I'm wary for super advanced features.

Matthew Dean
@matthew-dean

Maybe one good reason to avoid it, is the risk of cyclic loops of longer_alts that could cause infinite loops.

tbh, I think that's more of an end user concern, just knowing that A shouldn't call B which calls A

It's a nice to have, but I do have some workarounds, so whatever you decide to do is fine.

I do think it's at least worth noting that they can't be chained? Because I intuited that it was "matching the next token", and that matching the next token came with all of the default token-matching behaviors, including looking at its own longer_alt prop. As in, Chevrotain's current documentation / language around this led me to believe this could work, even though there was no example of chaining.
1 reply
Matthew Dean
@matthew-dean
New CSS pre-processor using Chevrotain! (In alpha) https://www.npmjs.com/package/jess
1 reply
Shahar Soel
@bd82
Hello the Chevrotain project is being moved to github.com/chevrotain/chevrotain I am not sure whats is going to happen to this gitter Chat, possible issues expected...
Shahar Soel
@bd82
Please use the new Github discussions feature instead of gitter.
Balint Maschio
@bmaschio
hello everyonw
everyone
Shahar Soel
@bd82

Hello @bmaschio

Please use: https://github.com/Chevrotain/chevrotain/discussions if you have any questions.

Austin Turner
@paustint
I am attempting to upgrade from version 5.x to latest (not 9.x because typescript is broken in this release, I filed an issue) and I used to be able to define private helper methods on my visitor e.x. private $_getFieldFunction(...) but now I am getting an error message There is no Grammar Rule corresponding to this method's name. Some of these helper methods call this.visit. What is the proper way to include helper functions on my visitor class?
3 replies
Lukas Köbis
@lukas1994
Hi everyone, I'm having an issue with if statements in my grammar. If you paste https://pastebin.com/btshX5jJ in https://chevrotain.io/playground/ and then use the expression if 3 = 2 or 3 != 3 then 1 else 0 you'll see the issue. I've dealt with quite a few uniqueness issues in the past but this one looks like a different issue. It'd be great if someone could take a look. I'd appreciate some help :)
4 replies
ivan-abdulin
@ivan-abdulin

Hello guys. Need your advice on how to correctly implement an EVAL function (basically thing that takes code as a string and runs it). I've got it working in the most basic example here
https://github.com/ivan-abdulin/chevrotain-eval-example/tree/master
also a direct link to a file with implementation for your convenience
https://github.com/ivan-abdulin/chevrotain-eval-example/blob/master/index.ts

The thing is - this implementation is an ugly hack. It is not architecturally sound and it creates loopholes, like nested calls => EVAL("EVAL("1 + 1")") and etc. So are there better ways to do it, then just passing a lexer and parser into visitor?
Any advice? Any documentation links I should read or ready-made examples?

Shahar Soel
@bd82

Hello @ivan-abdulin

My first impression when looking into your code is that I would probably try to transform the CST to some higher level data structure (e.g AST) before running my interpreter. Consider that complex productive compilers may have multiple data structure to represent the code.

The second impression is that you should not be re-parsing the input text to implement eval.
If you have an interpreter for an AST, and you have an AST of the whole "file" you should be able to execute different parts of this AST (in different contexts). Note that when you implement your AST data structure you also implement your own traversal mechanisms on it.

In other words, the CST / CST visitor is a low level data structure that can be used for syntactic level work (e.g implementing a formatter).
But in more complex flows you would often want to transform it to a higher level data structure that possesses the relevant capabilities for your scenario.

4 replies
kokokenada
@kokokenada
Hi - I'm using chevrotain as part of a healthcare focused low code platform. Are there any chevrotain experts that are interested in some freelance work?
2 replies
Simon Buteau
@SimBt_gitlab
Hi - I'm looking to create a Lexer / Parser using a list of fields and Value from a Back-end. Is there any body who know if this is possible to do that?
1 reply
biosbob
@biosbob

i'm building a parser that will handle obj.prop style code-completion in an editor, where i want to present a set of alternative property names when a user enters obj. alone.... obviously, the latter input is syntactically wrong; but i still need to produce as much of my AST as possible, so i can subject everything else to semantic analysis.... for example, i need to know the type of obj in this case....

from what i've learned about chevrotain, i could have the parser generate a CST (with might contain recovered nodes) that i could then transform into my own legacy AST structure.... i started, however, with an embedded actions parser -- since it was quite straightforward to build the AST directly.... i'm also developing in typescript, which gave me a lot of robustness in terms of the types of AST nodes returned by each rule....

but unlike a CST parser (which appears to insert an identifier token when just presented with obj.), i can't seem to achieve the same effect with my embedded action parser.... i tried adding a recoveryValueFunc on the rule active at the time the error was trigger, but it never executed; i am, however, able to trigger a recoveryValueFunc on higher-level rules (eg., my start rule)....

if there is a way to handle this use-case with an embedded action parser, as that would be my preference.... being that a CST is very loosely-typed (from a typescript perspective), constructing my own AST nodes can be a little error-prone....

suggestions???

3 replies
Sawcce
@sawcce
when I follow the doc's tutorial on the parser why does it say "parser.selectStatement is not a function" on testing? The selectStatement should exist in the class right?
3 replies
nomuna
@nomuna
Hello everyone.
I have a parser that extends the cst parser with embedded grammar rules. I am trying to extract the grammar as json pbject but it is giving me an empty object what am I doing wrong?
nomuna
@nomuna
Sorry just saw the discussions link above. Have a nice day.