Coder Social home page Coder Social logo

flex-js's People

Contributors

raydenfilipp avatar sormy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

flex-js's Issues

Regexps with Unicode flag

Hi! Thanks for this great library.

I'm wondering if it would be possible to add support for Unicode regular expressions? Currently, it seems that the "u" flag is discarded when the lexer compiles a rule. Unicode regular expressions are necessary to properly match non BMP characters (e.g. emojis) as well as use Unicode properties as character classes.

How to get all tokens?

I wrote a block of code

const Lexer = require('flex-js');
const lexer = new Lexer();
lexer.setIgnoreCase(true);
const s = "* @return this is a test.";
lexer.addDefinition('COMMENT', /\s*\*\s+/);
lexer.addDefinition('RETURN', /@return/);
lexer.addDefinition('DESCRIPTION', /.*/);
lexer.addRule(/{COMMENT}{RETURN}{DESCRIPTION}/, function (lexer : any) {
  console.log('Found' + lexer.text);
});
lexer.setSource(s);
lexer.lex();

image

How to get the tokens in sequence?

COMMENT:  * 
RETURN: @return
DESCRIPTION: this is a test.

Cannot set property 'lastIndex' of undefined

I wrote your basic sample in VSCode

const Lexer = require('flex-js');
var lexer = new Lexer();
// options
lexer.setIgnoreCase(true);  // does not make sense for this scanner, just for reference
// definitions
lexer.addDefinition('DIGIT', /[0-9]/);
// rules
lexer.addRule(/{DIGIT}+\.{DIGIT}+/, function (lexer) {
  console.log('Found float: ' + lexer.text);
});
lexer.addRule(/\s+/);
// code
lexer.setSource('1.2 3.4 5.6');
lexer.lex();

and I got an error

...\node_modules\flex-js\src\Lexer.js:647
  re.lastIndex = this.index;
               ^

TypeError: Cannot set property 'lastIndex' of undefined
    at Lexer.execRegExp (...\node_modules\flex-js\src\Lexer.js:647:16)

Screenshot_1

I am not sure what is the problem but I handled the error with a line of code

  if (!re) return undefined;

Screenshot_2

Can you guide me?

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.