]> granicus.if.org Git - jq/commitdiff
Move everything around - delete old Haskell code, clean up build.
authorStephen Dolan <mu@netsoc.tcd.ie>
Tue, 18 Sep 2012 16:44:43 +0000 (17:44 +0100)
committerStephen Dolan <mu@netsoc.tcd.ie>
Tue, 18 Sep 2012 16:44:43 +0000 (17:44 +0100)
35 files changed:
.gitignore
JQ.hs [deleted file]
Lexer.x [deleted file]
Main.hs [deleted file]
Makefile [moved from c/Makefile with 50% similarity]
Parser.y [deleted file]
builtin.c [moved from c/builtin.c with 100% similarity]
builtin.h [moved from c/builtin.h with 100% similarity]
bytecode.c [moved from c/bytecode.c with 100% similarity]
bytecode.h [moved from c/bytecode.h with 100% similarity]
compile.c [moved from c/compile.c with 100% similarity]
compile.h [moved from c/compile.h with 100% similarity]
execute.c [moved from c/execute.c with 100% similarity]
forkable_stack.h [moved from c/forkable_stack.h with 100% similarity]
frame_layout.h [moved from c/frame_layout.h with 100% similarity]
gen_utf8_tables.py [moved from c/gen_utf8_tables.py with 100% similarity]
jv.c [moved from c/jv.c with 100% similarity]
jv.h [moved from c/jv.h with 100% similarity]
jv_dtoa.c [moved from c/jv_dtoa.c with 100% similarity]
jv_dtoa.h [moved from c/jv_dtoa.h with 100% similarity]
jv_parse.c [moved from c/jv_parse.c with 100% similarity]
jv_parse.h [moved from c/jv_parse.h with 100% similarity]
jv_print.c [moved from c/jv_print.c with 100% similarity]
jv_test.c [moved from c/jv_test.c with 100% similarity]
jv_unicode.c [moved from c/jv_unicode.c with 98% similarity]
jv_unicode.h [moved from c/jv_unicode.h with 100% similarity]
lexer.l [moved from c/lexer.l with 98% similarity]
locfile.h [moved from c/locfile.h with 100% similarity]
main.c [moved from c/main.c with 100% similarity]
opcode.c [moved from c/opcode.c with 100% similarity]
opcode.h [moved from c/opcode.h with 100% similarity]
opcode_list.h [moved from c/opcode_list.h with 100% similarity]
parser.h [moved from c/parser.h with 100% similarity]
parser.y [moved from c/parser.y with 99% similarity]
testdata [moved from c/testdata with 100% similarity]

index 130e618dda47e5420445d242cdd5e54bdc5633ec..50e45cc8d94284ac3427111300922e258ff96664 100644 (file)
@@ -1,12 +1,10 @@
 *.o
 *~
 
-# Autogenerated by flex/bison
-lexer.yy.*
-parser.tab.*
-parser.info
+# Autogenerated
+*.gen.*
 
 # Test binaries
 jv_test
 jv_parse
