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

Trace Reconstruction #2

Merged
Show file tree
Hide file tree
Changes from 80 commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
ab9c4b6
comment out old trace reconstruction code
mmcloughlin Jun 12, 2024
11938f0
wip
RoryBrennan-Jones Jun 14, 2024
005b519
implemented wip solutions for reconstruct and build_trace_tree
RoryBrennan-Jones Jul 2, 2024
efbef7c
implemented different fix for build_trace_reconstruction that involve…
RoryBrennan-Jones Jul 2, 2024
11e73be
included additional comments and a new test case
RoryBrennan-Jones Jul 3, 2024
f3be6d8
implemented exit-only trace building technique
RoryBrennan-Jones Jul 10, 2024
f4efe32
Convinced Dafny that |trace| was being decreased in build_trace_tree2…
RoryBrennan-Jones Jul 11, 2024
7afbec6
Convinced Dafny that the trace is required to be concrete
RoryBrennan-Jones Jul 12, 2024
ebbfd64
Convinced Dafny that the returned trace tree is wf
RoryBrennan-Jones Jul 12, 2024
2986a42
Performed code surgery on build_trace_tree2 to get build_trace_tree3,…
RoryBrennan-Jones Jul 12, 2024
a453727
Created build_proof_tree and slightly enhanced trace.pl
RoryBrennan-Jones Jul 12, 2024
189b11d
Removed match from build_proof_tree, as it was created to allow recon…
RoryBrennan-Jones Jul 12, 2024
64843d4
There was a mk_thm that used head.i instead of ri, so I fixed that
RoryBrennan-Jones Jul 12, 2024
13feca4
Added an ensures and an invariant, and removed two assumes
RoryBrennan-Jones Jul 12, 2024
de7f272
Removed unnecessary comments
RoryBrennan-Jones Jul 12, 2024
2f27b15
Changed comments in def.dfy
RoryBrennan-Jones Jul 16, 2024
c01aa06
Added parser support for predicates without arguments
RoryBrennan-Jones Jul 16, 2024
f026007
Experimented with makefile and trace.pl in preparation for test suite
RoryBrennan-Jones Jul 16, 2024
2ea9437
Added test suite
RoryBrennan-Jones Jul 16, 2024
d560d23
Created new test case
RoryBrennan-Jones Jul 22, 2024
bf14157
Created limited, experimental parser support for numbers
RoryBrennan-Jones Jul 23, 2024
925c59d
Added parser rule for constants
RoryBrennan-Jones Jul 23, 2024
329465c
Began adding support for strings, but encountered issue where strings…
RoryBrennan-Jones Jul 23, 2024
17834a0
Strings are now supported
RoryBrennan-Jones Jul 23, 2024
ef7b2d9
Added new test
RoryBrennan-Jones Jul 23, 2024
be6a50b
Implemented support for builtin operations involving numbers, and mad…
RoryBrennan-Jones Jul 23, 2024
6978483
Moved around code in a way that did not effect functionality
RoryBrennan-Jones Jul 23, 2024
908a9a8
Made small change
RoryBrennan-Jones Jul 23, 2024
8ad939a
Added support for two more operators
RoryBrennan-Jones Jul 23, 2024
a2443b1
Made minor change
RoryBrennan-Jones Jul 23, 2024
0acdf0a
Another minor change
RoryBrennan-Jones Jul 23, 2024
187b552
Fixed issue
RoryBrennan-Jones Jul 23, 2024
77ef808
Replaced incorrect inequality operator with correct one
RoryBrennan-Jones Jul 23, 2024
024ba64
Changed disequality symbol back to previous one
RoryBrennan-Jones Jul 23, 2024
78ad347
Added parser support for atoms and variables with non-leading undersc…
RoryBrennan-Jones Jul 24, 2024
ac4adb3
Changed comments.
RoryBrennan-Jones Jul 24, 2024
cb98432
Fixed verification issue with unify, and deleted some files from Git
RoryBrennan-Jones Jul 24, 2024
995cfd3
Clause now uses sub rules
RoryBrennan-Jones Jul 24, 2024
d66cc9f
Added parser support for lists
RoryBrennan-Jones Jul 24, 2024
0960332
Basic lists example
RoryBrennan-Jones Jul 24, 2024
d3d7f40
Added parser support for length builtin and an example of its use
RoryBrennan-Jones Jul 24, 2024
2e73b75
Added support for split string builtin
RoryBrennan-Jones Jul 24, 2024
58a3a05
Added support for member builtin
RoryBrennan-Jones Jul 25, 2024
01b6535
Added support for reverse builtin
RoryBrennan-Jones Jul 25, 2024
b930eec
Added support for nth1 builtin
RoryBrennan-Jones Jul 25, 2024
b551486
Added support for string_chars builtin
RoryBrennan-Jones Jul 25, 2024
a625ecb
Added support for string_lower builtin
RoryBrennan-Jones Jul 25, 2024
48e52ce
Added support for < and > operators and made a few minor changes
RoryBrennan-Jones Jul 26, 2024
b8c27fb
Fixed previously unknown issue with the trace reconstruction algorith…
RoryBrennan-Jones Jul 26, 2024
5743440
Removed choice from trace event since it was no longer used
RoryBrennan-Jones Jul 26, 2024
68fd13b
Updated git ignore to ignore test outputs
RoryBrennan-Jones Jul 29, 2024
1aae322
Fixed string split example
RoryBrennan-Jones Jul 29, 2024
1ee3c05
Added todo comment
RoryBrennan-Jones Jul 29, 2024
4d71937
Deleted large block of commented code
RoryBrennan-Jones Jul 29, 2024
b405617
Deleted large block of commented code for reconstruct
RoryBrennan-Jones Jul 29, 2024
8db3222
Added final newlines to the test files that lacked them
RoryBrennan-Jones Jul 29, 2024
1efab9d
Deleted large block of commented code for incomplete experiment
RoryBrennan-Jones Jul 29, 2024
bea05c8
Uncommented test code in def.dfy
RoryBrennan-Jones Jul 29, 2024
4e3790b
Deleted commented code at end of def.dfy
RoryBrennan-Jones Jul 29, 2024
72591ea
Cleaned up the run method
RoryBrennan-Jones Jul 29, 2024
4fab32f
Deleted build_trace_tree2
RoryBrennan-Jones Jul 29, 2024
f9ded11
Added trailing newline to def.dfy
RoryBrennan-Jones Jul 29, 2024
6225f62
Removed match datatype
RoryBrennan-Jones Jul 29, 2024
8b10a44
Deleted trace tree code
RoryBrennan-Jones Jul 29, 2024
1de85ce
Added two more test cases
RoryBrennan-Jones Jul 29, 2024
8ae39b6
The method build_proof_tree now prints out the tree it is processing
RoryBrennan-Jones Jul 30, 2024
39eb100
Changed comments in datalog.g4
RoryBrennan-Jones Jul 30, 2024
255a7f7
Changed comment in AstBuilder.cs
RoryBrennan-Jones Jul 30, 2024
894bec8
Added random connectivity example generator script to repository
RoryBrennan-Jones Jul 30, 2024
0d812c3
Added comments to trace reconstruction code
RoryBrennan-Jones Jul 30, 2024
f757995
Created readme file
RoryBrennan-Jones Jul 30, 2024
425ec6d
Created readme file
RoryBrennan-Jones Jul 30, 2024
124de22
Changed readme file
RoryBrennan-Jones Jul 31, 2024
f5d733e
Added another print to def.dfy
RoryBrennan-Jones Jul 31, 2024
6f16433
Added support for the actual backslash character in strings (note: es…
RoryBrennan-Jones Jul 31, 2024
669ce54
Added support for double quotes in strings
RoryBrennan-Jones Jul 31, 2024
7fbdb36
Added support for more escaped characters in strings
RoryBrennan-Jones Jul 31, 2024
86a1be7
Added support for more ASCII characters in strings
RoryBrennan-Jones Jul 31, 2024
e892cc1
Changed README.md
RoryBrennan-Jones Jul 31, 2024
52b96fb
Changed README.md
RoryBrennan-Jones Jul 31, 2024
b5e93fc
Added final newlines
RoryBrennan-Jones Aug 1, 2024
822249f
Reformatted README
RoryBrennan-Jones Aug 1, 2024
28ab87e
Removed heading in README
RoryBrennan-Jones Aug 1, 2024
43a92a7
Minor changes to Python script
RoryBrennan-Jones Aug 1, 2024
2705f6b
Addressed issue with escaping
RoryBrennan-Jones Aug 1, 2024
eac52a9
Actually fixed issue with escaping
RoryBrennan-Jones Aug 1, 2024
323233e
Cleaned up VisitString
RoryBrennan-Jones Aug 1, 2024
19359d4
Cleaned up VisitBuiltin and VisitExpression
RoryBrennan-Jones Aug 1, 2024
0a10520
Disabled support for escaped double quotes because of resulting bugs
RoryBrennan-Jones Aug 1, 2024
7a7f372
Cleaned up VisitBuiltin
RoryBrennan-Jones Aug 1, 2024
47d0914
Added back the removed space
RoryBrennan-Jones Aug 1, 2024
adfc803
Cleaned up switch statement
RoryBrennan-Jones Aug 1, 2024
8d61cc6
Updated Python script to use main method
RoryBrennan-Jones Aug 1, 2024
4ac2338
Cleaned up lower_char
RoryBrennan-Jones Aug 1, 2024
e9ac6c5
Made use of padchars in split string illegal for now
RoryBrennan-Jones Aug 1, 2024
b3b635b
Expanded README
RoryBrennan-Jones Aug 1, 2024
04b3a71
Added missing final newline
RoryBrennan-Jones Aug 1, 2024
7dd1cb0
Updated readme
RoryBrennan-Jones Aug 2, 2024
8b3d786
Updated readme
RoryBrennan-Jones Aug 2, 2024
ae4da38
Fixed naming issue involving natural numbers
RoryBrennan-Jones Aug 2, 2024
55c5b56
Changed readme
RoryBrennan-Jones Aug 2, 2024
abc81b5
Removed comment
RoryBrennan-Jones Aug 2, 2024
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
4 changes: 4 additions & 0 deletions dafny/lcf/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Compiled C# code
*.dll
# Test outputs
*.trace
*.thm
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please could we fix the missing newlines at the end of files? I think there's a few examples of it in this PR.

I think there's a vscode setting for this: https://stackoverflow.com/a/44704969

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

32 changes: 25 additions & 7 deletions dafny/lcf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,33 @@ def.cs: def.dfy
bin/datalog.dll: datalog/datalog.csproj out/datalogParser.cs def.cs datalog/AstBuilder.cs datalog/Program.cs
dotnet build datalog/datalog.csproj --output bin

examples/trace.out: examples/trace.pl
swipl -l $< > $@
tests/%.trace: trace.pl tests/%.pl
swipl -l $< -g "consult('tests/$*.pl')" -g trace -g "go" -g notrace -g halt > $@

.PHONY: check
check: bin/datalog.dll examples/connectivity.pl examples/trace.out
dotnet $^
tests/%.thm: bin/datalog.dll tests/%.pl tests/%.trace
dotnet $^ > $@

TESTS=$(wildcard tests/*.pl)
THMS=$(patsubst %.pl,%.thm,$(TESTS))

.PHONY: test
test: $(THMS)

.PHONY: print
print(%):
cat '$*'

.PHONY: printtests
printtests:
cat ${TESTS}

.PHONY: printthms
printthms:
cat ${THMS}

.PHONY: clean
clean:
$(RM) -r out
$(RM) examples/*.out
$(RM) def.cs
$(RM) tests/*.trace
$(RM) tests/*.thm
$(RM) def.cs
20 changes: 20 additions & 0 deletions dafny/lcf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Project Overview

The Veri-Datalog project is a verified Datalog+ engine. It proves the correctness of Datalog+ programs by constructing proof trees from their trace output. Datalog+ is a research defined language that is similar to Datalog but with more feature support; both are subsets of Prolog.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: wrap paragraphs to some reasonable width, 100 or 120 characters perhaps?


## Contributions by Rory Brennan-Jones
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps remove this heading? We know it was your work, but I don't think the README needs to say that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


### Test Suite

In the lcf directory, running `make test` will verify the go predicate of every Datalog+ file in the tests directory. The results are saved as .thm files with names matching the original code files. Using the Python script in the tools directory, it is possible to randomly generate example Datalog+ programs involving edge connectivity problems.

### Trace Reconstruction

The trace output of a Prolog program shows an exploration of many possible paths before settling on one that allows the query to be true
or resolves some unification. The new trace reconstruction algorithm attempts to discard all the failed paths and look at just the successful path, which greatly simplifies the process of constructing a proof tree for that query. The algorithm does this by only looking at trace events that use the exit port, since these events result from successes and contain full variable assignments. However, failed paths can have zero or more temporary successes, potentially leading to the presence of "junk" events with exit ports in the trace output.

Since exit ports always follow successes, the first exit ports in the trace happen after finding succesful base cases (builtin operations, facts, etc.), and later exit ports show the successes of predicates that depended on other rules and facts. As a result, the algorithm reads from the trace backwards in order to go from the root to the leaves instead of vice versa. The algorithm uses a mix of recursion and iteration, where the recursion helps the algorithm move "up" and "down" the tree, and the iteration helps algorithm move between siblings in the tree and skip junk events. A trace event with a prop such as a fact, equality, or builtin becomes a leaf in the proof tree, whereas other trace events become regular theorems that have proofs using other theorems and leaves from lower down in the tree as arguments.

### Types and Builtins

Unlike Datalog, Datalog+ supports constants other than atoms, including numbers, strings, and lists. These types are not complete yet. It has not been decided yet if the numbers should be natural numbers or integers (or if both should be supported). Furthermore, strings do not support all characters that could be found in a legal Datalog+ string, including escaped characters such as double quotes. Also, lists currently only support constant terms and cannot use the pipe operator. In addition to these types, there is also support for certain builtin operations, such as equality operators and string and list builtins.
79 changes: 74 additions & 5 deletions dafny/lcf/datalog.g4
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trace
;

traceevent
: port level=integer id=integer goal=clause ';'
: port level=integer id=integer goal=clause';'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: keep the space after clause?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

;

port
Expand Down Expand Up @@ -37,26 +37,63 @@ rule
;

clause
: name=Identifier '(' term_list ')'
: builtin
| app
| expression
;

builtin
: name=Builtin '(' term_list ')'
;

app
: name=Identifier ( '(' term_list ')' )?
;

expression
: left=term name=Operator right=term
;

term
: atom
: constant
| variable
;

constant
: atom
| natural
| string
| list
;

clause_list
: clause ( ',' clause)*
;

term_list
: term( ',' term)*
: term ( ',' term)*
;

atom
: val=Identifier
;

natural
: numeral=Int // TODO: make natural use the Nat rule, or switch support from natural numbers to integers
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we can't do this TODO now?

It's odd to have a rule called natural actually be an integer. I'd suggest we either rename natural to integer, or change Int to Nat. Either is fine, just the mixed naming is odd right now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in person, this may have to stay unresolved for now. To summarize, the kernel only supports natural numbers right now, but the Nat lexer rule in the parser doesn't seem to work.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that the naming issue is worth resolving now, if we can.

Copy link
Author

@RoryBrennan-Jones RoryBrennan-Jones Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have resolved the naming issue. The Int lexer rule has been commented out, and the rest of the Antlr uses the Nat rule.

;

string
: s=Str
;

list
: '[' constant_list ']'
;

constant_list
: constant ( ',' constant)*
;

variable
: name=VarName
;
Expand All @@ -65,6 +102,15 @@ variable
* Lexer Rules
*/

fragment CHARACTER
: ALPHANUMERIC // TODO: expand to all characters that are permitted by Prolog strings
| '.' | ',' | ';' | '!' | '?' | ' '
| '\t' | '\\t'
| '\n' | '\\n'
| '\r' | '\\r'
| '"' | '\\"'
| '\\'
;
fragment ALPHANUMERIC: ALPHA | DIGIT ;
fragment ALPHA: '_' | SMALL_LETTER | CAPITAL_LETTER ;
fragment LEADER: '_' | CAPITAL_LETTER;
Expand All @@ -76,10 +122,25 @@ Port
: 'call' | 'redo' | 'unify' | 'exit' | 'fail'
;

Builtin
: 'split_string'
| 'sub_string'
| 'string_lower'
| 'string_chars'
| 'length'
| 'lists:member' | 'member'
| 'lists:reverse' | 'reverse'
| 'lists:nth1' | 'nth1'
Comment on lines +131 to +133
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do both forms appear? That is, do you see both lists:member and member in the trace?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the trace, I see "lists:member", but in the .pl file, I see "member".

;

Identifier
: SMALL_LETTER (Nondigit | Digit)*
;

Operator
: '=' | '=<' | '>=' | '\\=' | '=\\=' | '<' | '>' | '=='
;

VarName
: LEADER (Nondigit | Digit)*
;
Expand All @@ -88,8 +149,16 @@ Int
: ('-')? Digit+
;

Nat
: Digit+
;

Str
: '"' CHARACTER* '"'
;

fragment Nondigit
: [a-zA-Z]
: [a-zA-Z] | '_'
;

fragment Digit
Expand Down
87 changes: 84 additions & 3 deletions dafny/lcf/datalog/AstBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,88 @@ private static int RuleID(ParserRuleContext context) {
return context.Start.Line;
}

public override object VisitClause(datalogParser.ClauseContext context) {
var name = Sequence<char>.FromString(context.name.Text);
public override object VisitBuiltin(datalogParser.BuiltinContext context) {
var terms = (Dafny.ISequence<_ITerm>) VisitTerm_list(context.term_list());
return new _module.Prop_App(name, terms);
switch (context.name.Text) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these cases have the same form:

return new _module.Prop_BuiltinOp(new _module.Builtin_SplitString(), terms);

Can we refactor this to use function that returns the builtin type from the builtin name?

    switch (context.name.Text) {
        case "split_string":
          return new _module.Builtin_SplitString();
        case "sub_string":
          return new _module.Builtin_SubString();
        // ...

Then each case doesn't need to have the new _module.Prop_BuiltinOp(..., terms); repeated.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

case "split_string":
return new _module.Prop_BuiltinOp(new _module.Builtin_SplitString(), terms);
case "sub_string":
return new _module.Prop_BuiltinOp(new _module.Builtin_SubString(), terms);
case "string_lower":
return new _module.Prop_BuiltinOp(new _module.Builtin_StringLower(), terms);
case "string_chars":
return new _module.Prop_BuiltinOp(new _module.Builtin_StringChars(), terms);
case "length":
return new _module.Prop_BuiltinOp(new _module.Builtin_Length(), terms);
case "lists:member":
return new _module.Prop_BuiltinOp(new _module.Builtin_Member(), terms);
case "member":
return new _module.Prop_BuiltinOp(new _module.Builtin_Member(), terms);
case "lists:reverse":
return new _module.Prop_BuiltinOp(new _module.Builtin_Reverse(), terms);
case "reverse":
return new _module.Prop_BuiltinOp(new _module.Builtin_Reverse(), terms);
case "lists:nth1":
return new _module.Prop_BuiltinOp(new _module.Builtin_Nth1(), terms);
case "nth1":
return new _module.Prop_BuiltinOp(new _module.Builtin_Nth1(), terms);
default:
return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be best to have this throw an exception instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}
}

public override object VisitExpression(datalogParser.ExpressionContext context) {
var left = (_module.Term)VisitTerm(context.left);
var right = (_module.Term)VisitTerm(context.right);
var terms = new List<_module.Term> { left, right };
var terms2 = (Dafny.ISequence<_ITerm>) Sequence<_module.Term>.Create(terms.Count, i => terms[(int) i]);
switch(context.name.Text) {
case "=<":
return new _module.Prop_BuiltinOp(new _module.Builtin_NatLeq(), terms2);
case ">=":
return new _module.Prop_BuiltinOp(new _module.Builtin_NatGeq(), terms2);
case "\\=":
return new _module.Prop_BuiltinOp(new _module.Builtin_NatNeq(), terms2);
case "=\\=":
return new _module.Prop_BuiltinOp(new _module.Builtin_NatNeq(), terms2);
case "<":
return new _module.Prop_BuiltinOp(new _module.Builtin_NatLt(), terms2);
case ">":
return new _module.Prop_BuiltinOp(new _module.Builtin_NatGt(), terms2);
default:
return new _module.Prop_Eq(left, right);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to have an explicit case for equals.

The default case should error out.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}
}

public override object VisitApp(datalogParser.AppContext context) {
var name = Sequence<char>.FromString(context.name.Text);
if (context.term_list() == null ) {
var terms = new List<_module.Term>();
var terms2 = Sequence<_module.Term>.Create(terms.Count, i => terms[(int) i]);
return new _module.Prop_App(name, (Dafny.ISequence<_ITerm>) terms2);
} else {
var terms = (Dafny.ISequence<_ITerm>) VisitTerm_list(context.term_list());
return new _module.Prop_App(name, terms);
}
}

public override object VisitAtom(datalogParser.AtomContext context) {
return new Term_Const(new Const_Atom(Sequence<char>.FromString(context.val.Text)));
}

public override object VisitNatural(datalogParser.NaturalContext context) {
return new Term_Const(new Const_Nat(BigInteger.Parse(context.numeral.Text)));
}

public override object VisitString(datalogParser.StringContext context) {
return new Term_Const(new Const_Str(Sequence<char>.FromString(context.s.Text.Substring(1, context.s.Text.Length - 2))));
// A substring of the text is taken in order to remove the double quotes.
Copy link
Collaborator

@mmcloughlin mmcloughlin Aug 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you say you had supported escaping now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it to replace escaped characters with the actual characters. However, I discovered that adding support for escaped double quotes broke the parser, so I had to stop supporting them for now (although other escaped characters are now fully supported).

}

public override object VisitList(datalogParser.ListContext context) {
return new Term_Const(new Const_List( (Dafny.ISequence<_IConst>) VisitConstant_list(context.constant_list()) ));
}

public override object VisitVariable(datalogParser.VariableContext context) {
return new Term_Var(Sequence<char>.FromString(context.name.Text));
}
Expand All @@ -101,6 +173,15 @@ public override object VisitTerm_list(datalogParser.Term_listContext context) {
}
return Sequence<_module.Term>.Create(terms.Count, i => terms[(int) i]);
}

public override object VisitConstant_list(datalogParser.Constant_listContext context) {
var consts = new List<_module.Const>();
foreach (var constant in context.constant()) {
var dafny_const = (_module.Const) ((_module.Term_Const) VisitConstant(constant))._val;
consts.Add(dafny_const);
}
return Sequence<_module.Const>.Create(consts.Count, i => consts[(int) i]);
}
}

public partial class __default
Expand Down
2 changes: 2 additions & 0 deletions dafny/lcf/datalog/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ static void Main(string[] args) {
try {
// Parse rule set.
var rules_parser = BuildParser(args[0]);
rules_parser.ErrorHandler = new BailErrorStrategy();
var rules_parse_tree = rules_parser.program();
var rules_ast_builder = new AstBuilder();
var rules = (Sequence<_module.Rule>)rules_ast_builder.VisitProgram(rules_parse_tree);

// Parse trace.
var trace_parser = BuildParser(args[1]);
trace_parser.ErrorHandler = new BailErrorStrategy();
var trace_parse_tree = trace_parser.trace();
var trace_ast_builder = new AstBuilder();
var trace = (Sequence<_module.Event>)trace_ast_builder.VisitTrace(trace_parse_tree);
Expand Down
Loading