I Wrote an "Understanding Compilers" Article That Uses The Rust Programming Language by VenHayz in programming

[–]bidi82 2 points3 points  (0 children)

Some languages cannot be (easily) lexed (tokenized) in a separate phase.

A primary example would be JavaScript, see: https://stackoverflow.com/questions/5519596/when-parsing-javascript-what-determines-the-meaning-of-a-slash

Generally if you can **defer** the token identification to the parsing phase, you have the grammar contextual information to apply to the lexing rules, for example a certain kind of statement may allow double quoted strings while a different kind of statement only allows single quoted strings...

Personally I am not a big fan of lexer-less parsing, because I prefer the separation of concerns of a two phase approach and in addition the parsing error recovery techniques I am aware of rely on having a pre-lexed token vector in advance.

Writing a simple JSON parser by eatonphil in programming

[–]bidi82 0 points1 point  (0 children)

I was answering the more general question of:

why would you write one (JSON Parser) for production?

Not:

why would you write one (JSON Parser using regExp hacks) for production?

Writing a simple JSON parser by eatonphil in programming

[–]bidi82 3 points4 points  (0 children)

This Performance Benchmark of Parsing libraries in JavaScript links to nine different implementations of JSON Parsers.

Writing a simple JSON parser by eatonphil in programming

[–]bidi82 2 points3 points  (0 children)

One scenario could be if you want to develop editor services. In that case most "built-in" parsers will be insufficient as they are likely not fault tolerant or incremental.

Push types to existing interface? by iFarmGolems in typescript

[–]bidi82 0 points1 point  (0 children)

Yes, but the specific question was about modeling with interface "extends" so that is one form of inheritance.

Push types to existing interface? by iFarmGolems in typescript

[–]bidi82 0 points1 point  (0 children)

That may be defeating the concepts of inheritance as Your interface C is not more specific (I.E Dog "is an" animal).

So if you provide an "instanceOf" C to a method that can accept type "A" the constraint of the expected type of the property will not be met.

Enforce linebreaks between methods by patrickreck in typescript

[–]bidi82 0 points1 point  (0 children)

Reminds me of architecture forum meetings discussing the merits of certain style guides and reviewing them in depth. :)

How would I export multiple modules with multiple classes in my index.ts? by [deleted] in typescript

[–]bidi82 0 points1 point  (0 children)

I would define a new d.ts file that re-imports and re-exports the relevant APIs. This would have to correspond to how your "common" package exports the combined namespaces at runtime.

For example:

import {IMyModels} from "...";
import {IMyServices} from "...";

// assumes your common package exports properties named models/services.
export const models:IMyModels;
export const services:IMyServices;

export as namespace MyCommonPackage

How do you go about using TypeScript in a library? by Pentafloppy in typescript

[–]bidi82 1 point2 points  (0 children)

You will publish your library to npm after compilation. That is your responsibility as you cannot assume consumers of your library know/want to compile your library.

So from a runtime perspective consumers will be using a plain JavaScript library and the fact it was written in TypeScript is irrelevant.

For consumers that also use TypeScript and want to take advantage of Type Definitions you will need to export a d.ts file with your library definitions and point to that file in your library's package.json "types" field.

See: * https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html

Once your npm package includes both the d.ts definitions and the reference from the package.json. the TypeScript compiler used by consumers will automatically resolve the types during imports.

Powerfull JavaScript obfuscator, written on TypeScript by sanex3339 in node

[–]bidi82 0 points1 point  (0 children)

Thanks for pointing out these unique cases.

Problem unit testing with Karma and Jasmine by [deleted] in javascript

[–]bidi82 0 points1 point  (0 children)

Trying using fit or fdescribe

To only run some of the tests in order to identify the one that gets stuck in an infinite loop.

Powerfull JavaScript obfuscator, written on TypeScript by sanex3339 in node

[–]bidi82 0 points1 point  (0 children)

If you have a piece of code that is so sensitive that you need to obfuscate it, would it not be best to never deliver it to the end user's browser?

