parser: add invalid-word-name, use it to check for redefining quotes.

db4
John Benediktsson 2013-04-25 15:41:20 -07:00
parent 00eeb07680
commit 2b7d53b7d1
2 changed files with 11 additions and 3 deletions

View File

@ -35,6 +35,13 @@ unit-test
eval( -- ) "USE: parser.tests hello" eval( -- string ) eval( -- ) "USE: parser.tests hello" eval( -- string )
] unit-test ] unit-test
[ "IN: parser.tests : \" ( -- n ) 123 ;" eval( -- ) ]
[ error>> invalid-word-name? ] must-fail-with
[ "IN: parser.tests : \"asdf ( -- n ) 123 ;" eval( -- ) ]
[ error>> invalid-word-name? ] must-fail-with
[ "IN: parser.tests : 123 ( -- n ) 123 ;" eval( -- ) ]
[ error>> invalid-word-name? ] must-fail-with
[ ] [ ]
[ "! This is a comment, people." eval( -- ) ] [ "! This is a comment, people." eval( -- ) ]
unit-test unit-test

View File

@ -71,11 +71,12 @@ ERROR: number-expected ;
: scan-number ( -- number ) : scan-number ( -- number )
(scan-token) parse-number ; (scan-token) parse-number ;
ERROR: invalid-word-name string ;
: scan-word-name ( -- string ) : scan-word-name ( -- string )
scan-token scan-token
dup string>number [ dup "\"" = [ t ] [ dup string>number ] if
"Word names cannot be numbers" throw [ invalid-word-name ] when ;
] when ;
: scan-new ( -- word ) : scan-new ( -- word )
scan-word-name create-in ; scan-word-name create-in ;