mirror of
https://github.com/github/semantic.git
synced 2024-12-24 23:42:31 +03:00
Special handling of ruby require, load, and friends
This commit is contained in:
parent
5f52a71b19
commit
17cf9c26af
@ -9,9 +9,11 @@ module Language.Ruby.Assignment
|
||||
import Assigning.Assignment hiding (Assignment, Error)
|
||||
import qualified Assigning.Assignment as Assignment
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Control.Monad (guard)
|
||||
import Data.Record
|
||||
import Data.Functor (void)
|
||||
import Data.List.NonEmpty (some1)
|
||||
import Data.List (elem)
|
||||
import Data.Syntax (contextualize, postContextualize, emptyTerm, parseError, handleError, infixContext, makeTerm, makeTerm', makeTerm'', makeTerm1)
|
||||
import qualified Data.Syntax as Syntax
|
||||
import qualified Data.Syntax.Comment as Comment
|
||||
@ -29,6 +31,7 @@ type Syntax = '[
|
||||
Comment.Comment
|
||||
, Declaration.Class
|
||||
, Declaration.Function
|
||||
, Declaration.Import
|
||||
, Declaration.Method
|
||||
, Declaration.Module
|
||||
, Expression.Arithmetic
|
||||
@ -296,9 +299,15 @@ pair :: Assignment
|
||||
pair = makeTerm <$> symbol Pair <*> children (Literal.KeyValue <$> expression <*> (expression <|> emptyTerm))
|
||||
|
||||
methodCall :: Assignment
|
||||
methodCall = makeTerm <$> symbol MethodCall <*> children (Expression.Call <$> pure [] <*> expression <*> args <*> (block <|> emptyTerm))
|
||||
methodCall = makeTerm' <$> symbol MethodCall <*> children (require <|> regularCall)
|
||||
where
|
||||
regularCall = inj <$> (Expression.Call <$> pure [] <*> expression <*> args <*> (block <|> emptyTerm))
|
||||
require = inj <$> (symbol Identifier *> do
|
||||
s <- source
|
||||
guard (elem s ["autoload", "load", "require", "require_relative"])
|
||||
Declaration.Import <$> args' <*> emptyTerm <*> pure [])
|
||||
args = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children (many expression) <|> pure []
|
||||
args' = makeTerm'' <$> (symbol ArgumentList <|> symbol ArgumentListWithParens) <*> children (many expression) <|> emptyTerm
|
||||
|
||||
call :: Assignment
|
||||
call = makeTerm <$> symbol Call <*> children (Expression.MemberAccess <$> expression <*> (expression <|> args))
|
||||
|
3
test/fixtures/ruby/require.A.rb
vendored
Normal file
3
test/fixtures/ruby/require.A.rb
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
require "json"
|
||||
|
||||
foo(a)
|
3
test/fixtures/ruby/require.B.rb
vendored
Normal file
3
test/fixtures/ruby/require.B.rb
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
require "nokogiri"
|
||||
|
||||
autoload(:Bar, "bar.rb")
|
14
test/fixtures/ruby/require.diffA-B.txt
vendored
Normal file
14
test/fixtures/ruby/require.diffA-B.txt
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
(Program
|
||||
(Import
|
||||
{ (TextElement)
|
||||
->(TextElement) }
|
||||
(Empty))
|
||||
{+(Import
|
||||
{+(
|
||||
{+(Symbol)+}
|
||||
{+(TextElement)+})+}
|
||||
{+(Empty)+})+}
|
||||
{-(Call
|
||||
{-(Identifier)-}
|
||||
{-(Identifier)-}
|
||||
{-(Empty)-})-})
|
14
test/fixtures/ruby/require.diffB-A.txt
vendored
Normal file
14
test/fixtures/ruby/require.diffB-A.txt
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
(Program
|
||||
(Import
|
||||
{ (TextElement)
|
||||
->(TextElement) }
|
||||
(Empty))
|
||||
{+(Call
|
||||
{+(Identifier)+}
|
||||
{+(Identifier)+}
|
||||
{+(Empty)+})+}
|
||||
{-(Import
|
||||
{-(
|
||||
{-(Symbol)-}
|
||||
{-(TextElement)-})-}
|
||||
{-(Empty)-})-})
|
8
test/fixtures/ruby/require.parseA.txt
vendored
Normal file
8
test/fixtures/ruby/require.parseA.txt
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
(Program
|
||||
(Import
|
||||
(TextElement)
|
||||
(Empty))
|
||||
(Call
|
||||
(Identifier)
|
||||
(Identifier)
|
||||
(Empty)))
|
9
test/fixtures/ruby/require.parseB.txt
vendored
Normal file
9
test/fixtures/ruby/require.parseB.txt
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
(Program
|
||||
(Import
|
||||
(TextElement)
|
||||
(Empty))
|
||||
(Import
|
||||
(
|
||||
(Symbol)
|
||||
(TextElement))
|
||||
(Empty)))
|
Loading…
Reference in New Issue
Block a user