Commit Graph

1278 Commits

Author SHA1 Message Date
Adam Sampson
87574796fb Make the lexer only recognise known preprocessor directives.
This is another one for the list of occam oddities: there are situations where
both a hex literal and a preprocessor directive are legal, so the two can't be
ambiguous -- no #FACE or #ADA in the future!
2007-08-21 21:12:44 +00:00
Adam Sampson
1bac142a53 Rework the parser to use the new lexer.
The occam parser is now a GenParser Token OccState, rather than a GenParser
Char OccState, and a lot of now-redundant code has been removed. The parser is
also somewhat faster, which wasn't intended but is nice anyway.

I've also modified the Rain parser to not rely on the old preprocessing code;
it wasn't appropriate for Rain's syntax anyway, so I assume Neil will be
replacing it eventually.
2007-08-21 20:44:15 +00:00
Adam Sampson
1f490e9f7f Lex multiline strings as multiple tokens.
This is because the structure pass needs to be able to tell where new lines
start, and if the line number changes in the middle of a token then it'll get
confused.
2007-08-21 20:01:46 +00:00
Adam Sampson
3fb0cf088f Implement continuation line rules. 2007-08-21 17:46:30 +00:00
Adam Sampson
065df28bbc Make unknown preprocessor directives a warning rather than an error.
This is what the "old" preprocessor does; it's more useful at the moment.
2007-08-21 17:27:16 +00:00
Adam Sampson
1fc6dcd0e9 Add Outdents when reaching the end of a file.
This doesn't make a difference for regular programs and headers -- but it does
for .inc files containing processes.
2007-08-21 17:25:10 +00:00
Adam Sampson
3d66a7634b Fix lexing of preprocessor directives.
This looks more complicated than it is because it meant adding state to the
lexer -- it's now quite a neat little three-state machine.

This also renames DecimalLiteral to IntLiteral to match the rest of the code.
2007-08-21 17:22:25 +00:00
Adam Sampson
d28e945574 Don't allow *s in strings that aren't escapes. 2007-08-21 17:20:10 +00:00
Neil Brown
8a3edfd2e2 Actually added Pattern.hs
This file should have been in the earlier patch at 22:01 on Mon Aug 20, but it got missed out by accident.
2007-08-21 00:44:55 +00:00
Neil Brown
66eddfa672 Rain: added some tests for parsing data types 2007-08-20 22:39:58 +00:00
Neil Brown
6afbb5ecf4 Rain: changed the top-level parser from the dummy value to the proper value (topLevelDecl) 2007-08-20 22:37:47 +00:00
Neil Brown
43c3ae4aa7 Rain: added the parsing of top-level declarations (and tuple definitions) 2007-08-20 22:08:24 +00:00
Neil Brown
eb4a629d57 Rain: Fixed the meta tags for each part of a block 2007-08-20 22:07:58 +00:00
Neil Brown
923eefe317 Rain: refactored the parsing of blocks 2007-08-20 22:06:56 +00:00
Neil Brown
eee8ce2492 Rain: Corrected the parse tests for the top level declaration 2007-08-20 21:54:46 +00:00
Neil Brown
1213661b36 Added some helper functions for creating simple Patterns to TestUtil 2007-08-20 21:53:24 +00:00
Neil Brown
3e0b781b88 Added better pretty-printing for list Patterns, with a special case for strings that prints them out nicely 2007-08-20 21:35:19 +00:00
Neil Brown
391890faa7 Moved TreeUtil.Pattern to its own module (Pattern), which allowed me to show the pshowPattern function to be part of the PrettyShow.pshow function 2007-08-20 21:01:06 +00:00
Adam Sampson
223a14d767 Add a preprocessor that works with the new lexer.
The parser now gets a stream of tokens, rather than needing to worry about
loading files itself.

