aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/control/parser/code.lux
blob: 0840fd16d64810b87c3551744e2685d7156e567f (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
(.require
 [library
  [lux (.except nat int rev local not symbol)
   ["$" documentation (.only documentation:)]
   [data
    [text (.only \n)
     ["%" \\format (.only format)]]]
   [macro
    ["[0]" template]]]]
 [\\library
  ["[0]" /]])

(documentation: (/.Parser it)
  "A Lux code parser.")

(documentation: /.any
  "Yields the next input without applying any logic.")

(with_template [<query> <check>]
  [(`` (documentation: <query>
         (format "Parses the next " (,, (template.text [<query>])) " input.")))
   (`` (documentation: <check>
         (format "Checks for a specific " (,, (template.text [<query>])) " input.")))]

  [/.bit    /.this_bit]
  [/.nat    /.this_nat]
  [/.int    /.this_int]
  [/.rev    /.this_rev]
  [/.frac   /.this_frac]
  [/.text   /.this_text]
  [/.symbol /.this_symbol]
  )

(documentation: /.this
  "Ensures the given Code is the next input."
  [(this code)])

(with_template [<query> <check> <desc>]
  [(documentation: <query>
     (format "Parse a local " <desc> " (a " <desc> " that has no module prefix)."))
   (documentation: <check>
     (format "Checks for a specific local " <desc> " (a " <desc> " that has no module prefix)."))]

  [/.local /.this_local "local symbol"]
  )

(with_template [<name>]
  [(`` (documentation: <name>
         (format "Parses the contents of a " (,, (template.text [<name>])) ".")))]

  [/.form]
  [/.variant]
  [/.tuple]
  )

(documentation: /.end
  "Verifies there are no more inputs.")

(documentation: /.end?
  "Checks whether there are no more inputs.")

(documentation: /.result
  "Executes a parser against a stream of code, and verifies all the inputs are consumed."
  [(result parser inputs)])

(documentation: /.locally
  "Runs parser against the given list of inputs."
  [(locally inputs parser)])

(documentation: /.not
  "Yields the next Code token if the parser fails."
  [(not expected_to_fail)])

(documentation: /.next
  "Yields the next Code token without consuming it from the input stream.")

(.def .public documentation
  (.List $.Module)
  ($.module /._
            ""
            [..Parser
             ..any

             ..bit
             ..this_bit
             ..nat
             ..this_nat
             ..int
             ..this_int
             ..rev
             ..this_rev
             ..frac
             ..this_frac
             ..text
             ..this_text
             ..symbol
             ..this_symbol
             
             ..this

             ..local
             ..this_local
             
             ..form
             ..tuple
             
             ..variant
             ..end
             ..end?
             ..result
             ..locally
             ..not
             ..next]
            []))