Skip to content

Commit

Permalink
fix: cedarschema parsing bug
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Hakanson <kevhak@amazon.com>
  • Loading branch information
hakanson committed Apr 22, 2024
1 parent 7d49063 commit 77e80b6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## v0.7.3 (Pre-release) 2024-04-19
## v0.7.3 (Pre-release) 2024-04-21

- IntelliSense and validation using human-readable schema

Expand Down
20 changes: 19 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,11 @@ const parseCedarSchemaNaturalDoc = (
});
actionIds.push({
name: trimmed,
range: makeRange(line, offset + quotePosition, trimmed.length - 1),
range: makeRange(
line,
offset + quotePosition,
trimmed.length - quotePosition
),
});
} else {
const range = makeRange(line, offset, item.length);
Expand Down Expand Up @@ -1481,6 +1485,20 @@ const parseCedarSchemaNaturalDoc = (
}
}
});
} else {
const inIndex = linePreComment.indexOf(' in ');
if (inIndex > -1) {
const match = linePreComment.match(
/ in\s+(([_a-zA-Z][_a-zA-Z0-9]*::)*[_a-zA-Z][_a-zA-Z0-9]*)/
);
if (match) {
parseCedarSchemaEntityItem(
match[1],
i,
textLine.indexOf(match[1], textLine.indexOf(' in '))
);
}
}
}
const colonIndex = textLine.indexOf(':');
if (declarationStartLine !== -1 && colonIndex > -1) {
Expand Down
26 changes: 21 additions & 5 deletions syntaxes/cedarschema.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
{
"include": "#comment"
},
{
"include": "#namespace"
},
{
"include": "#keywords"
},
{
"include": "#sections"
},
{
"include": "#constants"
"include": "#properties"
},
{
"include": "#strings"
Expand All @@ -23,10 +26,23 @@
"name": "comment.line.double-slash.cedarschema",
"match": "//.*(?=$)"
},
"namespace": {
"patterns": [{
"match": "\\b(namespace)\\s+([_a-zA-Z][_a-zA-Z0-9]*)",
"captures": {
"1" : {
"name": "keyword.cedarschema"
},
"2" : {
"name": "entity.name.namespace.cedarschema"
}
}
}]
},
"sections": {
"patterns": [{
"name": "keyword.cedarschema",
"match": "^\\s*(namespace|type|entity|action)\\b"
"match": "^\\s*(type|entity|action)(?=\\s+)"
}]
},
"keywords": {
Expand All @@ -35,12 +51,12 @@
"match": "\\b(in|appliesTo)\\b"
}]
},
"constants": {
"properties": {
"patterns": [{
"match": "\\b(principal|resource|context):",
"match": "\\b([_a-zA-Z][_a-zA-Z0-9]*)(?=[?]?:(?!:))",
"captures": {
"1" : {
"name": "variable.other.constant.cedarschema"
"name": "variable.other.property.cedarschema"
}
}
}]
Expand Down

0 comments on commit 77e80b6

Please sign in to comment.