-parsertest
\ No newline at end of file
+parsertest*~
diff --git a/JQ.hs b/JQ.hs
deleted file mode 100644 (file)
index ca8df79..0000000
--- a/JQ.hs
+++ /dev/null
@@ -1,157 +0,0 @@
-module JQ where
-import Text.JSON
-import Text.JSON.String
-import Data.Maybe
-import Data.List (sortBy,sort,groupBy)
-import Data.Function (on)
-import Data.Ord (comparing)
-import Control.Monad
-import Control.Monad.Writer
-import Control.Monad.List
-import Control.Monad.Reader
-
-type Path = [Either Int String]
-
-type Program = JSValue -> [(JSValue, Path)]
-
-type JQ = ReaderT JSValue (WriterT Path [])
-
-runJQ :: JQ a -> JSValue -> [a]
-runJQ prog val = map fst $ runWriterT $ runReaderT prog val
-
-(>|) :: JQ JSValue -> JQ a -> JQ a
-a >| b = do
-  val <- a
-  local (const val) b
-
-collect :: JQ a -> JQ [a]
-collect prog = do
-  arg <- ask
-  return $ runJQ prog arg
-  
-collectPaths :: JQ a -> JQ [(a,Path)]
-collectPaths prog = do
-  arg <- ask
-  return $ runWriterT $ runReaderT prog arg
-
-insert :: JSValue -> (JSValue, Path) -> JSValue
-insert base (replace, []) = replace
-insert (JSArray values) (replace, ((Left n):rest)) = JSArray values'
-    where
-      (left, (_:right)) = splitAt n values
-      values' = left ++ [replace] ++ right
-insert (JSObject obj) (replace, ((Right k):rest))= JSObject $ toJSObject obj'
-    where
-      withoutK = filter ((/= k) . fst) $ fromJSObject obj
-      obj' = (k, replace):withoutK
-
-
-eqj a b = JSBool $ a == b
-
-
-liftp :: (JSValue -> JSValue) -> JQ JSValue
-liftp f = liftM f ask
-
-idp = undefined
-failp t = []
-
-constp :: JSValue -> Program
-constp t t' = idp t
-
-anyj :: [JSValue] -> Bool
-anyj values = any isTrue values
-  where
-    isTrue (JSBool False) = False
-    isTrue (JSNull) = False
-    isTrue _ = True
-
-selectp prog = do
-  match <- collect prog
-  guard $ anyj match
-  ask
-
-constStr :: String -> JQ JSValue
-constStr = return . JSString . toJSString
-
-constInt :: Int -> JQ JSValue
-constInt = return . JSRational False . toRational
-
-updatep p = do
-  t <- ask
-  liftM (foldl insert t) $ collectPaths p
-
-arrayp prog = liftM JSArray $ collect prog
-
-
-childp' :: JSValue -> JQ JSValue
-childp' (JSArray values) = msum [tell [Left i] >> return v | (v,i) <- zip values [0..]]
-childp' (JSObject obj) = msum [tell [Right k] >> return v | (k,v) <- fromJSObject obj]
-childp' _ = mzero
-
-childp = ask >>= childp'
-
---findp :: Program -> Program
-findp prog = do
-  found <- collect prog
-  if anyj found then ask else childp >| findp prog
-
-groupp prog = do
-  list <- ask
-  case list of
-    JSArray values -> do
-      marked <- forM values $ \v -> do 
-        m <- collect (return v >| prog)
-        return (m,v)
-      msum $
-        map (return . JSArray . map snd) $ 
-        groupBy ((==) `on` fst) $ 
-        sortBy (comparing fst) $ 
-        marked
-    _ -> return JSNull
-
-
-  
-
-withArray f (JSArray values) = JSArray $ f values
-withArray f x = x
-
-callp "select" [p] = selectp p
-callp "find" [p] = findp p
-callp "set" [p] = updatep p
-callp "sort" [] = liftp (withArray sort)
-callp "group" [p] = groupp p
-
-lookupj :: JSValue -> JSValue -> JQ JSValue
-lookupj (JSArray values) (JSRational _ n) = do
-  let idx = round n
-  tell [Left idx]
-  if idx >= 0 && idx < length values
-    then return $ values !! idx
-    else return $ JSNull
-lookupj (JSObject obj) (JSString s) = do
-  tell [Right (fromJSString s)]
-  case (lookup (fromJSString s) (fromJSObject obj)) of
-    Just x -> return x
-    Nothing -> return JSNull
-lookupj _ _ = mzero
-
-
-plusj (JSRational _ n1) (JSRational _ n2) = JSRational True (n1 + n2)
-plusj (JSString s1) (JSString s2) = JSString $ toJSString (fromJSString s1 ++ fromJSString s2)
-plusj (JSArray a1) (JSArray a2) = JSArray $ a1 ++ a2
-
-
-js :: JSON a => a -> JSValue
-js = showJSON
-
-index s = do
-  v <- ask
-  lookupj v (js s)
-
-
-dictp progs = do
-  liftM (JSObject . toJSObject) $ forM progs $ \(k,v) -> do
-    JSString k' <- k
-    v' <- v
-    return (fromJSString k', v')
-
diff --git a/Lexer.x b/Lexer.x
deleted file mode 100644 (file)
index 700c69e..0000000
--- a/Lexer.x
+++ /dev/null
@@ -1,101 +0,0 @@
-{
-module Lexer where
-import Control.Monad.Error
-}
-
-%wrapper "monadUserState"
-
-$digit = 0-9
-$alpha = [a-zA-Z_]
-@reserved = "."|"["|"]"|","|":"|"("|")"|"{"|"}"|"|"|"=="|"+"
-@ident = $alpha [$alpha $digit]*
-@string = \" ($printable)* \"
-
-
-tokens :- 
-
-<0> $white+             ;
-<0> @reserved           { tok TRes }
-<0> @ident              { tok TIdent }
-<0> $digit+             { tok $ TInt . read }
-
-
-<0> \"                  { enterString }
-<string> \"             { leaveString }
-<string> ($printable # [\"\\]) { pushString id }
-<string> \\ [\"\\\/]    { pushString (drop 1) }
-<string> \\ [nrt]       { pushString (escape . drop 1) }
---<string> \\ 'u' [0-9a-fA-F]{4}
---                        { pushString (parseUnicode . drop 2) }
-
--- @string { \s -> TString $ init $ tail s}
-
-
-{
-  
-escape :: String -> String
-escape "r" = "\r"
-escape "n" = "\n"
-escape "t" = "\t"
-
-getState :: Alex AlexState
-getState = Alex $ \s -> Right (s, s)
-
-getUserState :: Alex AlexUserState
-getUserState = liftM alex_ust getState
-
-setUserState :: AlexUserState -> Alex ()
-setUserState s' = Alex $ \s -> Right (s{alex_ust = s'}, ()) 
-
-alexEOF = return $ Nothing
-
-enterString input len = do
-  setUserState []
-  alexSetStartCode string
-  skip input len
-
-pushString f i@(p, _, s) len = do
-  buf <- getUserState
-  setUserState (buf ++ [f $ take len s])
-  skip i len
-  
-leaveString input len = do
-  s <- getUserState
-  alexSetStartCode 0
-  return $ Just $ TString $ concat s
-  
-
-tok f (p,_,s) len = return $ Just $ f (take len s)
-data Token = TRes String | TString String | TIdent String | TInt Int
-
-instance Show Token where
-  show (TRes t) = "token " ++ t
-  show (TString t) = "string " ++ t
-  show (TIdent t) = "identifier " ++ t
-  show (TInt t) = "integer " ++ show t
-
-
-type AlexUserState = [String]
-
-alexInitUserState = undefined
-
-wrapError (Alex scanner) = Alex $ \s -> case scanner s of
-  Left message -> Left (message ++ " at " ++ showpos (alex_pos s))
-    where
-      showpos (AlexPn off line col) = "line " ++ show line ++ ", column " ++ show col
-  x -> x
-
-scanner = do
-  tok <- wrapError alexMonadScan
-  case tok of
-    Nothing -> do
-      s <- getState
-      case alex_scd s of
-        0 -> return []
-        string -> alexError "Unterminated string literal"
-    Just tok -> liftM (tok:) scanner
-
-runLexer :: String -> Either String [Token]
-runLexer input = runAlex input scanner
-
-}
\ No newline at end of file
diff --git a/Main.hs b/Main.hs
deleted file mode 100644 (file)
index 695520c..0000000
--- a/Main.hs
+++ /dev/null
@@ -1,22 +0,0 @@
-import Parser
-import Lexer
-import JQ
-import Text.JSON
-import Text.JSON.String
-import System.Environment
-import Control.Monad
-import System.IO
-
-
-parseJS :: String -> JSValue
-parseJS s = case runGetJSON readJSValue s of
-  Left err -> error err
-  Right val -> val
-
-  
-main = do
-  [program] <- getArgs
-  json <- liftM parseJS $ hGetContents stdin
-  case runLexer program >>= runParser of
-    Left err -> putStrLn err
-    Right program -> mapM_ (putStrLn . encode) (runJQ program json)
\ No newline at end of file
similarity index 50%
rename from c/Makefile
rename to Makefile
index 7f58c6171be1ff7fb055b54e10dcb023bea09804..db63b77741a17fc5e927b37c3c8bbfcf65835139 100644 (file)
+++ b/Makefile
@@ -8,23 +8,23 @@ clean:
        sed 's/.*`\(.*\)'\''.*/\1/' | grep -v '^all$$' | \
        xargs rm
 
