mirror of https://github.com/Wilfred/difftastic/
Some progress
parent
af9e5084f1
commit
05f5b856d6
@ -1,21 +1,93 @@
|
|||||||
/*
|
/*
|
||||||
* grammar.js
|
* grammar.js
|
||||||
* Copyright (C) 2021 Stephan Seitz <stephan.seitz@fau.de>
|
* Copyright (C) 2021 Stephan Seitz <stephan.seitz@fau.de>
|
||||||
|
* Adapted from tree-sitter-clojure
|
||||||
*
|
*
|
||||||
* Distributed under terms of the GPLv3 license.
|
* Distributed under terms of the GPLv3 license.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const clojure = require("tree-sitter-clojure/grammar");
|
const clojure = require("tree-sitter-clojure/grammar");
|
||||||
|
|
||||||
module.exports = grammar (clojure, {
|
const WHITESPACE_CHAR =
|
||||||
name: 'common-lisp',
|
/[\f\n\r\t \u000B\u001C\u001D\u001E\u001F\u2028\u2029\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2008\u2009\u200a\u205f\u3000]/;
|
||||||
|
|
||||||
extras: ($, original) => [...original],
|
const WHITESPACE =
|
||||||
conflicts: ($, original) => [...original],
|
token(repeat1(WHITESPACE_CHAR));
|
||||||
|
|
||||||
|
module.exports = grammar(clojure, {
|
||||||
|
name: 'commonlisp',
|
||||||
|
|
||||||
|
extras: ($, original) => [...original, $.block_comment],
|
||||||
|
conflicts: (_, original) => [...original],
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
source: $ =>
|
block_comment: _ => token(seq('#|', repeat(choice(/[^|]/, /\|[^#]/)) ,'|#')),
|
||||||
repeat(choice(clojure._form,
|
|
||||||
clojure._gap)),
|
fancy_literal: _ => token(seq('|', repeat(/[^|]/) ,'|')),
|
||||||
|
|
||||||
|
_ws: _ =>
|
||||||
|
WHITESPACE,
|
||||||
|
|
||||||
|
unquoting_lit: $ =>
|
||||||
|
seq(field('marker', ","),
|
||||||
|
repeat($._gap),
|
||||||
|
field('value', $._form)),
|
||||||
|
|
||||||
|
unquote_splicing_lit: $ =>
|
||||||
|
seq(repeat($._metadata_lit),
|
||||||
|
field('marker', ",@"),
|
||||||
|
repeat($._gap),
|
||||||
|
field('value', $._form)),
|
||||||
|
|
||||||
|
syn_quoting_lit: $ =>
|
||||||
|
seq(field('marker', "`"),
|
||||||
|
repeat($._gap),
|
||||||
|
field('value', $.list_lit)),
|
||||||
|
|
||||||
|
//defun_header: $ =>
|
||||||
|
//seq(field('keyword', 'defun'),
|
||||||
|
//repeat($._gap),
|
||||||
|
//field('function_name', $._form),
|
||||||
|
//repeat($._gap),
|
||||||
|
//field('lambda_list', $.list_lit)),
|
||||||
|
//
|
||||||
|
array_dimension: $ => seq($.num_lit, 'A'),
|
||||||
|
|
||||||
|
_bare_vec_lit: $ =>
|
||||||
|
choice(seq(field('open', '#0A'), $.num_lit),
|
||||||
|
seq(field('open', '#'), optional(field('dimension_indicator', $.array_dimension)), $.list_lit)),
|
||||||
|
|
||||||
|
_form: $ =>
|
||||||
|
choice(// atom-ish
|
||||||
|
$.num_lit,
|
||||||
|
$.fancy_literal,
|
||||||
|
//$.defun_header,
|
||||||
|
$.kwd_lit,
|
||||||
|
$.str_lit,
|
||||||
|
$.char_lit,
|
||||||
|
$.nil_lit,
|
||||||
|
//$.bool_lit,
|
||||||
|
$.sym_lit,
|
||||||
|
// basic collection-ish
|
||||||
|
$.list_lit,
|
||||||
|
//$.map_lit,
|
||||||
|
$.vec_lit,
|
||||||
|
// dispatch reader macros
|
||||||
|
$.set_lit,
|
||||||
|
//$.anon_fn_lit,
|
||||||
|
//$.regex_lit,
|
||||||
|
$.read_cond_lit,
|
||||||
|
$.splicing_read_cond_lit,
|
||||||
|
//$.ns_map_lit,
|
||||||
|
$.var_quoting_lit,
|
||||||
|
$.sym_val_lit,
|
||||||
|
$.evaling_lit,
|
||||||
|
//$.tagged_or_ctor_lit,
|
||||||
|
// some other reader macros
|
||||||
|
$.derefing_lit,
|
||||||
|
$.quoting_lit,
|
||||||
|
$.syn_quoting_lit,
|
||||||
|
$.unquote_splicing_lit,
|
||||||
|
$.unquoting_lit),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,89 @@
|
|||||||
|
==========================================
|
||||||
|
Block Comments
|
||||||
|
==========================================
|
||||||
|
|
||||||
|
#|(ql.foo:quickload "cl-project")
|
||||||
|
(defun add (a b) |
|
||||||
|
(+ a b ))|#
|
||||||
|
|
||||||
|
(add 8 9)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(source (block_comment) (list_lit (sym_lit) (num_lit) (num_lit)))
|
||||||
|
|
||||||
|
|
||||||
|
==========================================
|
||||||
|
Block Comments 2
|
||||||
|
==========================================
|
||||||
|
|
||||||
|
(add #|8 |#9)
|
||||||
|
|
||||||
|
---
|
||||||
|
(source (list_lit (sym_lit) (block_comment) (num_lit)))
|
||||||
|
|
||||||
|
|
||||||
|
==========================================
|
||||||
|
Quasi-Quoting
|
||||||
|
==========================================
|
||||||
|
|
||||||
|
`(add a ,(b))
|
||||||
|
`(add a ,@(b))
|
||||||
|
`(add a , b)
|
||||||
|
`(add a ,b)
|
||||||
|
|
||||||
|
---
|
||||||
|
(source
|
||||||
|
(syn_quoting_lit (list_lit (sym_lit) (sym_lit) (unquoting_lit (list_lit (sym_lit)))))
|
||||||
|
(syn_quoting_lit (list_lit (sym_lit) (sym_lit) (unquote_splicing_lit (list_lit (sym_lit)))))
|
||||||
|
(syn_quoting_lit (list_lit (sym_lit) (sym_lit) (unquoting_lit (sym_lit))))
|
||||||
|
(syn_quoting_lit (list_lit (sym_lit) (sym_lit) (unquoting_lit (sym_lit)))))
|
||||||
|
|
||||||
|
==========================================
|
||||||
|
Fancy Literal
|
||||||
|
==========================================
|
||||||
|
|
||||||
|
(|`(add a ,(b))| a)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(source (list_lit (fancy_literal) (sym_lit)))
|
||||||
|
|
||||||
|
==========================================
|
||||||
|
Defun header
|
||||||
|
|
||||||
|
(defun a (a b)
|
||||||
|
(car 1 2)
|
||||||
|
2)
|
||||||
|
( defun a (a b)
|
||||||
|
(car 1 2)
|
||||||
|
2)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(source (list_lit (defun_header (sym_lit) (list_lit (sym_lit) (sym_lit))) (list_lit (sym_lit) (num_lit) (num_lit)) (num_lit))
|
||||||
|
(list_lit (defun_header (sym_lit) (list_lit (sym_lit) (sym_lit))) (list_lit (sym_lit) (num_lit) (num_lit)) (num_lit)))
|
||||||
|
==========================================
|
||||||
|
--
|
||||||
|
(source)
|
||||||
|
|
||||||
|
|
||||||
|
==========================================
|
||||||
|
Vectors
|
||||||
|
==========================================
|
||||||
|
|
||||||
|
#( 2 3 4)
|
||||||
|
#()
|
||||||
|
|
||||||
|
---
|
||||||
|
(source (vec_lit (list_lit (num_lit) (num_lit) (num_lit))) (vec_lit (list_lit)))
|
||||||
|
|
||||||
|
==========================================
|
||||||
|
Arrays
|
||||||
|
==========================================
|
||||||
|
|
||||||
|
#0A2
|
||||||
|
#2A((2 3 4))
|
||||||
|
|
||||||
|
---
|
||||||
|
(source (vec_lit (num_lit)) (vec_lit (array_dimension (num_lit)) (list_lit (list_lit (num_lit) (num_lit) (num_lit)))))
|
||||||
Loading…
Reference in New Issue