Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SingleLineComment support to object #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,17 @@ public void TestStringLiteralSuccess(string index, string expected)
result.ToString().Should().Be(expected);
}

[TestCase("object({name = \"string\", age = \"number\"})")]
[TestCase("object({name = \"string\", age = object({name = \"string\", age = \"number\"})})")]
[TestCase("object({name = \"string\", age = \"number\"})", -1)]
[TestCase("object({name = \"string\", age = object({name = \"string\", age = \"number\"})})", -1)]
[TestCase("object({\n name = \"string\"\n # this is a name\n age = \"number\"\n # this is the age\n})", 0)]
[TestCase(
"object({name = \"string\", age = object({name = \"string\", age = \"number\"}), address = tuple([\"string\", object({name = \"string\", age = \"number\"})])})")]
public void ObjectTypeTest(string index)
"object({name = \"string\", age = object({name = \"string\", age = \"number\"}), address = tuple([\"string\", object({name = \"string\", age = \"number\"})])})",
-1
)]
public void ObjectTypeTest(string index, int indent)
{
var result = HclParser.ObjectTypeProperty.Parse(index);
result.ToString(-1).Should().Be(index);
result.ToString(indent).Should().Be(index);
}

[TestCase("tuple([\"string\", \"number\"])")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public void ParseHereDoc()
{
var template = TerraformLoadTemplate("multilinestring.txt");
var parsed = HclParser.HereDoc.Parse(template);
parsed.Item3.Should().Match("\nHello\nWorld\n");
parsed.Item3.Should().Match("\nHello\nWorld\nTHEPARSERSHOULDNOTMATCHTHIS DESCRIPTION\nHello\nAgain\n");
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<<DESCRIPTION
Hello
World
THEPARSERSHOULDNOTMATCHTHIS DESCRIPTION
Hello
Again
DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,18 @@ from last in Parse.String("*/")
from indentMarker in Parse.Char('-').Optional()
from marker in Parse.AnyChar.Except(Parse.Char(LineBreak)).Many().Text()
from lineBreak in Parse.Char(LineBreak)
from rest in Parse.AnyChar.Except(Parse.String(marker))
.Or(Parse.Char(LineBreak))
.Many().Text()
from last in Parse.String(marker)
select Tuple.Create(marker, indentMarker.IsDefined, lineBreak + rest)).Token();
from rest in Parse.AnyChar.Except(
Parse.Contained(
Parse.String(marker),
Parse.Concat(
Parse.LineEnd,
Parse.WhiteSpace.Many()
).Or(Parse.LineEnd),
Parse.WhiteSpace.Until(Parse.LineTerminator)
)
).Many().Text()
from whitespace in Parse.WhiteSpace.Until(Parse.String(marker)).Text()
select Tuple.Create(marker, indentMarker.IsDefined, $"{lineBreak}{rest}{whitespace}")).Token();

/// <summary>
/// Represents the "//" used to start a comment
Expand Down Expand Up @@ -575,6 +582,7 @@ from content in
(
from value in ElementTypedObjectProperty
.Or(PrimitiveTypeObjectProperty)
.Or(SingleLineComment)
from comma in Comma.Optional()
select value
).Token().Many()
Expand Down