Lexer for the "monkey" language

#117 Merged
  1. Martin Contento

Hi, my clone contains a lexer for the monkey language. Monkey is a language similar to basic that compiles to a many different targets (target being "iOS", "Android", "HTML5" etc.).

I wrote the lexer looking at the VisualBasic.Net one, the old BlitzMax lexer and of course the language spec[2]. I am confident I covered even most of the edge cases and would be very glad to get this merged into the main repo :)

Feedback and requests for changes are welcome. I was really unsure what to put into the mimetype field, so i made "text/x-monkey" up ;)

[1] https://en.wikipedia.org/wiki/Monkey_(programming_language) [2] https://blitz-wiki.appspot.com/Language_reference

Comments (8)

  1. Tim Hatch

    Overall looks good. Yes, we often have to make up mime-types. See comments below.

    Georg, want to give you a veto option on what file this goes in -- technically it's source-to-source compiled.

  2. Martin Contento author

    Thanks for the review, i'll fix the things you flagged this weekend :)

    You are right about the overuse of the insensitivity flag, I started writing the lexer with strict checking of the case (because the language spec said so), but later I was told that the compiler actually allow almost all variants, even very strange ones like "InTERfacE". The only place the case sensitivity actually helps, is in recognising variables/functions/classes... i'll look into using the global flag instead :)

  3. Martin Contento author

    @Tim Hatch: i made the changes you mentioned and also refined some behavior (especially preprocessor variables, those were not covered before)

    I opted to keep the lexer case sensitive, although so many rules override the behavior, because it just felt "cleaner" to me to keep as much strictness as possible and so the lexer can distinguish between variables/functions/constants.

    Hoping you find this agreeable :)

  4. Martin Contento author

    I think one of the fixes is wrong, the Operator really is "|=", not "[|]=" what the regex imho now matches (because regexlint escaped the square brackets I used to make the pipe a chargroup)

    Also the operators "~" and "|" are missing from the final chargroup in that list, I total missed those :(

    Do you want to add them in your branch or should I update mine and the pull request?

    Sorry for the effort this causes, I should have spotted or tested all of those :(

    addtional lines for examples.monkey, that show errors in regex:

    ' operators
    Global a = 32
    Global b = 32 ~ 0
    b ~= 16
    b |= 16
    b &= 16
    Global c = a | b
  5. Martin Contento author

    Yep, looks good, thank you :)

    Not sure why I used a char group instead of just escaping the pipe and the star... I probably saw this in one of the other lexers.