mirror of
https://github.com/github/semantic.git
synced 2025-01-02 04:10:29 +03:00
Represent the tree-sitter parsers with a single constructor.
This commit is contained in:
parent
1a80dcf2ce
commit
d921337dae
@ -31,16 +31,10 @@ data Parser term where
|
||||
=> Parser (AST grammar) -- ^ A parser producing 'AST'.
|
||||
-> Assignment (Node grammar) (Term (Union fs) Location) -- ^ An assignment from 'AST' onto 'Term's.
|
||||
-> Parser (Term (Union (Syntax.Error [Error grammar] ': fs)) Location) -- ^ A parser of 'Term's, weakened to allow for 'Syntax.Error' cases.
|
||||
-- | A tree-sitter parser for 'C'.
|
||||
CParser :: Parser (SyntaxTerm Text DefaultFields)
|
||||
-- | A tree-sitter parser for 'Go'.
|
||||
GoParser :: Parser (SyntaxTerm Text DefaultFields)
|
||||
-- | A tree-sitter parser.
|
||||
TreeSitterParser :: Language -> Ptr TS.Language -> Parser (SyntaxTerm Text DefaultFields)
|
||||
-- | A parser for 'Markdown' using cmark.
|
||||
MarkdownParser :: Parser (SyntaxTerm Text DefaultFields)
|
||||
-- | A tree-sitter parser for 'Ruby'.
|
||||
RubyParser :: Parser (SyntaxTerm Text DefaultFields)
|
||||
-- | A tree-sitter parser for 'TypeScript'.
|
||||
TypeScriptParser :: Parser (SyntaxTerm Text DefaultFields)
|
||||
-- | A parser which will parse any input 'Source' into a top-level 'Term' whose children are leaves consisting of the 'Source's lines.
|
||||
LineByLineParser :: Parser (SyntaxTerm Text DefaultFields)
|
||||
|
||||
@ -48,11 +42,11 @@ data Parser term where
|
||||
parserForLanguage :: Maybe Language -> Parser (SyntaxTerm Text DefaultFields)
|
||||
parserForLanguage Nothing = LineByLineParser
|
||||
parserForLanguage (Just language) = case language of
|
||||
C -> CParser
|
||||
TypeScript -> TypeScriptParser
|
||||
C -> TreeSitterParser C tree_sitter_c
|
||||
Go -> TreeSitterParser Go tree_sitter_go
|
||||
Markdown -> MarkdownParser
|
||||
Ruby -> RubyParser
|
||||
Language.Go -> GoParser
|
||||
Ruby -> TreeSitterParser Ruby tree_sitter_ruby
|
||||
TypeScript -> TreeSitterParser TypeScript tree_sitter_typescript
|
||||
|
||||
runParser :: Parser term -> Source -> IO term
|
||||
runParser parser = case parser of
|
||||
@ -61,11 +55,8 @@ runParser parser = case parser of
|
||||
ast <- runParser parser source
|
||||
let Result errors term = assign assignment source ast
|
||||
pure (maybe (cofree ((totalRange source :. totalSpan source :. Nil) :< inj (Syntax.Error errors))) (hoistCofree weaken) term)
|
||||
CParser -> treeSitterParser C tree_sitter_c
|
||||
GoParser -> treeSitterParser Go tree_sitter_go
|
||||
TreeSitterParser language tslanguage -> treeSitterParser language tslanguage
|
||||
MarkdownParser -> cmarkParser
|
||||
RubyParser -> treeSitterParser Ruby tree_sitter_ruby
|
||||
TypeScriptParser -> treeSitterParser TypeScript tree_sitter_typescript
|
||||
LineByLineParser -> lineByLineParser
|
||||
|
||||
-- | A fallback parser that treats a file simply as rows of strings.
|
||||
|
Loading…
Reference in New Issue
Block a user