-jv_utf8_tables.h: gen_utf8_tables.py
+jv_utf8_tables.gen.h: gen_utf8_tables.py
        python $^ > $@
 
-lexer.yy.c: lexer.l
-       flex -o lexer.yy.c --header-file=lexer.yy.h lexer.l
-lexer.yy.h: lexer.yy.c
+lexer.gen.c: lexer.l
+       flex -o lexer.gen.c --header-file=lexer.gen.h lexer.l
+lexer.gen.h: lexer.gen.c
 
-parser.tab.c: parser.y lexer.yy.h
-       bison -W -d parser.y -v --report-file=parser.info
-parser.tab.h: parser.tab.c
+parser.gen.c: parser.y lexer.gen.h
+       bison -W -d parser.y -v --report-file=parser.gen.info -o $@
+parser.gen.h: parser.gen.c
 
-jv_unicode.c: jv_utf8_tables.h
+jv_unicode.c: jv_utf8_tables.gen.h
 
-parsertest: parser.tab.c lexer.yy.c main.c opcode.c bytecode.c compile.c execute.c builtin.c jv.c jv_parse.c jv_print.c jv_dtoa.c jv_unicode.c
+parsertest: parser.gen.c lexer.gen.c main.c opcode.c bytecode.c compile.c execute.c builtin.c jv.c jv_parse.c jv_print.c jv_dtoa.c jv_unicode.c
        $(CC) -DJQ_DEBUG=1 -o $@ $^
 
