Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Lots of cleanup. Lambdas with no args work, not sure why adding an ar…

…g into the mix makes it explode. Once I get lambdas and definitions working, I believe the parsing will be finished.
  • Loading branch information...
commit 6210105e78e0cab663725c5a93fbf6770280fbcc 1 parent 2ce6b7a
Marie Markwell authored

Showing 1 changed file with 31 additions and 22 deletions. Show diff stats Hide diff stats

  1. +31 22 Parser.hs
53 Parser.hs
@@ -6,7 +6,7 @@ import Control.Applicative hiding (many, optional, (<|>))
6 6 program = endBy1 statement eol
7 7 statement = commentLiteral
8 8 -- <|> definitionLiteral
9   --- <|> lambdaLiteral
  9 + <|> lambdaLiteral
10 10 <|> stringLiteral
11 11 <|> charLiteral
12 12 <|> number
@@ -17,50 +17,54 @@ commentLiteral = try docCommentLiteral
17 17
18 18 docCommentLiteral =
19 19 do string ";;"
20   - content <- many commentLiteralChar
  20 + content <- many1 commentLiteralChar
21 21 return ("comment.doc", content)
22 22
23 23 plainCommentLiteral =
24 24 do char ';'
25   - content <- many commentLiteralChar
  25 + content <- many1 commentLiteralChar
26 26 return ("comment.plain", content)
27 27
28   -{--
29 28 definitionLiteral =
30 29 do name <- identifierLiteral
31 30 char ':'
32 31 _ <- whitespace
33 32 value <- statement
34   - return ("define", ...)
35   ---}
  33 + return ("define", "...")
  34 +
  35 +
  36 +identifierLiteral =
  37 + do start <- identifierStartLiteralChar
  38 + rest <- many1 identifierLiteralChar
  39 + string ([start] ++ rest)
  40 +
  41 +identifierStartLiteralChar = oneOf "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-=./<>?~!@#$%^&*()_+|"
  42 +identifierLiteralChar = oneOf "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=./<>?~!@#$%^&*()_+|"
36 43
37   -{--
38 44 lambdaLiteral =
39 45 do char '['
40   - args <- argListLiteral
  46 +-- args <- argListLiteral
41 47 _ <- whitespace
42   - string '->'
  48 + string "->"
43 49 _ <- whitespace
44   - contents <- many statement
  50 + contents <- many1 statement
45 51 _ <- whitespace
46 52 char ']'
47   - return ("lambda", ...)
48   ---}
  53 + return ("lambda", "...")
49 54
50   -{--
51   -argListLiteral = many argLiteral
  55 +argListLiteral = many identifierLiteral --argLiteral
52 56
53 57 argLiteral =
54   - do value <- many argLiteralChars
  58 + do value <- identifierLiteral
55 59 _ <- whitespace
56 60 return value
57 61
58   -argLiteralChars = -- any character except whitespace or [ ] ( ) { } " ' \ ; : `
59   ---}
  62 +--argLiteralChar = noneOf " \t [](){}\"'\\;:`" -- any character except whitespace or [ ] ( ) { } " ' \ ; : `
  63 +--argLiteralChar = oneOf "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=./<>?~!@#$%^&*()_+|"
60 64
61 65 stringLiteral =
62 66 do char '"'
63   - content <- many stringLiteralChar
  67 + content <- many1 stringLiteralChar
64 68 char '"'
65 69 return ("string", content)
66 70
@@ -113,18 +117,23 @@ decDigits = many1 digit
113 117 octDigits = many1 octDigit
114 118 hexDigits = many1 hexDigit
115 119 binDigits = many1 binDigit
116   -binDigit = char '0' <|> char '1'
  120 +binDigit = char '0' <|> char '1'
117 121
118   --- Handle escaped "s and 's
  122 +-- TODO: Handle escaped "s and 's
119 123 stringLiteralChar = noneOf "\""
120 124 charLiteralChar = noneOf "'"
121 125
122 126 commentLiteralChar = noneOf "\r\n"
123 127
  128 +-- This probably should be whitespaceLiteral, but this is nicer imo
  129 +whitespace = many whitespaceCharLiteral
  130 +whitespaceCharLiteral = try space
  131 + <|> try tab
  132 +
124 133 eol = try (string "\n\r")
125 134 <|> try (string "\r\n")
126   - <|> string "\n"
127   - <|> string "\r"
  135 + <|> try (string "\n")
  136 + <|> string "\r"
128 137 <?> "end of line"
129 138
130 139

0 comments on commit 6210105

Please sign in to comment.
Something went wrong with that request. Please try again.