From 501453a261771e2874bd065a78772e987616b14c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 24 Feb 2014 08:03:59 -0800 Subject: * parser.l: Support octal and binary numbers. * txr.1: Documented. * genvim.txr, txr.vim: Updated. --- ChangeLog | 8 ++++++++ genvim.txr | 2 ++ parser.l | 44 ++++++++++++++++++++++++++++++++++++++++++++ txr.1 | 9 +++++++++ txr.vim | 2 ++ 5 files changed, 65 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9e10c324..298f658b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2014-02-24 Kaz Kylheku + + * parser.l: Support octal and binary numbers. + + * txr.1: Documented. + + * genvim.txr, txr.vim: Updated. + 2014-02-24 Kaz Kylheku * parser.y (modifiers): Bugfix: list element not subject to expansion 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; } +{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; +} + +{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; +} + ({FLO}|{FLODOT}){TOK} | ({FLO}|{FLODOT}){BTOK} | ({FLO}|{FLODOT}){NTOK} { @@ -270,6 +294,26 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} return METANUM; } +@{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; +} + +@{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; +} + {TOK} | {BTOK} | {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 -- cgit v1.2.3