-jq: parser.tab.c lexer.yy.c main.c opcode.c bytecode.c compile.c execute.c builtin.c jv.c jv_parse.c jv_print.c jv_dtoa.c jv_unicode.c
+jq: parser.gen.c lexer.gen.c main.c opcode.c bytecode.c compile.c execute.c builtin.c jv.c jv_parse.c jv_print.c jv_dtoa.c jv_unicode.c
        $(CC) -DJQ_DEBUG=0 -o $@ $^
 
 jv_test: jv_test.c jv.c jv_print.c jv_dtoa.c jv_unicode.c
diff --git a/Parser.y b/Parser.y
deleted file mode 100644 (file)
index 544fe5b..0000000
--- a/Parser.y
+++ /dev/null
@@ -1,78 +0,0 @@
-{
-module Parser where
-import Lexer
-import JQ
-import Text.JSON
-import Debug.Trace
-import Data.List
-import Control.Monad.Error
-import Control.Monad.Reader
-}
-
-%name runParser Exp
-%tokentype { Token }
-
-%monad { Either String }
-%error { \t -> fail $ "parse error: unexpected " ++ if null t then [] else (show $ head t) }
-
-%token
-  '|' { TRes "|" }
-  '.' { TRes "." }
-  '[' { TRes "[" }
-  ']' { TRes "]" }
-  '{' { TRes "{" }
-  '}' { TRes "}" }
-  '(' { TRes "(" }
-  ')' { TRes ")" }
-  ',' { TRes "," }
-  ':' { TRes ":" }
-  '==' { TRes "==" }
-  '+' { TRes "+" }
-  Ident { TIdent $$ }
-  String { TString $$ }
-  Int { TInt $$ }
-
-%left '|'
-%left ','
-%nonassoc '=='
-%left '+'
-
-%%
-
-Exp 
-  : Exp '|' Exp         { $1 >| $3 }
-  | Exp ',' Exp         { $1 `mplus` $3 }
-  | Exp '==' Exp        { liftM2 eqj $1 $3 }
-  | Exp '+' Exp         { liftM2 plusj $1 $3 }
-  | Term                { $1 }
-
-ExpD
-  : ExpD '|' ExpD       { $1 >| $3 }
-  | ExpD '==' ExpD      { liftM2 eqj $1 $3 }
-  | Term                { $1 }
-
-
-Term 
-  : '.'                 { ask }
-  | Term '.' Ident      { $1 >| index $3 }
-  | '.' Ident           { index $2 }
-  | String              { constStr $1 }
-  | Term '[' Exp ']'    { do {t <- $1; i <- $3; lookupj t i} }
-  | Term '[' ']'        { $1 >| childp }
-  | '(' Exp ')'         { $2 }
-  | '[' Exp ']'         { arrayp $2 }
-  | Int                 { constInt $1 }
-  | '{' MkDict '}'      { dictp $2 }
-  | Ident '(' Exp ')'   { callp $1 [$3] }
-  | Ident               { callp $1 [] }
-
-MkDict
-  :                     { [] }
-  | MkDictPair          { [$1] }
-  | MkDictPair ',' MkDict { $1:$3 }
-MkDictPair
-  : Ident ':' ExpD      { (constStr $1, $3) }
-  | Ident               { (constStr $1, index $1) }
-  | String ':' ExpD     { (constStr $1, $3) }
-  | '(' Exp ')' ':' ExpD{ ($2, $5) }
similarity index 100%
rename from c/builtin.c
rename to builtin.c
similarity index 100%
rename from c/builtin.h
rename to builtin.h
similarity index 100%
rename from c/bytecode.c
rename to bytecode.c
similarity index 100%
rename from c/bytecode.h
rename to bytecode.h
similarity index 100%
rename from c/compile.c
rename to compile.c
similarity index 100%
rename from c/compile.h
rename to compile.h
similarity index 100%
rename from c/execute.c
rename to execute.c
similarity index 100%
rename from c/forkable_stack.h
rename to forkable_stack.h
similarity index 100%
rename from c/frame_layout.h
rename to frame_layout.h
similarity index 100%
rename from c/gen_utf8_tables.py
rename to gen_utf8_tables.py
diff --git a/c/jv.c b/jv.c
similarity index 100%
rename from c/jv.c
rename to jv.c
diff --git a/c/jv.h b/jv.h
similarity index 100%
rename from c/jv.h
rename to jv.h
similarity index 100%
rename from c/jv_dtoa.c
rename to jv_dtoa.c
similarity index 100%
rename from c/jv_dtoa.h
rename to jv_dtoa.h
similarity index 100%
rename from c/jv_parse.c
rename to jv_parse.c
similarity index 100%
rename from c/jv_parse.h
rename to jv_parse.h
similarity index 100%
rename from c/jv_print.c
rename to jv_print.c
similarity index 100%
rename from c/jv_test.c
rename to jv_test.c
similarity index 98%
rename from c/jv_unicode.c
rename to jv_unicode.c
index 375ad36702aa46b1277f7583cb05830d720c39ec..b1417a2a504c8508dc24e68a4b44fe9e45e24291 100644 (file)
@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include <assert.h>
 #include "jv_unicode.h"
