Skip to content

Commit

Permalink
Made the treetop grammar more lax
Browse files Browse the repository at this point in the history
This made it possible to use awlpp on AWL code that is not generated
in step 7
  • Loading branch information
tallakt committed Jan 23, 2013
1 parent b64f677 commit 7b894b7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/plcutil.rb
Expand Up @@ -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

90 changes: 63 additions & 27 deletions lib/plcutil/siemens/awl/awl.treetop
Expand Up @@ -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?
Expand Down Expand Up @@ -66,7 +66,7 @@ module PlcUtil
end

rule db_name
'DB ' number:([0-9]+)
'DB' ' '? number:([0-9]+)
end

rule version
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7b894b7

Please sign in to comment.