| 1 |
grammar HelpGrammar |
| 2 |
rule line |
| 3 |
spaces sws:switches* text [\n]* { |
| 4 |
def to_tex(opened) |
| 5 |
res = "" |
| 6 |
unless sws.empty? |
| 7 |
if !opened.is_open |
| 8 |
res << "\\begin{description}\n" |
| 9 |
opened.is_open = true |
| 10 |
end |
| 11 |
res << "\\item[" |
| 12 |
res << sws.elements.map { |s| s.to_tex }.join(",") |
| 13 |
res << "] " |
| 14 |
end |
| 15 |
res << "\\noindent " unless text.text_value.empty? |
| 16 |
res << quote(text.text_value) |
| 17 |
end |
| 18 |
} |
| 19 |
end |
| 20 |
|
| 21 |
rule spaces |
| 22 |
[\s]* |
| 23 |
end |
| 24 |
|
| 25 |
rule switches |
| 26 |
"-" sw:( short_switch / long_switch ) { |
| 27 |
def to_tex |
| 28 |
sw.to_tex |
| 29 |
end |
| 30 |
} |
| 31 |
end |
| 32 |
|
| 33 |
rule short_switch |
| 34 |
name:[a-zA-Z] ","? spaces { |
| 35 |
def to_tex |
| 36 |
"\\Opt{-#{name.text_value}}" |
| 37 |
end |
| 38 |
} |
| 39 |
end |
| 40 |
|
| 41 |
rule long_switch |
| 42 |
"-" name:[^,\s=]+ val:("=" [^,\s]+)? ","? spaces { |
| 43 |
def to_tex |
| 44 |
val.empty? ? "\\LOpt{#{quote(name.text_value)}}" : "\\LOptArg{#{quote(name.text_value)}}{#{quote(val.text_value)}}" |
| 45 |
end |
| 46 |
} |
| 47 |
end |
| 48 |
|
| 49 |
rule text |
| 50 |
[^\n]* |
| 51 |
end |
| 52 |
end |