-#include "jv_utf8_tables.h"
+#include "jv_utf8_tables.gen.h"
 
 const char* jvp_utf8_next(const char* in, const char* end, int* codepoint) {
   if (in == end) {
similarity index 100%
rename from c/jv_unicode.h
rename to jv_unicode.h
similarity index 98%
rename from c/lexer.l
rename to lexer.l
index 07cba83c56a963082a18a0336dbf3a6a8086e884..e604adabe1215f271bd6e06eda759856e62101aa 100644 (file)
--- a/c/lexer.l
+++ b/lexer.l
@@ -1,6 +1,6 @@
 %{
 #include "compile.h"
-#include "parser.tab.h"  /* Generated by bison. */
+#include "parser.gen.h"  /* Generated by bison. */
 
 #define YY_USER_ACTION                           \
   do {                                           \
similarity index 100%
rename from c/locfile.h
rename to locfile.h
diff --git a/c/main.c b/main.c
similarity index 100%
rename from c/main.c
rename to main.c
similarity index 100%
rename from c/opcode.c
rename to opcode.c
similarity index 100%
rename from c/opcode.h
rename to opcode.h
similarity index 100%
rename from c/opcode_list.h
rename to opcode_list.h
similarity index 100%
rename from c/parser.h
rename to parser.h
similarity index 99%
rename from c/parser.y
rename to parser.y
index b47c3574f3adc9a79ec9831db9404d315a3a661a..0fda65bdfb0d7358a11d1185c346b09974bc2826 100644 (file)
+++ b/parser.y
@@ -81,7 +81,7 @@
 
 %type <blk> Exp Term MkDict MkDictPair ExpD ElseBody QQString FuncDef FuncDefs
 %{
-#include "lexer.yy.h"
+#include "lexer.gen.h"
 #define FAIL(loc, msg)                                   \
   do {                                                   \
     location l = loc;                                    \
similarity index 100%
rename from c/testdata
rename to testdata