File: help_parse.treetop

package info (click to toggle)
jellyfish 2.3.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,276 kB
  • sloc: cpp: 35,703; sh: 995; ruby: 578; makefile: 397; python: 165; perl: 36
file content (52 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
grammar HelpGrammar
  rule line
    spaces sws:switches* text [\n]* {
      def to_tex(opened)
        res = ""
        unless sws.empty?
          if !opened.is_open
            res << "\\begin{description}\n"
            opened.is_open = true
          end
          res << "\\item["
          res << sws.elements.map { |s| s.to_tex }.join(",")
          res << "] "
        end
        res << "\\noindent " unless text.text_value.empty?
        res << quote(text.text_value)
      end
    }
  end

  rule spaces
    [\s]*
  end

  rule switches
    "-" sw:( short_switch / long_switch ) {
      def to_tex
        sw.to_tex
      end
    }
  end

  rule short_switch
    name:[a-zA-Z] ","? spaces {
      def to_tex
        "\\Opt{-#{name.text_value}}"
      end
    }
  end

  rule long_switch
    "-" name:[^,\s=]+ val:("=" [^,\s]+)? ","? spaces {
      def to_tex
        val.empty? ? "\\LOpt{#{quote(name.text_value)}}" : "\\LOptArg{#{quote(name.text_value)}}{#{quote(val.text_value)}}"
      end
    }
  end

  rule text
    [^\n]*
  end
end