Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiMode Lexer defaultMode should not be implicitly defined. #202

Closed
bd82 opened this issue Jun 5, 2016 · 1 comment
Closed

MultiMode Lexer defaultMode should not be implicitly defined. #202

bd82 opened this issue Jun 5, 2016 · 1 comment
Labels

Comments

@bd82
Copy link
Member

bd82 commented Jun 5, 2016

Currently a MultiMode lexer uses the "first" mode in the definition as the default mode.
So in this example the defaultMode will be "numbers_mode"

// old deprecated format
var multiModeLexerDefinition = {
    // the default (initial) mode is "numbers_mode" it is implicitly defined as the first key in the definition object.
    "numbers_mode": [One, Two, Three, ExitNumbers, EnterLetters, Whitespace],
    "Letter_mode":  [Alpha, Beta, Gamma, ExitLetter, EnterSigns, Whitespace],
    "signs_mode":   [Hash, Caret, Amp, ExitSigns, EnterNumbers, Whitespace]
};

The problem is that the default mode relies on the order of iteration on javascript objects
which is left undefined in the ECMAScript specifications and is thus implementation dependent.

A more robust way would be to define the defaultMode explicitly:

// new format
var multiModeLexerDefinition = {

    modes : {
        "numbers_mode": [One, Two, Three, ExitNumbers, EnterLetters, Whitespace],
        "Letter_mode":  [Alpha, Beta, Gamma, ExitLetter, EnterSigns, Whitespace],
        "signs_mode":   [Hash, Caret, Amp, ExitSigns, EnterNumbers, Whitespace]
    },

    // the default mode is explicitly defined.
    defaultMode : "numbers_mode"
};
@bd82
Copy link
Member Author

bd82 commented Jun 6, 2016

Not that this is a breaking change which requires slight modification to existing MultiMode Lexers.

@bd82 bd82 changed the title MultiMode Lexer defaultMode should not be implicitly defined MultiMode Lexer defaultMode should not be implicitly defined. Jun 6, 2016
bd82 added a commit that referenced this issue Jun 6, 2016
…iteration

  on javascript objects.

* XML Grammar Example.

Fixes #201
Fixes #202
@bd82 bd82 closed this as completed in 31be93b Jun 6, 2016
VILOZNY pushed a commit to VILOZNY/chevrotain that referenced this issue Sep 18, 2016
…iteration

  on javascript objects.

* XML Grammar Example.

Fixes Chevrotain#201
Fixes Chevrotain#202
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant