Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

New cool construction syntax.

  • Loading branch information...
commit a0d9f25d3ed833f3feebb198675d44f7c072660a 1 parent 364171c
Friedrich Weber authored

Showing 2 changed files with 27 additions and 22 deletions. Show diff stats Hide diff stats

  1. +21 19 optparse/Option.ooc
  2. +6 3 test.ooc
40 optparse/Option.ooc
@@ -5,16 +5,19 @@ import optparse/Parser
5 5 Option: abstract class {
6 6 key: String
7 7
  8 + init: func (=key) {}
  9 +
8 10 storeValue: func <T> (parser: Parser, value: T) {
9 11 parser values put(key, value)
10 12 }
11   -
  13 +
12 14 storeDefault: abstract func (parser: Parser)
13 15 activate: abstract func (parser: Parser, reader: CommandLineReader) -> Bool
14 16 }
15 17
16 18 SimpleOption: abstract class extends Option {
17   - longName, shortName: String
  19 + longName := ""
  20 + shortName := ""
18 21
19 22 activate: func (parser: Parser, reader: CommandLineReader) -> Bool {
20 23 token := reader peek()
@@ -29,19 +32,17 @@ SimpleOption: abstract class extends Option {
29 32 return false
30 33 }
31 34
  35 + longName: func (=longName) {}
  36 + shortName: func (=shortName) {}
  37 +
32 38 activate2: abstract func (parser: Parser, reader: CommandLineReader)
33 39 }
34 40
35 41 ToggleOption: class extends SimpleOption {
36   - store, defaultValue: Bool
  42 + store := true
  43 + defaultValue := false
37 44
38   - init: func ~verbose (=key, =longName, =shortName, =store, =defaultValue) {
39   -
40   - }
41   -
42   - init: func ~storeTrue (=key, =longName, =shortName, =defaultValue) {
43   - store = true
44   - }
  45 + init: func ~doggl (=key) {}
45 46
46 47 activate2: func (parser: Parser, reader: CommandLineReader) {
47 48 storeValue(parser, store)
@@ -50,15 +51,16 @@ ToggleOption: class extends SimpleOption {
50 51 storeDefault: func (parser: Parser) {
51 52 storeValue(parser, defaultValue)
52 53 }
  54 +
  55 + store: func (=store) {}
  56 + defaultValue: func (=defaultValue) {}
53 57 }
54 58
55 59 StringOption: class extends SimpleOption {
56   - defaultValue: String
  60 + defaultValue := ""
  61 +
  62 + init: func ~s (=key) {}
57 63
58   - init: func (=key, =longName, =shortName, =defaultValue) {
59   -
60   - }
61   -
62 64 activate2: func (parser: Parser, reader: CommandLineReader) {
63 65 storeValue(parser, reader get())
64 66 }
@@ -66,13 +68,13 @@ StringOption: class extends SimpleOption {
66 68 storeDefault: func (parser: Parser) {
67 69 storeValue(parser, defaultValue)
68 70 }
  71 +
  72 + defaultValue: func (=defaultValue) {}
69 73 }
70 74
71 75 ListOption: class extends SimpleOption {
72   - init: func (=key, =longName, =shortName) {
73   -
74   - }
75   -
  76 + init: func ~ichLiebeWurstsalat (=key) {}
  77 +
76 78 activate2: func (parser: Parser, reader: CommandLineReader) {
77 79 parser values get(key, ArrayList<String>) add(reader get())
78 80 }
9 test.ooc
@@ -11,9 +11,12 @@ test: func (parser: Parser, args: ArrayList<String>) {
11 11
12 12 main: func (args: Array<String>) {
13 13 parser := Parser new()
14   - parser addOption(ToggleOption new("quiet", "quiet", "q", false))
15   - parser addOption(StringOption new("name", "name", "n", "Bla-Bli-Blubb"))
16   - parser addOption(ListOption new("libs", "lib", "l"))
  14 +
  15 + quiet := ToggleOption new("quiet") .longName("quiet") .shortName("q")
  16 + name := StringOption new("name") .longName("name") .shortName("n")
  17 + libs := ListOption new("libs") .longName("lib") .shortName("l")
  18 +
  19 + parser addOption(quiet) .addOption(name) .addOption(libs)
17 20
18 21 test(parser, args toArrayList())
19 22 }

0 comments on commit a0d9f25

Please sign in to comment.
Something went wrong with that request. Please try again.