summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-02-24 08:03:59 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-02-24 19:17:30 -0800
commit501453a261771e2874bd065a78772e987616b14c (patch)
tree569029b676c1df641959e14528a0d28303593f5e
parentfd795adb279719bf77a7a6333b1e97500c454964 (diff)
downloadtxr-501453a261771e2874bd065a78772e987616b14c.tar.gz
txr-501453a261771e2874bd065a78772e987616b14c.tar.bz2
txr-501453a261771e2874bd065a78772e987616b14c.zip
* parser.l: Support octal and binary numbers.
* txr.1: Documented. * genvim.txr, txr.vim: Updated.
-rw-r--r--ChangeLog8
-rw-r--r--genvim.txr2
-rw-r--r--parser.l44
-rw-r--r--txr.19
-rw-r--r--txr.vim2
5 files changed, 65 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 9e10c324..298f658b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2014-02-24 Kaz Kylheku <kaz@kylheku.com>
+ * parser.l: Support octal and binary numbers.
+
+ * txr.1: Documented.
+
+ * genvim.txr, txr.vim: Updated.
+
+2014-02-24 Kaz Kylheku <kaz@kylheku.com>
+
* parser.y (modifiers): Bugfix: list element not subject to expansion
of Lisp forms denoted by @.
(expand_meta): Bugfix: failure to expand vars, which can be
diff --git a/genvim.txr b/genvim.txr
index d14eea5c..11a989bb 100644
--- a/genvim.txr
+++ b/genvim.txr
@@ -85,6 +85,8 @@ syn match txr_ncomment ";.*" contained
syn match txr_dot "\." contained
syn match txr_num "#x[+\-]\?[0-9A-Fa-f]\+" contained
+syn match txr_num "#o[+\-]\?[0-7]\+" contained
+syn match txr_num "#b[+\-]\?[0-1]\+" contained
syn match txr_num "[+\-]\?[0-9]\+" contained
syn match txr_ident "[:@@]\?[A-Za-z0-9!$%&*+\-<=>?\\^_~]*[A-Za-z!$%&*+\-<=>?\\^_~][A-Za-z0-9!$%&*+\-<=>?\\^_~]*" contained
syn match txl_ident "[:@@]\?[A-Za-z0-9!$%&*+\-<=>?\\^_~/]*[A-Za-z!$%&*+\-<=>?\\^_~/][A-Za-z0-9!$%&*+\-<=>?\\^_~/]*" contained
diff --git a/parser.l b/parser.l
index d553b56b..0f30365a 100644
--- a/parser.l
+++ b/parser.l
@@ -156,6 +156,8 @@ NUM {SGN}?{DIG}+
FLO {SGN}?({DIG}*[.]{DIG}+{EXP}?|{DIG}+[.]?{EXP})
FLODOT {SGN}?{DIG}+[.]
XNUM #x{SGN}?{XDIG}+
+ONUM #o{SGN}?[0-7]+
+BNUM #b{SGN}?[0-1]+
BSCHR [a-zA-Z0-9!$%&*+\-<=>?\\^_~]
NSCHR [a-zA-Z0-9!$%&*+\-<=>?\\^_~/]
ID_END [^a-zA-Z0-9!$%&*+\-<=>?\\^_~/]
@@ -213,6 +215,28 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
return NUMBER;
}
+<SPECIAL,NESTED,BRACED>{ONUM} {
+ val str = string_own(utf8_dup_from(yytext + 2));
+
+ if (yy_top_state() == INITIAL
+ || yy_top_state() == QSILIT)
+ yy_pop_state();
+
+ yylval.val = int_str(str, num(8));
+ return NUMBER;
+}
+
+<SPECIAL,NESTED,BRACED>{BNUM} {
+ val str = string_own(utf8_dup_from(yytext + 2));
+
+ if (yy_top_state() == INITIAL
+ || yy_top_state() == QSILIT)
+ yy_pop_state();
+
+ yylval.val = int_str(str, num(2));
+ return NUMBER;
+}
+
<SPECIAL>({FLO}|{FLODOT}){TOK} |
<BRACED>({FLO}|{FLODOT}){BTOK} |
<NESTED>({FLO}|{FLODOT}){NTOK} {
@@ -270,6 +294,26 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
return METANUM;
}
+<NESTED,QSILIT>@{ONUM} {
+ val str = string_own(utf8_dup_from(yytext + 3));
+
+ if (yy_top_state() == INITIAL
+ || yy_top_state() == QSILIT)
+ yy_pop_state();
+ yylval.val = int_str(str, num(8));
+ return METANUM;
+}
+
+<NESTED,QSILIT>@{BNUM} {
+ val str = string_own(utf8_dup_from(yytext + 3));
+
+ if (yy_top_state() == INITIAL
+ || yy_top_state() == QSILIT)
+ yy_pop_state();
+ yylval.val = int_str(str, num(2));
+ return METANUM;
+}
+
<SPECIAL>{TOK} |
<BRACED>{BTOK} |
<NESTED>{NTOK} {
diff --git a/txr.1 b/txr.1
index 0838a5c4..9195a2bd 100644
--- a/txr.1
+++ b/txr.1
@@ -1152,6 +1152,15 @@ and the upper or lower case letters A through F:
#xFF ;; 255
#x-ABC ;; -2748
+Similarly, octal numbers are supported with the prefix #o followed by
+octal digits:
+
+ #b777 ;; 511
+
+and binary numbers can be written with a #b prefix:
+
+ #b1110 ;; 14
+
A floating-point constant is marked by the inclusion of a decimal point, the
exponential "e notation", or both. It is an optional sign, followed
by a mantissa consisting of digits, a decimal point, more digits, and then an
diff --git a/txr.vim b/txr.vim
index a44d7830..268fcbad 100644
--- a/txr.vim
+++ b/txr.vim
@@ -184,6 +184,8 @@ syn match txr_ncomment ";.*" contained
syn match txr_dot "\." contained
syn match txr_num "#x[+\-]\?[0-9A-Fa-f]\+" contained
+syn match txr_num "#o[+\-]\?[0-7]\+" contained
+syn match txr_num "#b[+\-]\?[0-1]\+" contained
syn match txr_num "[+\-]\?[0-9]\+" contained
syn match txr_ident "[:@]\?[A-Za-z0-9!$%&*+\-<=>?\\^_~]*[A-Za-z!$%&*+\-<=>?\\^_~][A-Za-z0-9!$%&*+\-<=>?\\^_~]*" contained
syn match txl_ident "[:@]\?[A-Za-z0-9!$%&*+\-<=>?\\^_~/]*[A-Za-z!$%&*+\-<=>?\\^_~/][A-Za-z0-9!$%&*+\-<=>?\\^_~/]*" contained