Update format specifiers

pull/70/head
Stephan Seitz 2021-04-18 18:34:30 +07:00
parent 4ce4a62efe
commit 6cc6cd07db
5 changed files with 58398 additions and 58417 deletions

@ -43,6 +43,10 @@ function srepeat(...args) {
return repeat(seq(...args))
}
function sep1 (rule, separator) {
return seq(rule, repeat(seq(separator, rule)))
}
module.exports = grammar(clojure, {
name: 'commonlisp',
@ -81,11 +85,13 @@ module.exports = grammar(clojure, {
repeat(choice(field('value', $._form), $._gap)),
field('close', ")")),
_format_token: $ => choice($.num_lit, seq("'", /./)),
// https://en.wikipedia.org/wiki/Format_Common_Lisp)
format_prefix_parameters: _ => choice('v', 'V', '#'),
format_modifiers: _ => choice('@', '@:', ':', ':@'),
format_modifiers: $ => seq(repeat(choice($._format_token, ',')), choice('@', '@:', ':', ':@')),
//format_modifiers: _ => choice('@', '@:', ':', ':@'),
format_directive_type: $ => choice(
seq(optional(field('repetitions', choice($.num_lit))), choice('~', '%', '&', '|')),
seq(optional(field('repetitions', $._format_token)), choice('~', '%', '&', '|')),
/[cC]/,
/\^/,
'\n',
@ -93,7 +99,6 @@ module.exports = grammar(clojure, {
/[pP]/,
/[iI]/,
/[wW]/,
/[sS]/,
/[aA]/,
'_',
/[()]/,
@ -101,11 +106,11 @@ module.exports = grammar(clojure, {
/[\[\]]/,
/[<>]/,
';',
seq(field('numberOfArgs', $.num_lit), '*'),
seq(field('numberOfArgs', $._format_token), '*'),
seq('/', $._form, '/', $._form, /[tT]/),
'?',
"Newline",
seq(repeat(choice($.num_lit, ',')), /[$rRbBdDgGxXeEoO]/),
seq(repeat(choice($._format_token, ',')), /[$rRbBdDgGxXeEoOsS]/),
),
format_specifier: $ =>
prec.left(seq(

@ -1776,6 +1776,28 @@
}
]
},
"_format_token": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "num_lit"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "'"
},
{
"type": "PATTERN",
"value": "."
}
]
}
]
},
"format_prefix_parameters": {
"type": "CHOICE",
"members": [
@ -1794,23 +1816,44 @@
]
},
"format_modifiers": {
"type": "CHOICE",
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "@"
},
{
"type": "STRING",
"value": "@:"
},
{
"type": "STRING",
"value": ":"
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_format_token"
},
{
"type": "STRING",
"value": ","
}
]
}
},
{
"type": "STRING",
"value": ":@"
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "@"
},
{
"type": "STRING",
"value": "@:"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "STRING",
"value": ":@"
}
]
}
]
},
@ -1827,13 +1870,8 @@
"type": "FIELD",
"name": "repetitions",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "num_lit"
}
]
"type": "SYMBOL",
"name": "_format_token"
}
},
{
@ -1892,10 +1930,6 @@
"type": "PATTERN",
"value": "[wW]"
},
{
"type": "PATTERN",
"value": "[sS]"
},
{
"type": "PATTERN",
"value": "[aA]"
@ -1932,7 +1966,7 @@
"name": "numberOfArgs",
"content": {
"type": "SYMBOL",
"name": "num_lit"
"name": "_format_token"
}
},
{
@ -1984,7 +2018,7 @@
"members": [
{
"type": "SYMBOL",
"name": "num_lit"
"name": "_format_token"
},
{
"type": "STRING",
@ -1995,7 +2029,7 @@
},
{
"type": "PATTERN",
"value": "[$rRbBdDgGxXeEoO]"
"value": "[$rRbBdDgGxXeEoOsS]"
}
]
}

@ -1476,6 +1476,10 @@
"multiple": false,
"required": false,
"types": [
{
"type": "'",
"named": false
},
{
"type": "num_lit",
"named": true
@ -1486,6 +1490,10 @@
"multiple": false,
"required": false,
"types": [
{
"type": "'",
"named": false
},
{
"type": "num_lit",
"named": true
@ -1595,7 +1603,17 @@
{
"type": "format_modifiers",
"named": true,
"fields": {}
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "num_lit",
"named": true
}
]
}
},
{
"type": "format_prefix_parameters",

File diff suppressed because it is too large Load Diff

@ -836,3 +836,49 @@ Num Literals (TODO)
(num_lit)
(sym_lit)
(num_lit)))
================================================================================
Format
================================================================================
"~S"
"~3,-4:@s"
"~,+4S"
(format T "~8,0b" 5)
(format T "~v,'0b" 8 5)
--------------------------------------------------------------------------------
(source
(str_lit
(format_specifier
(format_directive_type)))
(str_lit
(format_specifier
(format_modifiers
(num_lit)
(num_lit))
(format_directive_type)))
(str_lit
(format_specifier
(format_directive_type
(num_lit))))
(list_lit
(sym_lit)
(sym_lit)
(str_lit
(format_specifier
(format_directive_type
(num_lit)
(num_lit))))
(num_lit))
(list_lit
(sym_lit)
(sym_lit)
(str_lit
(format_specifier
(format_prefix_parameters)
(format_directive_type)))
(num_lit)
(num_lit)))