+ g++ -std=c++11 -Wall -I _tmp/micro-syntax -O0 -fsanitize=address -o _tmp/micro-syntax/micro_syntax doctools/micro_syntax.cc
+ set +o xtrace
  CXX doctools/micro_syntax.cc
Usage: micro-syntax FLAGS* FILE*

Recognizes the syntax of each file,, and prints it to stdout.

If there are no files, reads stdin.

Flags:
  -h --help   This help

  -l --lang   Language: py|cpp|shell|...
  -t          Print tokens as TSV, instead of ANSI color
  -w          Print HTML for the web

  -m          More color, useful for debugging tokens

  -n --no-comments    Omit comments
  -o --comments-only  Only print comments
  -e --empty-strs     Substitute string literals for empty strings
     --color          on off always more


ANSI

=== <stdin> ===

    1 echo "hi $name"
1 lines, 1 significant

WEB
7:<stdin>,140:<tr><td class=num>1</td><td id=L1 class=line>echo <span class=str>"</span><span class=str>hi $name</span><span class=str>"</span>
</td></tr>,36:{"num_lines": 1, "num_sig_lines": 1},
+ echo TSV
TSV
+ echo 'echo "hi $name"'
+ _tmp/micro-syntax/micro_syntax -l shell -t
7:<stdin>,1	Name	0	4
1	WS	4	5
1	Str	5	6
1	Str	6	14
1	Str	14	15
1	WS	15	16
0:,36:{"num_lines": 1, "num_sig_lines": 1},+ echo

+ echo

+ echo '"dq"'
+ _tmp/micro-syntax/micro_syntax -l shell

=== <stdin> ===

    1 "dq"
1 lines, 0 significant
+ _tmp/micro-syntax/micro_syntax -l shell configure
+ wc -l
491
+ set +o errexit
+ _tmp/micro-syntax/micro_syntax -l shell _nonexistent_ZZ
Error opening _nonexistent_ZZ: No such file or directory
+ local status=1
+ test 1 -ne 1
+ set -o errexit
+ echo

+ run-tests
+ local bin=_tmp/micro-syntax/micro_syntax
+ build
+ local variant=asan
+ case $variant in
+ cxxflags='-O0 -fsanitize=address'
+ mkdir -p _tmp/micro-syntax
+ local cc=doctools/micro_syntax.cc
+ local h=_tmp/micro-syntax/micro_syntax.h
+ local bin=_tmp/micro-syntax/micro_syntax
+ my-re2c doctools/micro_syntax.re2c.h _tmp/micro-syntax/micro_syntax.h
+ local in=doctools/micro_syntax.re2c.h
+ local out=_tmp/micro-syntax/micro_syntax.h
+ re2c --tags -W -Wno-match-empty-string -Werror -o _tmp/micro-syntax/micro_syntax.h doctools/micro_syntax.re2c.h
+ set -o xtrace
+ g++ -std=c++11 -Wall -I _tmp/micro-syntax -O0 -fsanitize=address -o _tmp/micro-syntax/micro_syntax doctools/micro_syntax.cc
+ set +o xtrace
  CXX doctools/micro_syntax.cc
==== echo $'multi \n
     sq \' line'

=== <stdin> ===

    1 echo $'multi \n
    2      sq \' line'
2 lines, 1 significant

==== echo hi \' there

=== <stdin> ===

    1 echo hi \' there
1 lines, 1 significant

==== echo one#two

=== <stdin> ===

    1 echo one#two
1 lines, 1 significant

