Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Label definitions that look like registers are an error.

Stuff that looks like numbers probably should be too... But meh.
  • Loading branch information...
commit aaceb532d2a88c41d9ea5591c159f984469815bd 1 parent 13a062c
amtal authored
Showing with 34 additions and 9 deletions.
  1. +18 −4 DCPU16/Assembly/Parser.hs
  2. +16 −5 README.md
22 DCPU16/Assembly/Parser.hs
View
@@ -21,7 +21,7 @@ import Data.Vector (Vector)
import Data.Word (Word16)
import qualified Data.Vector as V
import Data.Char (toUpper)
-import Control.Monad (void,unless)
+import Control.Monad (void,unless,when)
import Text.Printf
-- | Default parsing options.
@@ -52,8 +52,10 @@ data Opt = Opt
-- Detailed errors with line and column numbers (as well as expected values)
-- will be printed to console if parsing fails.
parseFile opt f = do
- (Just syms) <- parseFromFile symbolDefs f
- parseFromFile (asm (Opt syms opt)) f
+ ss <- parseFromFile symbolDefs f
+ case ss of
+ (Just syms) -> parseFromFile (asm (Opt syms opt)) f
+ Nothing -> return Nothing
symbolDefs :: Parser String (Vector ByteString)
@@ -88,7 +90,19 @@ end = eof <?> "comment, end of file, or valid instruction"
-- later.
dat o = Data <$ symbol "dat" <*> word o
-label = Label <$ char ':' <*> labelName <* spaces
+label = do
+ char ':'
+ l<-labelName
+ when (isRegName (B.unpack l)) $
+ err [] $ "label definition "++show l++" clashes with register name"
+ spaces
+ return $ Label l
+ where
+ isRegName :: String -> Bool
+ isRegName s = map toUpper s `elem` regs
+ regs = ["A","B","C","X","Y","Z","I","J"
+ ,"POP","PEEK","PUSH","PC","O"
+ ]
labelName = B.pack `fmap` some labelChars
21 README.md
View
@@ -119,21 +119,32 @@ Parser Error Messages
No really, they're quite nice. They're even coloured!*
+Here, valid label characters are explained:
+
+```
+tasm/opt.asm:2:3: error: label definition "a" clashes with register name, expected: ".",
+ "_", letter or digit
+:a
+ ^
+```
+
+Again, pretty specific about what's expected:
+
```
-*DCPU16.Assembler.Parser> parseFile "test.masm"
test.masm:2:19: error: expected: "0", "[",
"a", "b", "c", "i", "j", "o", "pc", "peek",
"pop", "push", "sp", "x", "y", "z", digit,
letter or digit
set #a, 0x30 ; 7c01 0030
^
-Nothing
-*DCPU16.Assembler.Parser> parseFile "lower.masm"
+```
+
+No stupid mistakes allowed:
+
+```
lower.masm:14:29: error: label "lop" not defined
set pc, lop ; 7dc1 000d [*]
^
-Nothing
-*DCPU16.Assembler.Parser>
```
* No colour visible in copy-pastes.
Please sign in to comment.
Something went wrong with that request. Please try again.