Skip to content
This repository has been archived by the owner on Mar 21, 2019. It is now read-only.

Reserved identifiers #17

Open
CMCDragonkai opened this issue Jun 28, 2018 · 0 comments
Open

Reserved identifiers #17

CMCDragonkai opened this issue Jun 28, 2018 · 0 comments
Assignees
Labels

Comments

@CMCDragonkai
Copy link
Member

CMCDragonkai commented Jun 28, 2018

Parsing reserved identifiers follows a standard pattern.

Basically to parse an identifier, you always check if the identifier is a reserved identifier, and if so you disallow.

A reserved identifier is always a keyword then a conditional. That conditional can be a whitelist or blacklist. It can either say, that these are the things allowed after the keyword, or it can say these things are not allowed after the keyword.

The point is to disambiguate between let from letx.

Hnix uses:

reservedEnd :: Char -> Bool
reservedEnd x = isSpace x ||
    x == '{' || x == '(' || x == '[' ||
    x == '}' || x == ')' || x == ']' ||
    x == ';' || x == ':' || x == '.' ||
    x == '"' || x == '\'' || x == ','

reserved :: Text -> Parser ()
reserved n = lexeme $ try $
    string n *> lookAhead (void (satisfy reservedEnd) <|> eof)

I decided to simplify to just:

reserved :: Text -> Parser ()
reserved i = (lexeme . MP.try) $
  MPC.string i *> MP.lookAhead reservedAfter
  where
    reservedAfter = MPC.space1 <|> lineComment <|> blockComment <|> MP.eof

This ensures that a reserved identifier is a keyword with some sort of space \t \v ... etc the comments and EOF.

Hopefully the above works.

@CMCDragonkai CMCDragonkai added the enhancement New feature or request label Aug 14, 2018
@CMCDragonkai CMCDragonkai self-assigned this Aug 14, 2018
@CMCDragonkai CMCDragonkai added development Coding and removed enhancement New feature or request labels Aug 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

1 participant