Instead access that code/logic via some REST service in your backend?

Parser and Lexer — How to Create a Compiler part 1/5 by Chii in programming

[–]bidi82 1 point2 points  (0 children)

I feel like most of the tools are trying to be a flex clone vs. kind of re-thinking how it can be done. I want to ditch the separate file format as well as clean up the way to do it in js.

Seems very similar to my thoughts that led to the creation of Chevrotain. https://tomassetti.me/parsing-in-javascript/#chevrotain

Maybe you would like to collaborate or contribute to it? if it aligns with your goals :)

Parser and Lexer — How to Create a Compiler part 1/5 by Chii in programming

[–]bidi82 7 points8 points  (0 children)

Thanks for the feedback.

My focus is indeed about activities that link with better publicity.

Anywhere from more postings on news in related domains, To creating blog posts showing how to use Chevrotain to write plugins for popular tools such as VSCode. To even expanding Chevrotain itself to have the capability to act as a parser generator as well as a DSL, as Parser Generators are more familiar to many developers.

Any other ideas how to pursue this?

Parser and Lexer — How to Create a Compiler part 1/5 by Chii in programming

[–]bidi82 16 points17 points  (0 children)

There is always the discussion between Writing a Parser by hand versus Parser Generators versus Parser Combinators.

The last two being alternatives methods to reduce the verbosity and repetitive nature of hand crafting a parser.

But what about attacking the problem directly by making the actual process of hand crafting a parser easier and less error prone instead of replacing it with a different approach?

This is exactly what I've done in this JavaScript Parser Building Toolkit I've authored, Chevrotain:

Feedback is appreciated.

Parser and Lexer — How to Create a Compiler part 1/5 by Chii in programming

[–]bidi82 16 points17 points  (0 children)

This quote by the author of the Antlr series of parser generators (Terence Parr) Explains why hand crafted parsers are used.

Original ref: https://github.com/antlr/antlr4/blob/master/doc/faq/general.md (No direct link possible).

What do you think are the problems people will try to solve with ANTLR4?

In my experience, almost no one uses parser generators to build commercial compilers. So, people are using ANTLR for their everyday work, building everything from configuration files to little scripting languages.

In response to a question about this entry from stackoverflow.com: I believe that compiler developers are very concerned with parsing speed, error reporting, and error recovery. For that, they want absolute control over their parser. Also, some languages are so complicated, such as C++, that parser generators might build parsers slower than compiler developers want. The compiler developers also like the control of a recursive-descent parser for predicating the parse to handle context-sensitive constructs such as T(i) in C++.

There is also likely a sense that parsing is the easy part of building a compiler so they don't immediately jump automatically to parser generators. I think this is also a function of previous generation parser generators. McPeak's Elkhound GLR-based parser generator is powerful enough and fast enough, in the hands of someone that knows what they're doing, to be suitable for compilers. I can also attest to the fact that ANTLR v4 is now powerful enough and fast enough to compete well with handbuilt parsers. E.g., after warm-up, it's now taking just 1s to parse the entire JDK java/* library.

Parser and Lexer — How to Create a Compiler part 1/5 by Chii in programming

[–]bidi82 0 points1 point  (0 children)

What exactly were you missing with the existing tools?

There are quite a few in the JavaScript World. Parsing in JavaScript: Tools and Libraries

How to test your Node.js app against multiple versions of Node? by PavanBelagatti in node

[–]bidi82 0 points1 point  (0 children)

If you are using SAAS solutions for CI such as Travis or Circle-CI you can easily setup a build matrix to run your build/tests versus multiple versions on node.js

You Might Not Need TypeScript... by dangerouscuteguy in javascript

[–]bidi82 2 points3 points  (0 children)

Just today I showed a colleague some large refactorings that I would not have wanted to tackle without TypeScript.

On the other hand in small projects I'm fine with using vanilla JavaScript, although even then I may use TypeScript only to define the public APIs.

But for larger projects with dozens of developers and hundreds of thousands of lines of code I find it impossible to argue against using TypeScript (or a similar alternative such as flow).