Skip to content

Commit

Permalink
Add '<>:#' as valid characters in symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
scramjet committed Apr 16, 2020
1 parent 8e22d5f commit a188d21
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 15 additions & 7 deletions MPEdn/MPEdnParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,22 @@ - (void) addTagReader: (id<MPEdnTaggedValueReader>) reader

#pragma mark - Tokeniser

static BOOL is_sym_punct (unichar ch)
/// is this a character that may begin a symbol?
static BOOL isStartSymPunct (unichar ch)
{
// NB: '/' is added to the specified EDN set of punctuation allowed in
// symbol names. The check for its valid use will be done by the parser.
return (ch >= '!' && ch <= '_' &&
(ch == '!' || ch == '$' || ch == '%' || ch == '&' || ch == '*' ||
ch == '+' || ch == '-' || ch == '.' || ch == '=' || ch == '?' ||
ch == '_' || ch == '/' || ch == ':' || ch == '#'));
ch == '_' || ch == '/' || ch == ':' || ch == '#' || ch == '<' ||
ch == '>'));
}

/// is this a character that may be in a symbol?
static BOOL isSymPunct (unichar ch)
{
return isStartSymPunct (ch) || ch == ':' || ch == '#';
}

- (unichar) currentEndIdxChar
Expand Down Expand Up @@ -326,7 +334,7 @@ - (void) nextToken
{
[self readTagName];
}
} else if (isalpha (ch) || is_sym_punct (ch))
} else if (isalpha (ch) || isStartSymPunct (ch))
{
[self readNameToken];
} else
Expand Down Expand Up @@ -507,7 +515,7 @@ - (void) readNameToken
do
{
ch = [self advanceEndIdx];
} while (isalnum (ch) || is_sym_punct (ch));
} while (isalnum (ch) || isSymPunct (ch));

token = TOKEN_NAME;
tokenValue =
Expand All @@ -521,7 +529,7 @@ - (void) readKeywordToken
do
{
ch = [self advanceEndIdx];
} while (isalnum (ch) || is_sym_punct (ch));
} while (isalnum (ch) || isSymPunct (ch));

NSInteger length = endIdx - startIdx - 1;

Expand Down Expand Up @@ -627,8 +635,8 @@ - (void) readTagName
do
{
ch = [self advanceEndIdx];
} while (isalnum (ch) || is_sym_punct (ch));
} while (isalnum (ch) || isStartSymPunct (ch));

NSInteger tagLen = endIdx - startIdx - 1;

if (tagLen > 0)
Expand Down
4 changes: 3 additions & 1 deletion MPEdnTests/MPEdnParserTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ - (void) testSymbols

MPAssertParseOK (@"+", [MPEdnSymbol symbolWithName: @"+"], @"Symbol");
MPAssertParseOK (@"-", [MPEdnSymbol symbolWithName: @"-"], @"Symbol");
MPAssertParseOK (@"<", [MPEdnSymbol symbolWithName: @"<"], @"Symbol");
MPAssertParseOK (@"<:>", [MPEdnSymbol symbolWithName: @"<:>"], @"Symbol");
MPAssertParseOK (@"+a", [MPEdnSymbol symbolWithName: @"+a"], @"Symbol");
MPAssertParseOK (@"?", [MPEdnSymbol symbolWithName: @"?"], @"Symbol");
MPAssertParseOK (@"?a", [MPEdnSymbol symbolWithName: @"?a"], @"Symbol");
MPAssertParseOK (@"a?", [MPEdnSymbol symbolWithName: @"a?"], @"Symbol");

MPAssertParseError (@"}", @"Not a symbol");
MPAssertParseError (@"]", @"Not a symbol");
MPAssertParseError (@")", @"Not a symbol");
Expand Down

0 comments on commit a188d21

Please sign in to comment.