This also reworks the lexer's idea of what constitutes a Token -- it's now a
pair (Meta, TokenType), so it's always easy to pull out/rewrite the metadata --
and adds proper support for lexing preprocessor directives, rather than just
treating them as reserved words.
2007-08-20 23:46:57 +00:00
Adam Sampson
a640dabc04 Don't Haddock LexOccam.hs.
I think Haddock doesn't like the GHC preprocessor directives that Alex
generates, so just ignore the lexer source for now.
2007-08-20 23:44:47 +00:00
Adam Sampson
f95bcf6411 Tweak some Haddock syntax. 2007-08-20 23:44:10 +00:00
Neil Brown
30816b60ac On Adam's suggestion, renamed the occam 2.1 frontend to simply occam 2007-08-20 22:37:21 +00:00
Neil Brown
bd0af91813 Fixed a slightly confusing inner predicate name for findMeta 2007-08-20 22:06:26 +00:00
Neil Brown
34c61702de Rain: added a new test for testing the parsing of top-level declarations 2007-08-20 18:44:11 +00:00
Neil Brown
810dcbfbd9 Added Rain as a possible frontend for Tock, by adding a new command-line option. 2007-08-20 17:39:33 +00:00
Neil Brown
4d16320d26 Added a PassTest file intended for tests of the occam passes, and put in it a test for the functions-to-procs pass 2007-08-20 17:23:20 +00:00
Neil Brown
6d0cf6464a Added a fix for the Eq instance of toConstr being too weak, by adding a new helper function to TreeUtil 2007-08-19 09:20:35 +00:00
Neil Brown
e38d29f43d Moved a bunch of functions from RainPassTest to TestUtil, so that they can be re-used 2007-08-18 23:00:41 +00:00
Adam Sampson
c4a04675ad Make RainParse contain its own definition of RainParser.
It was previously defined in terms of OccParser, which I'm about to change.
2007-08-20 00:52:16 +00:00
Adam Sampson
a9f1e52103 Structure analyser for the new lexer. 2007-08-20 00:48:55 +00:00
Adam Sampson
543a7b6872 Add a first shot at a lexer for occam.
The aim is to separate lexing from the existing parser, which should make
indentation processing a good deal less painful.

The lexer is compiled using Alex, which generates Haskell code from the .x
file; it's not particularly elegant but the input syntax is nice and it does
seem to work well.
2007-08-19 20:21:40 +00:00
Adam Sampson
65d5fc450d Remove readSource in favour of readFile.
It turns out there's a Prelude function that does what readSource does already
-- so just use that. (I was in the process of moving readSource into Utils when
I found it, since I want to use it in other places.)
2007-08-19 18:21:23 +00:00
Adam Sampson
c8d5a4ff40 Add licensing information.
The compiler itself is under the GPLv2+; the support code that gets built into
user programs is under the LGPLv2+. This matches the existing practice for the
KRoC project.

(As with Occade, I've used the new GPLv3-style license header in the source
files, though, since that avoids having to update the FSF's postal address.)
2007-08-18 20:42:11 +00:00
Neil Brown
f9a811e775 Rain: implemented the pass for recording inferred types, and added one more test for it 2007-08-18 18:10:51 +00:00
Neil Brown
3473c512a3 Rain: Added a helper function to the pass tests for tests that are expected to fail 2007-08-18 18:10:09 +00:00
Neil Brown
3f84532695 Renamed the old pass that recorded declared types, added a new skeleton pass for recording inferred types, and wrote some tests for this new pass 2007-08-18 17:33:40 +00:00
Neil Brown
b9c12a0b22 Rain: refactored the tests, pulling out some common functionality 2007-08-18 17:32:41 +00:00
Neil Brown
88380cdc6f Rain: implemented the pass to record the type of names in CompState 2007-08-18 17:05:08 +00:00
Neil Brown
bc24ba16b1 Rain: added a skeleton pass for recording type names in CompState, and wrote a test for it 2007-08-18 16:56:25 +00:00
Neil Brown
d7dc28ce47 Rain: generalised part of the test framework and added a new helper function for testing passes 2007-08-18 16:55:20 +00:00
Neil Brown
dcfd23db4f Rain: expanding the unique-name pass to also resolve inner variables, and changed the tests accordingly 2007-08-18 16:03:19 +00:00
Neil Brown
34eac44d45 Rain: implemented the pass to give declarations unique names 2007-08-18 15:48:22 +00:00
Neil Brown
9d9b6dd73f Rain: added a skeleton pass for giving variables unique names, and wrote tests for it 2007-08-18 15:39:39 +00:00
Neil Brown
f732996c13 Rain: added various helper functions to RainPassTest 2007-08-18 15:38:43 +00:00
Neil Brown
f700392676 Added a useful transformEither function to Utils 2007-08-18 15:37:29 +00:00
Neil Brown
68a3b3f4bc Tidied up some test functions and added assertNotEqual function 2007-08-18 14:48:23 +00:00
Neil Brown
8ab4299553 Refactored TreeUtil to provide Show and Eq instances for AnyDataItem, which allowed other functions to be simplified/removed 2007-08-18 14:46:57 +00:00
Neil Brown
fe5141d310 Changed the Either order in TreeUtil of getMatchedItems to match Haskell convention 2007-08-18 11:09:37 +00:00
Neil Brown
7b81208794 Rain: refactored the pass tests to remove duplicate code 2007-08-18 10:59:00 +00:00
Neil Brown
3cb1a942f4 Rain: tidied up the types of the each tests slightly 2007-08-18 10:36:04 +00:00