3 Commits
Author SHA1 Message Date
josh 2e82339300 add docs 2026-04-10 16:29:09 -04:00
josh 0e5b0b1f8a complete adding lex_fn 2026-04-10 16:03:45 -04:00
josh e2db9c95c5 wip 2026-04-09 22:49:21 -04:00
9 changed files with 24 additions and 50 deletions

No files matched your search

-12
View File
@@ -1,15 +1,3 @@
## v4.3.0
### New Features
- Use #line for user code blocks to report input grammar position for errors.
## v4.2.0
### New Features
- Add support for a custom lex function.
## v4.1.0
### New Features
+4 -4
View File
@@ -5,11 +5,11 @@ GEM
date (3.5.1)
diff-lcs (1.6.2)
docile (1.4.1)
erb (6.0.4)
erb (6.0.1)
psych (5.3.1)
date
stringio
rake (13.4.2)
rake (13.3.1)
rdoc (7.2.0)
erb
psych (>= 4.0.0)
@@ -24,7 +24,7 @@ GEM
rspec-expectations (3.13.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.8)
rspec-mocks (3.13.7)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.7)
@@ -51,4 +51,4 @@ DEPENDENCIES
syntax
BUNDLED WITH
4.0.11
2.3.7
+1 -1
View File
@@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2010-2026 Josh Holtrop
Copyright (c) 2010-2024 Josh Holtrop
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -33,7 +33,7 @@ class Propane
def run(input_file, output_file, log_file, options)
begin
grammar = Grammar.new(File.read(input_file), input_file)
grammar = Grammar.new(File.read(input_file))
generator = Generator.new(grammar, output_file, log_file, options)
generator.generate
rescue Error => e
+1 -7
View File
@@ -38,13 +38,7 @@ class Propane
output_file = @output_file
end
erb = ERB.new(template, trim_mode: "<>")
result = erb.result(binding.clone).lines.each_with_index.map do |line, i|
if line == "#linereset\n"
"#line #{i + 2}\n"
else
line
end
end.join
result = erb.result(binding.clone)
File.open(output_file, "wb") do |fh|
fh.write(result)
end
+6 -14
View File
@@ -22,8 +22,7 @@ class Propane
attr_reader :on_token_node
attr_reader :token_user_fields
def initialize(input, filename)
@filename = filename
def initialize(input)
@patterns = []
@start_rules = []
@tokens = []
@@ -305,12 +304,8 @@ class Propane
def parse_code_block_statement!
if md = consume!(/<<([a-z]*)(.*?)>>\n/m)
name, code = md[1..2]
code = code.chomp
if code.start_with?("\n")
code = %[#line #{@line_number + 1} "#{@filename}"#{code}\n#linereset\n]
else
code = %[#line #{@line_number} "#{@filename}"\n#{code}\n#linereset\n]
end
code.sub!(/\A\n/, "")
code += "\n" unless code.end_with?("\n")
if @code_blocks[name]
@code_blocks[name] += code
else
@@ -351,12 +346,9 @@ class Propane
def parse_code_block!
if md = consume!(/<<(.*?)>>\n/m)
code = md[1].chomp
if code.start_with?("\n")
code = %[#line #{@line_number + 1} "#{@filename}"#{code}\n#linereset\n]
else
code = %[#line #{@line_number} "#{@filename}"\n#{code}\n#linereset\n]
end
code = md[1]
code.sub!(/\A\n/, "")
code += "\n" unless code.end_with?("\n")
code
end
end
+1 -1
View File
@@ -1,3 +1,3 @@
class Propane
VERSION = "4.3.0"
VERSION = "4.1.0"
end
+9 -9
View File
@@ -28,7 +28,7 @@ B -> <<
b = 0;
>>
EOF
grammar = Grammar.new(input, "test.propane")
grammar = Grammar.new(input)
expect(grammar.modulename).to eq "a.b"
expect(grammar.ptype).to eq "XYZ *"
expect(grammar.ptypes).to eq("default" => "XYZ *")
@@ -62,7 +62,7 @@ EOF
expect(o).to_not be_nil
expect(o.pattern).to eq "token_with_code"
expect(o.line_number).to eq 11
expect(o.code).to eq %[#line 12 "test.propane"\nCode for the token\n#linereset\n]
expect(o.code).to eq "Code for the token\n"
o = grammar.tokens.find {|token| token.name == "token_with_no_pattern"}
expect(o).to_not be_nil
@@ -83,7 +83,7 @@ EOF
expect(o.name).to eq "A"
expect(o.components).to eq %w[B]
expect(o.line_number).to eq 19
expect(o.code).to eq %[#line 20 "test.propane"\n a = 42;\n#linereset\n]
expect(o.code).to eq " a = 42;\n"
o = grammar.rules[1]
expect(o.name).to eq "B"
@@ -95,7 +95,7 @@ EOF
expect(o.name).to eq "B"
expect(o.components).to eq []
expect(o.line_number).to eq 23
expect(o.code).to eq %[#line 24 "test.propane"\n b = 0;\n#linereset\n]
expect(o.code).to eq " b = 0;\n"
end
it "parses code segments with semicolons" do
@@ -113,7 +113,7 @@ tokenid token_with_no_pattern;
prefix myparser_;
EOF
grammar = Grammar.new(input, "test.propane")
grammar = Grammar.new(input)
expect(grammar.prefix).to eq "myparser_"
o = grammar.tokens.find {|token| token.name == "code1"}
@@ -122,7 +122,7 @@ EOF
o = grammar.patterns.find {|pattern| pattern.token == o}
expect(o).to_not be_nil
expect(o.code).to eq %[#line 2 "test.propane"\n a = b;\n return c;\n#linereset\n]
expect(o.code).to eq " a = b;\n return c;\n"
o = grammar.tokens.find {|token| token.name == "code2"}
expect(o).to_not be_nil
@@ -130,7 +130,7 @@ EOF
o = grammar.patterns.find {|pattern| pattern.token == o}
expect(o).to_not be_nil
expect(o.code).to eq %[#line 7 "test.propane"\n writeln("Hello there");\n#linereset\n]
expect(o.code).to eq %[ writeln("Hello there");\n]
end
it "supports mode labels" do
@@ -144,7 +144,7 @@ m2: /bar/ <<
drop /q/;
m3: drop /r/;
EOF
grammar = Grammar.new(input, "test.propane")
grammar = Grammar.new(input)
o = grammar.tokens.find {|token| token.name == "a"}
expect(o).to_not be_nil
@@ -197,7 +197,7 @@ tokenid int(integer);
Start (node) -> R;
R -> abc int;
EOF
grammar = Grammar.new(input, "test.propane")
grammar = Grammar.new(input)
o = grammar.tokens.find {|token| token.name == "abc"}
expect(o).to_not be_nil
+1 -1
View File
@@ -51,7 +51,7 @@ class TestLexer
end
def run(grammar, input)
grammar = Propane::Grammar.new(grammar, "test.propane")
grammar = Propane::Grammar.new(grammar)
token_dfa = Propane::Lexer::DFA.new(grammar.patterns)
test_lexer = TestLexer.new(token_dfa)
test_lexer.lex(input)