dabeaz / sly

Sly Lex Yacc
Other
817 stars 108 forks source link

small doc err #29

Closed gitjoost closed 5 years ago

gitjoost commented 5 years ago

Small error/fix in the documentation under "Token Remapping" the following text/example:

# Base ID rule
    ID = r'[a-zA-Z_][a-zA-Z0-9_]*'

    # Special cases
    ID['if'] = IF
    ID['else'] = ELSE
    ID['while'] = WHILE

is a bit misleading as this gives no (intuitive) way to trigger a yacc rule that includes 'if', 'else' or 'while'. Assuming that the assignment is made with IF, ELSE and WHILE with keywords/tokens specified earlier. If however, the example specifies uppercase for the dict keys:

    # Special cases
    ID['IF'] = IF
    ID['ELSE'] = ELSE
    ID['WHILE'] = WHILE

a parser rule e.g.; @_('IF NUMBER "=" NUMBER') no longer fails.

dabeaz commented 5 years ago

I'm not sure I follow this. The string in [ ... ] needs to exactly match the token text. If the token being matched is lowercase such as "if", then it needs to specified as ID['if'] = IF as shown.

gitjoost commented 5 years ago

Yeah, sigh, in my infinite wishdom I had the text to parse going through upper() so “if” had to become “IF”. Blame it on too much wine... just close this one

dabeaz commented 5 years ago

Ha! No problem. It's always a good idea for me to double check such things though---so all reports related to documentation are good!