Giter VIP home page Giter VIP logo

Comments (7)

cdiggins avatar cdiggins commented on May 28, 2024

All JavaScript is also valid TypeScript, so you can start by just renaming the file from .js to .ts. For more information perhaps see: https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html. It depends on how strict your TypeScript is, I suppose. I've never really tried. If you give it a shot, let me know how it works, and I can help you out with specific issues along the way.

from myna-parser.

rmtuckerphx avatar rmtuckerphx commented on May 28, 2024

Tried to setup a TypeScript class for my grammar, but property chaining doesn't work:
image

from myna-parser.

cdiggins avatar cdiggins commented on May 28, 2024

Not sure that property chaining is the problem there, you are missing a closing parentheses. If you fix that, what happens next?

from myna-parser.

rmtuckerphx avatar rmtuckerphx commented on May 28, 2024

error TS2339: Property 'opt' does not exist on type 'Rule'.
public number: Rule = Myna.seq(Myna.integer, this.fraction.opt.ast);

from myna-parser.

cdiggins avatar cdiggins commented on May 28, 2024

This seems like a configuration problem: the opt property does exists on Rule: https://github.com/cdiggins/myna-parser/blob/master/myna.ts#L343. I'll be honest, this kind of silliness, is why I stopped coding in TypeScript, and went back to C#.

from myna-parser.

cdiggins avatar cdiggins commented on May 28, 2024

I think the language and tooling for TypeScript is mediocre.

from myna-parser.

ninoseki avatar ninoseki commented on May 28, 2024

Following code works without error in my env. (myna-parser: 2.5.1 & typescript: 3.5.1)

import { Myna } from "myna-parser";

export class MyGrammar {
  public fraction: Myna.Rule = Myna.seq(".", Myna.digit.zeroOrMore).ast;
  public number: Myna.Rule = Myna.seq(Myna.integer, this.fraction.opt).ast;
  public plainText: Myna.Rule = Myna.notChar("\n\r").oneOrMore;
  public document: Myna.Rule = Myna.choice(this.plainText, this.number)
    .zeroOrMore;
}

const myGrammar = new MyGrammar();

const input = "11111";

const ast = Myna.parse(myGrammar.document, input);
console.log(ast);

from myna-parser.

Related Issues (20)

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.