bug#13485: wrong warning for format ~!

2013-01-19 Thread Ian Price
Ian Price  writes:

> I'm currently looking through the format docs to see if any others are
> mishandled, and will post a patch later.

So, having went through all of the docs for format, I think I've handled
all of the sequences correctly (except for the iteration ones, which
were already done, and I never double-checked). The two main issues were
sequences that don't take an argument updating the count, and some
sequences were not treated insensitively.

~^ confused me a little, but I think I have the correct behaviour for it

Ludovic,
are there test cases for this? I'm not sure where to look

-- 
Ian Price -- shift-reset.com

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"
>From 986181b3b7bd7b6a0814ed45cb606238ab927db3 Mon Sep 17 00:00:00 2001
From: Ian Price 
Date: Sat, 19 Jan 2013 17:05:27 +
Subject: [PATCH] Fix argument count for various format string escape
 sequences.

* module/language/tree-il/analyze.scm (format-string-argument-count):
  Handle ~t and ~k options case-insensitively.
  ~! ~| ~/ ~q and ~Q should not update the min-count or max-count.
  ~^ returns the min-count and 'any
---
 module/language/tree-il/analyze.scm |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/module/language/tree-il/analyze.scm b/module/language/tree-il/analyze.scm
index 88f81f3..29dd876 100644
--- a/module/language/tree-il/analyze.scm
+++ b/module/language/tree-il/analyze.scm
@@ -1259,7 +1259,7 @@ accurate information is missing from a given `tree-il' element."
 (case state
   ((tilde)
(case (car chars)
- ((#\~ #\% #\& #\t #\_ #\newline #\( #\))
+ ((#\~ #\% #\& #\t #\T #\_ #\newline #\( #\) #\! #\| #\/ #\q #\Q)
 (loop (cdr chars) 'literal '()
   conditions end-group
   min-count max-count))
@@ -1330,10 +1330,12 @@ accurate information is missing from a given `tree-il' element."
  min-count)
   (+ (or (previous-number params) 1)
  max-count
- ((#\? #\k)
+ ((#\? #\k #\K)
   ;; We don't have enough info to determine the exact number
   ;; of args, but we could determine a lower bound (TODO).
   (values 'any 'any))
+ ((#\^)
+  (values min-count 'any))
  ((#\h #\H)
 (let ((argc (if (memq #\: params) 2 1)))
   (loop (cdr chars) 'literal '()
-- 
1.7.7.6



bug#13485: wrong warning for format ~!

2013-01-19 Thread Ian Price
Ian Price  writes:

>> I'm currently looking through the format docs to see if any others are
>> mishandled, and will post a patch later.
>
> So, having went through all of the docs for format, I think I've handled
> all of the sequences correctly (except for the iteration ones, which
> were already done, and I never double-checked).

Okay, spoke too soon. I forgot about the ' # + - parts of parameters.
I am less sure of these, but I have attached a patch.

-- 
Ian Price -- shift-reset.com

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"
>From f479d801659708d04bf23d26bc81600d68282e18 Mon Sep 17 00:00:00 2001
From: Ian Price 
Date: Sat, 19 Jan 2013 17:40:24 +
Subject: [PATCH] Fix escape sequence parameter handling in
 format-string-argument-count

* module/language/tree-il/analyze.scm (format-string-argument-count):
  + - # and ' should not increase the argument count.
---
 module/language/tree-il/analyze.scm |7 ++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/module/language/tree-il/analyze.scm b/module/language/tree-il/analyze.scm
index 29dd876..badce9f 100644
--- a/module/language/tree-il/analyze.scm
+++ b/module/language/tree-il/analyze.scm
@@ -1263,7 +1263,7 @@ accurate information is missing from a given `tree-il' element."
 (loop (cdr chars) 'literal '()
   conditions end-group
   min-count max-count))
- ((#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\, #\: #\@)
+ ((#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\, #\: #\@ #\+ #\- #\#)
 (loop (cdr chars)
   'tilde (cons (car chars) params)
   conditions end-group
@@ -1342,6 +1342,11 @@ accurate information is missing from a given `tree-il' element."
 conditions end-group
 (+ argc min-count)
 (+ argc max-count
+ ((#\')
+  (if (null? (cdr chars))
+  (throw &syntax-error 'unexpected-termination)
+  (loop (cddr chars) 'tilde (cons (cadr chars) params)
+conditions end-group min-count max-count)))
  (else  (loop (cdr chars) 'literal '()
   conditions end-group
   (+ 1 min-count) (+ 1 max-count)
-- 
1.7.7.6



bug#13485: wrong warning for format ~!

2013-01-19 Thread Ludovic Courtès
Hi!

Ian Price  skribis:

> So, having went through all of the docs for format, I think I've handled
> all of the sequences correctly (except for the iteration ones, which
> were already done, and I never double-checked). The two main issues were
> sequences that don't take an argument updating the count, and some
> sequences were not treated insensitively.

Excellent.

> Ludovic,
> are there test cases for this? I'm not sure where to look

Yes, in tree-il.test.  Can you add them?

Thanks!

Ludo’.