From 3f6c71b3a4b975d894bbb7833729350326e98de3 Mon Sep 17 00:00:00 2001 From: joshvera Date: Mon, 17 Jul 2017 12:52:50 -0400 Subject: [PATCH] Add json grammar module --- languages/json/json.cabal | 1 - semantic-diff.cabal | 1 + src/Language.hs | 2 ++ src/Language/JSON/Grammar.hs | 10 ++++++++++ src/Parser.hs | 2 ++ 5 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/Language/JSON/Grammar.hs diff --git a/languages/json/json.cabal b/languages/json/json.cabal index 7c21941e2..0b8e025c3 100644 --- a/languages/json/json.cabal +++ b/languages/json/json.cabal @@ -19,7 +19,6 @@ library default-language: Haskell2010 default-extensions: FlexibleInstances, OverloadedStrings, NoImplicitPrelude, RecordWildCards c-sources: vendor/tree-sitter-json/src/parser.c - , vendor/tree-sitter-json/src/scanner.c cc-options: -std=c99 -Os diff --git a/semantic-diff.cabal b/semantic-diff.cabal index 3ef33fd5f..ae8c8abad 100644 --- a/semantic-diff.cabal +++ b/semantic-diff.cabal @@ -51,6 +51,7 @@ library , Language.Markdown.Syntax , Language.Go , Language.Go.Syntax + , Language.JSON.Grammar , Language.Ruby , Language.Ruby.Grammar , Language.Ruby.Syntax diff --git a/src/Language.hs b/src/Language.hs index f86897322..a70fb9480 100644 --- a/src/Language.hs +++ b/src/Language.hs @@ -14,6 +14,7 @@ data Language = C | Go | JavaScript + | JSON | Markdown | Python | Ruby @@ -25,6 +26,7 @@ languageForType :: String -> Maybe Language languageForType mediaType = case mediaType of ".h" -> Just C ".c" -> Just C + ".json" -> Just JSON ".md" -> Just Markdown ".rb" -> Just Ruby ".go" -> Just Language.Go diff --git a/src/Language/JSON/Grammar.hs b/src/Language/JSON/Grammar.hs new file mode 100644 index 000000000..2439fe472 --- /dev/null +++ b/src/Language/JSON/Grammar.hs @@ -0,0 +1,10 @@ +{-# LANGUAGE TemplateHaskell #-} +module Language.JSON.Grammar where + +import Language.Haskell.TH +import Text.Parser.TreeSitter.Language +import Text.Parser.TreeSitter.JSON + +-- | Statically-known rules corresponding to symbols in the grammar. +-- v1 - bump this to regenerate +mkSymbolDatatype (mkName "Grammar") tree_sitter_json diff --git a/src/Parser.hs b/src/Parser.hs index 22e8c1654..c469ebafa 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -33,6 +33,7 @@ import Text.Parser.TreeSitter.Go import Text.Parser.TreeSitter.Python import Text.Parser.TreeSitter.Ruby import Text.Parser.TreeSitter.TypeScript +import Text.Parser.TreeSitter.JSON import TreeSitter -- | A parser from 'Source' onto some term type. @@ -58,6 +59,7 @@ parserForLanguage Nothing = LineByLineParser parserForLanguage (Just language) = case language of C -> TreeSitterParser C tree_sitter_c Go -> TreeSitterParser Go tree_sitter_go + JSON -> TreeSitterParser JSON tree_sitter_json JavaScript -> TreeSitterParser TypeScript tree_sitter_typescript Ruby -> TreeSitterParser Ruby tree_sitter_ruby TypeScript -> TreeSitterParser TypeScript tree_sitter_typescript