From 100157d1a83ccb02d82af21c5767ecda3d7cb1c2 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 16 Mar 2015 22:47:28 -0700 Subject: 939 - c++: fix an old parsing hack --- cpp/011load | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'cpp/011load') diff --git a/cpp/011load b/cpp/011load index 9806bfd0..d01c72d2 100644 --- a/cpp/011load +++ b/cpp/011load @@ -109,6 +109,8 @@ string next_word(istream& in) { ostringstream out; skip_whitespace(in); slurp_word(in, out); + skip_whitespace(in); + skip_comment(in); return out.str(); } @@ -144,12 +146,68 @@ void skip_comments_and_newlines(istream& in) { } } +void skip_comment(istream& in) { + if (in.peek() == '#') { + in.get(); + while (in.peek() != '\n') in.get(); + } +} + void skip_comma(istream& in) { skip_whitespace(in); if (in.peek() == ',') in.get(); skip_whitespace(in); } +:(scenario parse_comment_outside_recipe) +# comment +recipe main [ + 1:integer <- copy 23:literal +] ++parse: instruction: 1 ++parse: ingredient: {name: "23", type: 0} ++parse: product: {name: "1", type: 1} + +:(scenario parse_comment_amongst_instruction) +recipe main [ + # comment + 1:integer <- copy 23:literal +] ++parse: instruction: 1 ++parse: ingredient: {name: "23", type: 0} ++parse: product: {name: "1", type: 1} + +:(scenario parse_comment_amongst_instruction2) +recipe main [ + # comment + 1:integer <- copy 23:literal + # comment +] ++parse: instruction: 1 ++parse: ingredient: {name: "23", type: 0} ++parse: product: {name: "1", type: 1} + +:(scenario parse_comment_amongst_instruction3) +recipe main [ + 1:integer <- copy 23:literal + # comment + 2:integer <- copy 23:literal +] ++parse: instruction: 1 ++parse: ingredient: {name: "23", type: 0} ++parse: product: {name: "1", type: 1} ++parse: instruction: 1 ++parse: ingredient: {name: "23", type: 0} ++parse: product: {name: "2", type: 1} + +:(scenario parse_comment_after_instruction) +recipe main [ + 1:integer <- copy 23:literal # comment +] ++parse: instruction: 1 ++parse: ingredient: {name: "23", type: 0} ++parse: product: {name: "1", type: 1} + :(scenario parse_label) recipe main [ +foo -- cgit 1.4.1-2-gfad0 /tr>
path: root/themes/forest
blob: f5bbbafdf8c78a1a2e74a11cadb216b8c39377f7 (plain) (blame)
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