==== echo $(( 16#ff ))

=== <stdin> ===

    1 echo $(( 16#ff ))
1 lines, 1 significant

==== # comment

=== <stdin> ===

    1 # comment
1 lines, 0 significant

==== ### comment

=== <stdin> ===

    1 ### comment
1 lines, 0 significant

==== echo one # comment

=== <stdin> ===

    1 echo one # comment
1 lines, 1 significant

==== cat <<EOF
hello $world
EOF

=== <stdin> ===

    1 cat <<EOF
    2 hello $world
    3 EOF
3 lines, 1 significant

==== cat <<- "EOF"
$3.99
EOF 

=== <stdin> ===

    1 cat <<- "EOF"
    2 $3.99
    3 EOF 
3 lines, 1 significant

==== cat <<- \_ACAWK
$3.99
more
_ACAWK 
echo yo

=== <stdin> ===

    1 cat <<- \_ACAWK
    2 $3.99
    3 more
    4 _ACAWK 
    5 echo yo
5 lines, 2 significant

==== echo multiple << EOF1 << EOF2 > out
one
EOF1
...
two
EOF2
echo done

=== <stdin> ===

    1 echo multiple << EOF1 << EOF2 > out
    2 one
    3 EOF1
    4 ...
    5 two
    6 EOF2
    7 echo done
7 lines, 2 significant

==== #if 0

=== <stdin> ===

    1 #if 0
1 lines, 1 significant

==== not prepreproc #ifdef 0

=== <stdin> ===

    1 not prepreproc #ifdef 0
1 lines, 1 significant

==== // comment can't 

=== <stdin> ===

    1 // comment can't 
1 lines, 0 significant

==== f(); // comment isn't 

=== <stdin> ===

    1 f(); // comment isn't 
1 lines, 1 significant

==== '\''

=== <stdin> ===

    1 '\''
1 lines, 0 significant

==== void f(); /* multi-line
                comment
             */
  void g(int x);

=== <stdin> ===

    1 void f(); /* multi-line
    2                 comment
    3              */
    4   void g(int x);
4 lines, 2 significant

==== #include "foo.h"

=== <stdin> ===

    1 #include "foo.h"
1 lines, 1 significant

==== #include <foo.h> // comment

=== <stdin> ===

    1 #include <foo.h> // comment
1 lines, 1 significant

==== #define X 3  // comment
   int g();

=== <stdin> ===

    1 #define X 3  // comment
    2    int g();
2 lines, 2 significant

==== // hello
   #include <stdio.h>
   #define SUM(x, y) \
      (x) + \
      (y)      // comment
   void f();

=== <stdin> ===

    1 // hello
    2    #include <stdio.h>
    3    #define SUM(x, y) \
    4       (x) + \
    5       (y)      // comment
    6    void f();
6 lines, 5 significant

==== #undef x

=== <stdin> ===

    1 #undef x
1 lines, 1 significant

==== #define F(x) x##name

=== <stdin> ===

    1 #define F(x) x##name
1 lines, 1 significant

==== char* s = f(R"(one
  two
  three)");
  

=== <stdin> ===

    1 char* s = f(R"(one
    2   two
    3   three)");
    4   
4 lines, 2 significant

==== char* s = f(R"zzXX(hi
  world
  )zzX"  (not the end)
  )zzXX");
  

=== <stdin> ===

    1 char* s = f(R"zzXX(hi
    2   world
    3   )zzX"  (not the end)
    4   )zzXX");
    5   
5 lines, 2 significant

==== char* unclosed = f(R"zzXX(hi
  world
  )oops");
  

=== <stdin> ===

    1 char* unclosed = f(R"zzXX(hi
    2   world
    3   )oops");
    4   
4 lines, 1 significant

==== abc

=== <stdin> ===

    1 abc
1 lines, 1 significant

==== ""

=== <stdin> ===

    1 ""
1 lines, 0 significant

==== "dq \" backslash \\"

=== <stdin> ===

    1 "dq \" backslash \\"
1 lines, 0 significant

==== "missing 

=== <stdin> ===

    1 "missing 
1 lines, 1 significant

==== 'sq \' backslash \\'

=== <stdin> ===

    1 'sq \' backslash \\'
1 lines, 0 significant

==== "line\n"

=== <stdin> ===

    1 "line\n"
1 lines, 0 significant

==== "quote \" backslash \\ "

=== <stdin> ===

    1 "quote \" backslash \\ "
1 lines, 0 significant

==== "\n"

=== <stdin> ===

    1 "\n"
1 lines, 0 significant

==== hi # comment

=== <stdin> ===

    1 hi # comment
1 lines, 1 significant

==== "hi"  # comment

=== <stdin> ===

    1 "hi"  # comment
1 lines, 0 significant

==== (r"raw dq")

=== <stdin> ===

    1 (r"raw dq")
1 lines, 1 significant

==== (r'raw \' sq')

=== <stdin> ===

    1 (r'raw \' sq')
1 lines, 1 significant

====  "L1"  # first
  L2 # second

=== <stdin> ===

    1  "L1"  # first
    2   L2 # second
2 lines, 1 significant

====  def f():
    """docstring
    with "quote"
    """
    pass

=== <stdin> ===

    1  def f():
    2     """docstring
    3     with "quote"
    4     """
    5     pass
5 lines, 2 significant

====  def f():
    '''docstring
    with 'quote'
    '''
    pass

=== <stdin> ===

    1  def f():
    2     '''docstring
    3     with 'quote'
    4     '''
    5     pass
5 lines, 2 significant

====  print(r'''hello''')

=== <stdin> ===

    1  print(r'''hello''')
1 lines, 1 significant

====  print(r"""hi there""")

=== <stdin> ===

    1  print(r"""hi there""")
1 lines, 1 significant

==== "hi"  # comment

=== <stdin> ===

    1 "hi"  # comment
1 lines, 0 significant

==== f() # hello

=== <stdin> ===

    1 f() # hello
1 lines, 1 significant

==== x = f("1
  2 \"quote\"
  3")

=== <stdin> ===

    1 x = f("1
    2   2 \"quote\"
    3   3")
3 lines, 2 significant

==== x = f('1
  2
  3')

=== <stdin> ===

    1 x = f('1
    2   2
    3   3')
3 lines, 2 significant

==== No language

=== <stdin> ===

    1 #!/usr/bin/env bash
    2 #
    3 # Lexing / Parsing experiment
    4 #
    5 # Usage:
    6 #   doctools/micro-syntax.sh <function name>
    7 
    8 # TODO:
    9 # - Rename to micro-syntax, from micro-grammars and uchex?
   10 #   - micro-segmenting and lexing - comments, strings, and maybe { }
10 lines, 9 significant

/dev/null

=== <stdin> ===

0 lines, 0 significant