Repository navigation
Parse errors - #45
Parse errors#45hshkk wants to merge 26 commits into
Conversation
| withBuild :: [FeatureName] -> (FilePath -> IO ()) -> IO () | ||
| withBuild args tests = withSystemTempDirectory "LayeredHaskell-test" $ \dir -> do | ||
| let featureDir = dir </> "LH" </> "Feature" | ||
| -- Create ../LH/Feature/, which will then receive the superimposed files. | ||
| createDirectoryIfMissing True featureDir | ||
| superimpose args (addTrailingPathSeparator featureDir) | ||
| files <- listDirectory featureDir | ||
| superimpose args dir | ||
| files <- listFilesRecursive dir | ||
| -- For each Happy file, we execute Happy to produce a set of Haskell modules. | ||
| forM_ [file | file <- files, takeExtension file == ".y"] $ \y -> | ||
| run "happy" [featureDir </> y, "-g", "-a", "-c", "-o", featureDir </> replaceExtension y "hs"] | ||
| run "happy" [dir </> y, "-g", "-a", "-c", "-o", dir </> replaceExtension y "hs"] | ||
| -- Then, we can run cabal on the driver file. | ||
| _ <- run "cabal" | ||
| [ "exec", "--", "ghc", "-O0", "-package", "LayeredHaskell", "-i" ++ dir, "-outputdir", dir </> "build" | ||
| , "-o", dir </> "driver" <.> exeExtension, "test/LH/Test/Text/Parser/Driver.hs" ] | ||
| tests dir |
There was a problem hiding this comment.
The tests have been sped up. Previously, cabal test took around 40 seconds to complete, but now it takes around 30 seconds. I'm actually not entirely sure why this is the case, but it seems that slightly adjusting the output of superimposition did something beneficial in this regard.
There was a problem hiding this comment.
It does look like the tests went back to the speed they were previously at. I'm not really sure what happened here, but this can probably be ignored.
…ure.Parser.Error`)
In the future, I plan to generalize the parser tests into a general interface for all kinds of tests across feature combinations.
|
The most interesting finding (for me) is that layer-related errors are quite difficult to handle within the feature files themselves. I think it is much more idiomatic to identify and generate an uppermost, or maximal layer, then identify discrepancies. Since any layer is a subset of the uppermost layer, we can accomplish the following check (say, with respect to the parser). Call
This is what is written in the files so far. (See |
The rules for `let` expressions were adjusted for better error reporting. Likewise for `case` expressions and `data` declarations.
| -- | Determines the source of a 'LayerError' (and thus a 'ParseError'), producing a label and a possible fix. | ||
| -- | ||
| -- Some tokens alone are sufficient to identify the issue, like keywords or operators. | ||
| -- Others, like variables, aren't enough to figure out what went wrong, so 'layerReason' will search the AST produced by the | ||
| -- uppermost parser to identify the discrepancy. | ||
| layerReason :: LHsTextError -> Seq (L Upp.LHsDecl) -> (Maybe Text, Maybe Text) |
There was a problem hiding this comment.
This is the primary place where layer-specific syntax errors are handled. We can make some checks without traversing the AST generated by the uppermost parser, but in some cases (like variables), we have to traverse and identify whether there was an issue at a pattern, at a type parameter, etc.
| %monad { LHsParser } | ||
| %lexer { lexer } { LHsLexeme _ LHsTkEOF } | ||
| %error { parseError } | ||
| %error.expected |
There was a problem hiding this comment.
For generic syntax errors, we can summarize and report a series of expected tokens. This is achieved by adding the %error.expected directive to each of the parser files, in which case Happy passes a list [String] to the parseError function, and we can apply a function (which I've called toPhrases) that summarizes it for students to understand.
|
I think I'll try to write some tests before marking this ready for review. I do recommend pulling from the |
…erent places in the file
There is a slight weakness in this approach in that prefix operators cannot be assigned an unambiguous source. The issue is that the erroneous position pointed to is the binary operator itself (via the `Bin` nonterminal), and not the beginning of `'(' Bin ')'`.






This PR intends to create a preliminary implementation for parse errors.