Browse files

Made the treetop grammar more lax

This made it possible to use awlpp on AWL code that is not generated
in step 7
  • Loading branch information...
1 parent b64f677 commit 7b894b78bd604420a9ef61479cd4b1b67bba328e @tallakt committed Jan 23, 2013
Showing with 64 additions and 28 deletions.
  1. +1 −1 lib/plcutil.rb
  2. +63 −27 lib/plcutil/siemens/awl/awl.treetop
View
2 lib/plcutil.rb
@@ -3,6 +3,6 @@
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
module PlcUtil
- VERSION = '0.2.11'
+ VERSION = '0.2.12'
end
View
90 lib/plcutil/siemens/awl/awl.treetop
@@ -10,20 +10,20 @@ module PlcUtil
end
rule db
- 'DATA_BLOCK ' name eol
- title
- author?
- family?
- block_name?
- 'VERSION : ' version eol
- eol*
+ 'DATA_BLOCK' ws name eol
+ (title / author / family / block_name / eol / ws_comments / ('VERSION : ' version eol))*
root_struct_decl
+ ws_comments*
'BEGIN' eol
- assignment*
+ (ws_comments / assignment)*
'END_DATA_BLOCK' eol
ws_eol
end
+ rule ws_comments
+ (ws? line_comment? eol)
+ end
+
rule udt
'TYPE ' name eol
author?
@@ -66,7 +66,7 @@ module PlcUtil
end
rule db_name
- 'DB ' number:([0-9]+)
+ 'DB' ' '? number:([0-9]+)
end
rule version
@@ -98,11 +98,12 @@ module PlcUtil
end
rule declaration
+ eol*
ws
identifier
- ' : '
+ ws ':' ws
d:(array_declaration <ArrayDeclarationNode> / nonarray_declaration <NonArrayDeclarationNode>)
- eol
+ eol+
end
rule nonarray_declaration
@@ -133,11 +134,11 @@ module PlcUtil
rule struct_data_type
'STRUCT' ws? struct_comment:(line_comment?) eol
decl:declaration*
- ws 'END_STRUCT'
+ ws? 'END_STRUCT'
end
rule root_struct_decl
- ws struct_data_type ws ';' ws? eol
+ ws? struct_data_type ws? ';' ws? eol
end
rule udt_data_type
@@ -153,20 +154,55 @@ module PlcUtil
end
rule basic_data_type
- (
- 'INT' /
- 'DINT' /
- 'BOOL' /
- 'BYTE' /
- 'WORD' /
- 'DWORD' /
- 'TIME_OF_DAY' /
- 'REAL' /
- 'TIME' /
- 'S5TIME' /
- 'DATE' /
- 'CHAR'
- )
+ ( int / dint / bool / byte / word / dword / time_of_day / real / time / s5time / date / char )
+ end
+
+ rule int
+ [Ii] [Nn] [Tt]
+ end
+
+ rule dint
+ [Dd] [Ii] [Nn] [Tt]
+ end
+
+ rule bool
+ [Bb] [Oo] [Oo] [Ll]
+ end
+
+ rule byte
+ [Bb] [Yy] [Tt] [Ee]
+ end
+
+ rule word
+ [Ww] [Oo] [Rr] [Dd]
+ end
+
+ rule dword
+ [Dd] [Ww] [Oo] [Rr] [Dd]
+ end
+
+ rule time_of_day
+ [Tt] [Ii] [Mm] [Ee] [_] [Oo] [Ff] [_] [Dd] [Aa] [Yy]
+ end
+
+ rule real
+ [Rr] [Ee] [Aa] [Ll]
+ end
+
+ rule time
+ [Tt] [Ii] [Mm] [Ee]
+ end
+
+ rule s5time
+ [Ss] '5' [Tt] [Ii] [Mm] [Ee]
+ end
+
+ rule date
+ [Dd] [Aa] [Tt] [Ee]
+ end
+
+ rule char
+ [Cc] [Hh] [Aa] [Rr]
end
rule value

0 comments on commit 7b894b7

Please sign in to comment.